幾何計算アルゴリズムを提供する。
各種アルゴリズムはテンプレートによる実装のため、
自作クラスでもアダプターを作れば対応可能である。
などがある。その他の関数は作者のドキュメントを参照。
各種アルゴリズムはテンプレートによる実装のため、
自作クラスでもアダプターを作れば対応可能である。
- distance: 2つのGeometryの距離。
- intersects: 1つあるいは2つのGeometryの交差判定
- intersection:2つのGeometryの交差判定と交差部分のGeometryの出力
- envelop: bounding boxの計算
などがある。その他の関数は作者のドキュメントを参照。
下記のようなoperator()で要素にアクセスするPointクラスをGeometryのアルゴリズムで使えるようにする。
以上により、boost::geometryの各種関数に対してPoint3Dを使用することができる。
class Point3D { public: Point3D(); double& operator()(size_t i); const double& operator()(size_t i) const; private: std::array<double, 3> data; } namespace boost { namespace geometry { namespace traits { template<> struct tag<Point3D> { typedef point_tag type; }; template<> struct coordinate_type<Point3D> { tyepdef double type; }; template<> struct coordinate_system<Point3D> { typedef cs::cartesian type; }; template<> struct dimension<Point3D> : boost::mpl::int_<2> {}; template<> struct access<Point3D, 0> { static double get(Point3D const p) { return p(0); } static double set(Point3D& p, const double value) { p(0) = value; } }; template<> struct access<Point3D, 1> { static double get(Point3D const p) { return p(1); } static double set(Point3D& p, const double value) { p(1) = value; } }; template<> struct access<Point3D, 2> { static double get(Point3D const p) { return p(2); } static double set(Point3D& p, const double value) { p(2) = value; } }; }}}
以上により、boost::geometryの各種関数に対してPoint3Dを使用することができる。
Point3D p1(0,0,0); Point3D p2(0,0,10); Point3D p3(0,10,0); std::cout << boost::geometry::distance(p1, p2) << std::endl; boost::geometry::model::segment<Point3D> s(p1, p2); std::cout << boost::geometry::distance(p3, s) << std::endl;
コメントをかく