15 #include <boost/geometry.hpp>
16 #include <boost/geometry/geometries/geometries.hpp>
17 #include <boost/geometry/geometries/point_xy.hpp>
18 #include <boost/geometry/geometries/polygon.hpp>
20 #include "ad/physics/AngleOperation.hpp"
21 #include "ad/physics/Distance.hpp"
36 namespace unstructured {
39 typedef boost::geometry::model::d2::point_xy<double> Point;
40 typedef boost::geometry::model::linestring<Point> Line;
41 typedef boost::geometry::model::polygon<Point, false> Polygon;
42 typedef boost::geometry::model::multi_point<Point> MultiPoint;
51 inline Point
toPoint(ad::physics::Distance2D
const &distance)
53 return Point(
static_cast<double>(distance.x),
static_cast<double>(distance.y));
64 inline Point
toPoint(ad::physics::Distance
const &distanceX, ad::physics::Distance
const &distanceY)
66 return Point(
static_cast<double>(distanceX),
static_cast<double>(distanceY));
76 inline ad::physics::Distance2D
toDistance(Point
const &point)
78 ad::physics::Distance2D distance;
79 distance.x = ad::physics::Distance(point.x());
80 distance.y = ad::physics::Distance(point.y());
121 std::vector<state::HeadingRange> &overlapRanges);
142 Point
rotateAroundPoint(Point
const &origin, Point
const &relativePoint, ad::physics::Angle
const &angle);
153 Point
getPointOnCircle(Point
const &origin, ad::physics::Distance
const &radius, ad::physics::Angle
const &angle);
164 Point
getCircleOrigin(Point
const &point, ad::physics::Distance
const &radius, ad::physics::Angle
const &angle);
175 template <
typename T>
177 ad::physics::Distance
const &radius,
178 ad::physics::Angle
const &from,
179 ad::physics::Angle
const &delta,
180 ad::physics::Angle
const &stepWidth,
183 ad::physics::Angle currentAngle = from;
184 ad::physics::Angle maxAngle = currentAngle + delta;
185 while (currentAngle <= maxAngle)
187 boost::geometry::append(geometry,
getPointOnCircle(origin, radius, currentAngle));
188 currentAngle += stepWidth;
190 if (currentAngle - stepWidth != maxAngle)
192 boost::geometry::append(geometry,
getPointOnCircle(origin, radius, maxAngle));
216 bool combinePolygon(Polygon
const &a, Polygon
const &b, Polygon &result);
230 inline ad::rss::unstructured::Point
operator+(ad::rss::unstructured::Point
const &a,
231 ad::rss::unstructured::Point
const &b)
234 boost::geometry::add_point(result, b);
246 inline ad::rss::unstructured::Point
operator-(ad::rss::unstructured::Point
const &a,
247 ad::rss::unstructured::Point
const &b)
250 boost::geometry::subtract_point(result, b);
262 inline bool operator==(ad::rss::unstructured::Point
const &a, ad::rss::unstructured::Point
const &b)
264 return (std::abs(a.x() - b.x()) <= std::numeric_limits<double>::epsilon())
265 && (std::abs(a.y() - b.y()) <= std::numeric_limits<double>::epsilon());
276 inline bool operator!=(ad::rss::unstructured::Point
const &a, ad::rss::unstructured::Point
const &b)
290 inline std::string
to_string(ad::rss::unstructured::Point
const &value)
292 std::stringstream stream;
293 stream <<
"[" << value.x() <<
"," << value.y() <<
"]";
304 inline std::string
to_string(ad::rss::unstructured::Polygon
const &value)
306 std::stringstream stream;
308 for (
auto pt : value.outer())
323 inline std::string
to_string(ad::rss::unstructured::Line value)
325 std::stringstream stream;
327 for (
auto pt : value)
329 stream <<
"[" << pt.x() <<
"," << pt.y() <<
"],";