bool polygonIntersectsPolygon(const GeometryCoordinates& polygonA, const GeometryCoordinates& polygonB) { for (auto& p : polygonA) { if (polygonContainsPoint(polygonB, p)) return true; } for (auto& p : polygonB) { if (polygonContainsPoint(polygonA, p)) return true; } if (lineIntersectsLine(polygonA, polygonB)) return true; return false; }
std::vector<panda::types::Polygon> clipperPathsToPolys(const ClipperLib::Paths& paths) { std::vector<panda::types::Polygon> polys; std::vector<panda::types::Path> holes; for (const auto& path : paths) { auto pPath = clipperPathToPath(path); if (Orientation(path)) { panda::types::Polygon outPoly; outPoly.contour = std::move(pPath); polys.push_back(std::move(outPoly)); } else if (!path.empty()) { if (!polys.empty() && polygonContainsPoint(polys.back().contour, pPath.points[0])) polys.back().holes.push_back(std::move(pPath)); else holes.push_back(std::move(pPath)); } } // Find the correct polygon to put holes in std::vector<panda::types::Path> orphans; for (auto& hole : holes) { bool found = false; for (auto& poly : polys) { if (polygonContainsPoint(poly.contour, hole.points[0])) { poly.holes.push_back(std::move(hole)); found = true; break; } } if (!found) orphans.push_back(std::move(hole)); } // If we really didn't find where to place that path, we create a new polygon for it for (auto& orphan : orphans) { panda::types::Polygon poly; poly.contour = std::move(orphan); polys.push_back(std::move(poly)); } return polys; }
bool polygonIntersectsBufferedMultiPoint(const GeometryCoordinates& polygon, const GeometryCollection& rings, float radius) { for (auto& ring : rings) { for (auto& point : ring) { if (polygonContainsPoint(polygon, point)) return true; if (pointIntersectsBufferedLine(point, polygon, radius)) return true; } } return false; }
bool polygonIntersectsBufferedMultiLine(const GeometryCoordinates& polygon, const GeometryCollection& multiLine, float radius) { for (auto& line : multiLine) { if (polygon.size() >= 3) { for (auto& p : line) { if (polygonContainsPoint(polygon, p)) return true; } } if (lineIntersectsBufferedLine(polygon, line, radius)) return true; } return false; }