const std::vector< boost::geometry::model::d2::point_xy<T> > GetLineRectIntersections( const boost::geometry::model::linestring< boost::geometry::model::d2::point_xy<T> > line, const boost::geometry::model::box< boost::geometry::model::d2::point_xy<T> > rect) { typedef boost::geometry::model::d2::point_xy<T> Point; typedef boost::geometry::model::linestring<Point> Line; typedef boost::geometry::model::box<Point> Rect; const Point p0 = Point(rect.min_corner().x(), rect.min_corner().y()); const Point p1 = Point(rect.max_corner().x(), rect.min_corner().y()); const Point p2 = Point(rect.min_corner().x(), rect.max_corner().y()); const Point p3 = Point(rect.max_corner().x(), rect.max_corner().y()); const std::vector<Line> lines = { CreateLine(std::vector<Point>( {p0,p1} )), CreateLine(std::vector<Point>( {p0,p2} )), CreateLine(std::vector<Point>( {p1,p3} )), CreateLine(std::vector<Point>( {p2,p3} )) }; std::vector<Point> points; std::for_each(lines.begin(),lines.end(), [&points,line](const Line& side) { const std::vector<Point> v = GetLineLineIntersections(line,side); std::copy(v.begin(),v.end(),std::back_inserter(points)); } ); //Remove doublures //Put 'typename' before 'std::vector<Point>::iteratortype' to prevent getting the error below: //error: need 'typename' before 'std::vector<boost::geometry::model::d2::point_xy<T> >::iterator' // because 'std::vector<boost::geometry::model::d2::point_xy<T> >' is a dependent scope typename std::vector<Point>::iterator new_end = std::unique( points.begin(),points.end(), [](const Point& lhs, const Point& rhs) { return lhs.x() == rhs.x() && lhs.y() == rhs.y(); } ); points.erase(new_end,points.end()); assert(points.size() <= 2); return points; }
/** * Converts a geometry::box with Cartesian coordinates into a SpatialIndex::Region * @param b The box to convert * @return The converted region */ static SpatialIndex::Region convert_region_2d(const boost::geometry::model::box<point_2d>& b) { SpatialIndex::Point ll = convert_point_2d(b.min_corner()); SpatialIndex::Point ur = convert_point_2d(b.max_corner()); SpatialIndex::Region r(ll,ur); r.makeDimension(m_dimension); return r; }
/** * Converts a geometry::box into a SpatialIndex::Region * @param b The region (box) to convert * @return The converted region */ static SpatialIndex::Region convert_region_2d(const boost::geometry::model::box<point_type>& b) { point_type ll = b.min_corner(); point_type ur = b.max_corner(); SpatialIndex::Region r(convert_point(ll),convert_point(ur)); r.makeDimension(m_dimension); return r; }