ENH: improve normal support's efficiency

Similar to tree support, make as many steps parallel as possible.
Jira: STUDIO-2525

Change-Id: Iee310bbf6911d8d3e4262ee8ed6bd133d09670a9
(cherry picked from commit 3798f1a3ecb85bbfb81925b3702fb4384e18994d)
This commit is contained in:
Arthur 2023-03-20 12:02:15 +08:00 committed by Lane.Wei
parent ef1e4a132d
commit 1ac8013fa5
4 changed files with 179 additions and 133 deletions

View file

@ -207,7 +207,18 @@ bool Polygon::intersections(const Line &line, Points *intersections) const
}
return intersections->size() > intersections_size;
}
bool Polygon::overlaps(const Polygons& other) const
{
if (this->empty() || other.empty())
return false;
Polylines pl_out = intersection_pl(to_polylines(other), *this);
// See unit test SCENARIO("Clipper diff with polyline", "[Clipper]")
// for in which case the intersection_pl produces any intersection.
return !pl_out.empty() ||
// If *this is completely inside other, then pl_out is empty, but the expolygons overlap. Test for that situation.
std::any_of(other.begin(), other.end(), [this](auto& poly) {return poly.contains(this->points.front()); });
}
// Filter points from poly to the output with the help of FilterFn.
// filter function receives two vectors:
// v1: this_point - previous_point
@ -624,6 +635,15 @@ bool polygons_match(const Polygon &l, const Polygon &r)
return true;
}
bool overlaps(const Polygons& polys1, const Polygons& polys2)
{
for (const Polygon& poly1 : polys1) {
if (poly1.overlaps(polys2))
return true;
}
return false;
}
bool contains(const Polygon &polygon, const Point &p, bool border_result)
{
if (const int poly_count_inside = ClipperLib::PointInPolygon(p, polygon.points);