diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-10-25 01:39:33 +0300 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2016-10-25 08:12:31 +0300 |
commit | fc6344c5461c15956f425e39ee6c11dba638f46b (patch) | |
tree | 1af87e3ee6c9982e81c6583c4e3f80c479f16a5d /src | |
parent | 679bfbfb32d6371d6eb405b5e465353c53298c41 (diff) | |
download | qtlocation-mapboxgl-fc6344c5461c15956f425e39ee6c11dba638f46b.tar.gz |
[core] Added util::polygonIntersectsPolygon
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/util/intersection_tests.cpp | 32 | ||||
-rw-r--r-- | src/mbgl/util/intersection_tests.hpp | 1 |
2 files changed, 13 insertions, 20 deletions
diff --git a/src/mbgl/util/intersection_tests.cpp b/src/mbgl/util/intersection_tests.cpp index a0feb8ec37..c580357298 100644 --- a/src/mbgl/util/intersection_tests.cpp +++ b/src/mbgl/util/intersection_tests.cpp @@ -16,14 +16,6 @@ bool polygonContainsPoint(const GeometryCoordinates& ring, const GeometryCoordin return c; } -bool multiPolygonContainsPoint(const GeometryCollection& rings, const GeometryCoordinate& p) { - bool c = false; - for (auto& ring : rings) { - c = (c != polygonContainsPoint(ring, p)); - } - return c; -} - // Code from http://stackoverflow.com/a/1501725/331379. float distToSegmentSquared(const GeometryCoordinate& p, const GeometryCoordinate& v, const GeometryCoordinate& w) { if (v == w) return util::distSqr<float>(p, v); @@ -114,23 +106,23 @@ bool polygonIntersectsBufferedMultiLine(const GeometryCoordinates& polygon, cons return false; } -bool polygonIntersectsMultiPolygon(const GeometryCoordinates& polygon, const GeometryCollection& multiPolygon) { - if (polygon.size() == 1) { - return multiPolygonContainsPoint(multiPolygon, polygon.at(0)); +bool polygonIntersectsPolygon(const GeometryCoordinates& polygonA, const GeometryCoordinates& polygonB) { + for (auto& p : polygonA) { + if (polygonContainsPoint(polygonB, p)) return true; } - for (auto& ring : multiPolygon) { - for (auto& p : ring) { - if (polygonContainsPoint(polygon, p)) return true; - } + for (auto& p : polygonB) { + if (polygonContainsPoint(polygonA, p)) return true; } - for (auto& p : polygon) { - if (multiPolygonContainsPoint(multiPolygon, p)) return true; - } + if (lineIntersectsLine(polygonA, polygonB)) return true; - for (auto& polygonB : multiPolygon) { - if (lineIntersectsLine(polygon, polygonB)) return true; + return false; +} + +bool polygonIntersectsMultiPolygon(const GeometryCoordinates& polygon, const GeometryCollection& multiPolygon) { + for (auto& ring : multiPolygon) { + if (polygonIntersectsPolygon(polygon, ring)) return true; } return false; diff --git a/src/mbgl/util/intersection_tests.hpp b/src/mbgl/util/intersection_tests.hpp index 6adb3b5fdf..5bcb29c767 100644 --- a/src/mbgl/util/intersection_tests.hpp +++ b/src/mbgl/util/intersection_tests.hpp @@ -7,6 +7,7 @@ namespace util { bool polygonIntersectsBufferedMultiPoint(const GeometryCoordinates&, const GeometryCollection&, float radius); bool polygonIntersectsBufferedMultiLine(const GeometryCoordinates&, const GeometryCollection&, float radius); +bool polygonIntersectsPolygon(const GeometryCoordinates&, const GeometryCoordinates&); bool polygonIntersectsMultiPolygon(const GeometryCoordinates&, const GeometryCollection&); } // namespace util |