#include #include #include #include #include namespace { // anonymous namespace class myPoint { public: myPoint() {} myPoint(double xpos, double ypos) {this->pos_[0]=xpos; this->pos_[1]=ypos;} const double getXPos() const { return this->pos_[0]; } const double getYPos() const { return this->pos_[1]; } void setXPos(double xpos) { this->pos_[0] = xpos; } void setYPos(double ypos) { this->pos_[1] = ypos; } template const double get() const { assert(dimension==0 || dimension==1); return this->pos_[dimension]; } void sayHello(void) { std::cout<<"Hello!" << std::endl; } private: double pos_[2]; }; } // end anonymous namespace BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET(myPoint, double, cs::cartesian, getXPos, // how can i register get<0> ?? getYPos, // how can i register get<1> ?? setXPos, setYPos ) int main() { typedef myPoint point; //typedef std::shared_ptr point; // how to register?? typedef boost::geometry::model::ring< point > ring; typedef boost::geometry::model::polygon< point,false,false > Polygon; typedef boost::geometry::model::linestring< point > linestring; typedef boost::geometry::model::segment< point > segment; // Segment-segment intersection segment line_one(boost::geometry::make(-1.0, -1.0), boost::geometry::make(5.0, 5.0)); // made this 5 segment line_two(boost::geometry::make(4.0, 0.0), boost::geometry::make(0.0, 4.0)); std::vector points, points2, points3; boost::geometry::intersection(line_one, line_two, points); std::cout << "intersection points of segments: " << std::endl; for (auto it : points) { std::cout << "x: " << it.get<0>() << std::endl; std::cout << "y: " << it.get<1>() << std::endl; } // Linestring/linestring intersection linestring one, two; boost::geometry::append(one, boost::geometry::make(0.0, 0.0)); boost::geometry::append(one, boost::geometry::make(4.0, 4.0)); boost::geometry::append(two, boost::geometry::make(4.0, 0.0)); boost::geometry::append(two, boost::geometry::make(0.0, 4.0)); boost::geometry::intersection(one, two, points2); std::cout << "intersection points using linestrings: " << std::endl; for (auto it : points2) { std::cout << "x: " << it.get<0>() << std::endl; std::cout << "y: " << it.get<1>() << std::endl; } Polygon polygon; boost::geometry::append(polygon, boost::geometry::make(0, 0)); boost::geometry::append(polygon, boost::geometry::make(4, 0)); boost::geometry::append(polygon, boost::geometry::make(0, 4)); //boost::geometry::append(polygon, boost::geometry::make(0, 0)); // changed Closed=false boost::geometry::intersection(polygon, one, points3); std::cout << "intersection points using a Polygon and a linestring: " << std::endl; for (auto it : points3) { std::cout << "x: " << it.get<0>() << std::endl; std::cout << "y: " << it.get<1>() << std::endl; } return 0; }