18 #include <boost/geometry.hpp>
19 #include <boost/geometry/geometries/point_xy.hpp>
20 #include <boost/geometry/geometries/polygon.hpp>
22 using namespace boost::geometry;
27 typedef model::d2::point_xy<double>
point_t;
30 void init_from(
const std::vector<double>& x,
const std::vector<double>& y);
31 void get_points(std::vector<double>& xpos, std::vector<double>& ypos);
36 if (x.size() != y.size())
37 throw std::runtime_error(
38 "Polygon::Polygon(const std::vector<double>& x, const std::vector<double>& y) "
39 "Error. Sizes of arrays must conincide.");
40 std::vector<point_t> points;
41 for (
size_t i = 0; i < x.size(); ++i)
42 points.push_back(
point_t(x[i], y[i]));
43 assign_points(polygon, points);
51 for (
auto it = polygon.outer().begin(); it != polygon.outer().end(); ++it) {
53 xpos.push_back(boost::geometry::get<0>(*it));
54 ypos.push_back(boost::geometry::get<1>(*it));
78 std::vector<double> x;
79 std::vector<double> y;
80 for (
size_t i = 0; i < points.size(); ++i) {
81 if (points[i].size() != 2)
82 throw std::runtime_error(
83 "Polygon(const std::vector<std::vector<double> >& points) -> Error. "
84 " Should be two-dimensional array with second dimension of 2 size.");
85 x.push_back(points[i][0]);
86 y.push_back(points[i][1]);
121 ostr << wkt<PolygonPrivate::polygon_t>(
m_d->
polygon);
Defines structs Bin1D, Bin1DCVector.
Basic class for all shapes in 2D.
The private data for polygons to hide boost dependency from the header.
model::polygon< point_t > polygon_t
model::d2::point_xy< double > point_t
void init_from(const std::vector< double > &x, const std::vector< double > &y)
void get_points(std::vector< double > &xpos, std::vector< double > &ypos)
virtual bool contains(double x, double y) const
Returns true if point with given coordinates is inside or on border of the shape.
void getPoints(std::vector< double > &xpos, std::vector< double > &ypos) const
virtual void print(std::ostream &ostr) const
Polygon(const std::vector< double > x, const std::vector< double > y)