Boost 1.50.0になり、Boost.Geometryにtouches()アルゴリズムが追加されました。
この関数は、自身もしくは2つのジオメトリが空間的に接触しているかを判定するのに使用します。
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> #include <boost/assign/list_of.hpp> namespace bg = boost::geometry; typedef bg::model::d2::point_xy<int> point; typedef bg::model::polygon<point> polygon; int main() { polygon x; bg::exterior_ring(x) = boost::assign::list_of<point> (0, 0)(0, 3)(2, 3) (2, 2)(1, 2)(1, 1) (2, 1)(2, 2.5)(3, 2.5) (3, 0)(0, 0); if (bg::touches(x)) { std::cout << "x is touch" << std::endl; } else { std::cout << "x is not touch" << std::endl; } }
x is touch
次に2引数版。2つのジオメトリが接触しているかを判定します。
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> #include <boost/assign/list_of.hpp> namespace bg = boost::geometry; typedef bg::model::d2::point_xy<int> point; typedef bg::model::polygon<point> polygon; int main() { polygon x; bg::exterior_ring(x) = boost::assign::list_of<point> ( 0, 0) ( 0, 100) (100, 100) (100, 0) ( 0, 0); polygon y; bg::exterior_ring(y) = boost::assign::list_of<point> (100, 100) (100, 200) (200, 200) (200, 100) (100, 100); if (bg::touches(x, y)) { std::cout << "touch" << std::endl; } else { std::cout << "not touch" << std::endl; } }
touch
参照:
touches (one geometry) - Boost Geometry Library
touches (two geometries) - Boost Geometry Library