This is related to the a thread that was posted earlier in this forum.
What are some recommended frameworks for manipulating spatial data in C++?
您是否知道提供基于泛型的编译时保护以防止混合 UCS 和 GCS 坐标的几何库?例如,我正在寻找可以让我编写如下代码的东西:
Point2D<GCS> p1( 1.0, 1.0 );
Point2D<UCS> p2( 1.0, 1.0 );
std::cout << (p1 - p2) << std::endl; // compile-time error: mixing types!
我不需要防止混合不同的 UCS,只需要混合 GCS 和 UCS。混合局部和全局坐标系是完全可以避免的错误,可以通过适当的簿记来消除,应该使用 C++ 的强大类型检查和泛型支持来简化这种错误。我宁愿使用现有的库,也不愿重新发明轮子。
最佳答案
您可以编写一个函数将 UCS 转换为 GCS。然后你可以执行std::cout<<(p1-p2)<<"\n;
当他们都在 GCS 中时。
那么,就不会因为混合类型而出现编译错误。
关于c++ - 计算 Point2D<UCS> 和 Point2D<GCS> 之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4091381/