19 #include <boost/geometry.hpp>
22 class PolygonPrivate {
24 using point_t = boost::geometry::model::d2::point_xy<double>;
25 using polygon_t = boost::geometry::model::polygon<point_t>;
26 PolygonPrivate(
const std::vector<double>& x,
const std::vector<double>& y);
27 PolygonPrivate(
const std::vector<std::pair<double, double>>& pts);
29 void get_points(std::vector<double>& xpos, std::vector<double>& ypos);
32 PolygonPrivate::PolygonPrivate(
const std::vector<double>& x,
const std::vector<double>& y)
34 ASSERT(x.size() == y.size());
35 std::vector<point_t> points;
36 for (
size_t i = 0; i < x.size(); ++i)
37 points.emplace_back(x[i], y[i]);
38 boost::geometry::assign_points(polygon, points);
39 boost::geometry::correct(polygon);
42 PolygonPrivate::PolygonPrivate(
const std::vector<std::pair<double, double>>& pts)
44 std::vector<point_t> points;
45 for (
const std::pair<double, double>& p : pts)
46 points.emplace_back(p.first, p.second);
47 boost::geometry::assign_points(polygon, points);
48 boost::geometry::correct(polygon);
51 void PolygonPrivate::get_points(std::vector<double>& xpos, std::vector<double>& ypos)
55 for (
auto it = polygon.outer().begin(); it != polygon.outer().end(); ++it) {
57 xpos.push_back(boost::geometry::get<0>(*it));
58 ypos.push_back(boost::geometry::get<1>(*it));
73 , m_d(new PolygonPrivate(x, y))
84 , m_d(new PolygonPrivate(points))
90 , m_d(new PolygonPrivate(*d))
102 return boost::geometry::covered_by(PolygonPrivate::point_t(x, y),
m_d->polygon);
112 return boost::geometry::area(
m_d->polygon);
117 m_d->get_points(xpos, ypos);
122 ostr << boost::geometry::wkt<PolygonPrivate::polygon_t>(
m_d->polygon);
Defines the macro ASSERT.
#define ASSERT(condition)
Defines structs Bin1D, Bin1DCVector.
boost::geometry::model::d2::point_xy< double > point_t
Basic class for all shapes in 2D.
bool contains(double x, double y) const override
Returns true if point with given coordinates is inside or on border of the shape.
Polygon(std::vector< double > x, std::vector< double > y)
If polygon is unclosed (the last point doesn't repeat the first one), it will be closed automatically...
void getPoints(std::vector< double > &xpos, std::vector< double > &ypos) const
void print(std::ostream &ostr) const override