diff --git a/src/util/geo/Geo.h b/src/util/geo/Geo.h index 5568992..949a483 100644 --- a/src/util/geo/Geo.h +++ b/src/util/geo/Geo.h @@ -6,8 +6,8 @@ #define _USE_MATH_DEFINES -#include #include +#include #include "util/Misc.h" #include "util/geo/Box.h" #include "util/geo/Line.h" @@ -252,6 +252,18 @@ inline bool intersects(const Point& p, const Line& l) { return intersects(l, p); } +// _____________________________________________________________________________ +template +inline bool intersects(const Polygon& l, const Point& p) { + return contains(l, p); +} + +// _____________________________________________________________________________ +template +inline bool intersects(const Point& p, const Polygon& l) { + return intersects(l, p); +} + // _____________________________________________________________________________ template inline bool intersects(const Box& b1, const Box& b2) { @@ -284,6 +296,26 @@ inline bool intersects(const LineSegment& ls, const Box& b) { return contains(ls, b); } +// _____________________________________________________________________________ +template +inline bool intersects(const LineSegment& ls, const Polygon& p) { + for (size_t i = 1; i < p.getOuter().size(); i++) { + if (intersects(LineSegment(p.getOuter()[i - 1], p.getOuter()[i]), ls)) + return true; + } + + if (intersects(LineSegment(p.getOuter().back(), p.getOuter().front()), ls)) + return true; + + return contains(ls, p); +} + +// _____________________________________________________________________________ +template +inline bool intersects(const Polygon& p, const LineSegment& ls) { + return intersects(ls, p); +} + // _____________________________________________________________________________ template inline bool intersects(const Box& b, const LineSegment& ls) {