19 #include <boost/geometry.hpp>
20 #include <boost/geometry/geometries/point_xy.hpp>
21 #include <boost/geometry/geometries/polygon.hpp>
23 using namespace boost::geometry;
29 typedef model::d2::point_xy<double> point_t;
30 typedef model::polygon<point_t> polygon_t;
32 void init_from(
const std::vector<double>& x,
const std::vector<double>& y);
33 void get_points(std::vector<double>& xpos, std::vector<double>& ypos);
36 void PolygonPrivate::init_from(
const std::vector<double>& x,
const std::vector<double>& y)
38 if (x.size() != y.size())
40 "Polygon::Polygon(const std::vector<double>& x, const std::vector<double>& y) "
41 "Error. Sizes of arrays must conincide.");
42 std::vector<point_t> points;
43 for (
size_t i = 0; i < x.size(); ++i)
44 points.push_back(point_t(x[i], y[i]));
45 assign_points(polygon, points);
49 void PolygonPrivate::get_points(std::vector<double>& xpos, std::vector<double>& ypos)
53 for (
auto it = polygon.outer().begin(); it != polygon.outer().end(); ++it) {
55 xpos.push_back(boost::geometry::get<0>(*it));
56 ypos.push_back(boost::geometry::get<1>(*it));
80 std::vector<double> x;
81 std::vector<double> y;
82 for (
size_t i = 0; i < points.size(); ++i) {
83 if (points[i].size() != 2)
85 "Polygon(const std::vector<std::vector<double> >& points) -> Error. "
86 " Should be two-dimensional array with second dimension of 2 size.");
87 x.push_back(points[i][0]);
88 y.push_back(points[i][1]);
103 return covered_by(PolygonPrivate::point_t(x, y), m_d->polygon);
108 return contains(binx.getMidPoint(), biny.getMidPoint());
111 double Polygon::getArea()
const
113 return area(m_d->polygon);
116 void Polygon::getPoints(std::vector<double>& xpos, std::vector<double>& ypos)
const
118 m_d->get_points(xpos, ypos);
121 void Polygon::print(std::ostream& ostr)
const
123 ostr << wkt<PolygonPrivate::polygon_t>(m_d->polygon);
Defines structs Bin1D, Bin1DCVector.
Defines many exception classes in namespace Exceptionss.
Basic class for all shapes in 2D.
The private data for polygons to hide boost dependency from the header.
virtual bool contains(double x, double y) const
Returns true if point with given coordinates is inside or on border of the shape.
Polygon(const std::vector< double > x, const std::vector< double > y)