From 223ffa6f6b49bf1f31dd6f659349b8e1df4174fc Mon Sep 17 00:00:00 2001 From: Patrick Brosi Date: Mon, 16 Jul 2018 02:03:10 +0200 Subject: [PATCH] some work on util --- src/util/geo/Geo.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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) {