#pragma once #include #include #include #include #include #include #include #include #include "DataManagerGlobal.h" // /// // /// 内插法字典表 // /// // class InterpolationTable // { // }; /// /// 内插法算法类 /// class DATAMANAGER_DLL_API_EXPORTS Interpolation : public std::enable_shared_from_this { /// /// 内插法(线性求取插值算法) /// /// 字典表 /// 所取字段(属性)名 /// 键值步长 /// 实际键值 /// public: template static double Interpolate(std::unordered_map &dic, const std::string &propName, int step, double key) { double key1 = key / step; int keyFloor = static_cast(std::floor(key1)) * step; int keyCeiling = static_cast(std::ceil(key1)) * step; double offset = (key - keyFloor) / step; int keyMax = dic.Keys->Max([&](std::any m) { m; }); int keyMin = dic.Keys->Min([&](std::any m) { m; }); if (keyFloor >= keyMax) { keyFloor = keyMax; keyCeiling = keyMax; } if (!dic.contains(keyFloor) || !dic.contains(keyCeiling)) { throw std::runtime_error("提供的键值不在内插法字典键值范围内"); } std::any oFloor = dic[keyFloor]; std::any oCeiling = dic[keyCeiling]; std::shared_ptr prop = typeid(T).GetProperty(propName); double vFloor = std::any_cast(prop->GetValue(oFloor, std::vector())); double vCeiling = std::any_cast(prop->GetValue(oCeiling, std::vector())); double rtn = vFloor + (offset == 0.0 ? 0 : (vCeiling - vFloor) / offset); return rtn; } static double Linear(std::vector &points, std::vector &values, double t); };