From 3da135b98111bb1b65b019b5fc910a1fcd41bdaf Mon Sep 17 00:00:00 2001 From: Andy Salnikov Date: Mon, 2 Dec 2024 14:30:48 -0800 Subject: [PATCH] Improve performance of ConvexPolygon::overlap method. Calculation of Polygon overlaps with Circle and other Polygon gives precise answer, these methods were made to return true/false. This also helps with performance of overlap calculation for UnionRegions composed of polygons. --- src/ConvexPolygon.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ConvexPolygon.cc b/src/ConvexPolygon.cc index e001068..733dfc7 100644 --- a/src/ConvexPolygon.cc +++ b/src/ConvexPolygon.cc @@ -358,22 +358,22 @@ Relationship ConvexPolygon::relate(Ellipse const & e) const { } TriState ConvexPolygon::overlaps(Box const &b) const { - // Due to approximations we cannot know exact answer. + // Relation with box uses approximations, we cannot know exact answer. return _relationship_to_overlaps(relate(b)); } TriState ConvexPolygon::overlaps(Circle const &c) const { - // Due to approximations we cannot know exact answer. - return _relationship_to_overlaps(relate(c)); + // Circle relation is exact, not-disjoint means they overlap. + return TriState((relate(c) & DISJOINT) == 0); } TriState ConvexPolygon::overlaps(ConvexPolygon const &p) const { - // Due to approximations we cannot know exact answer. - return _relationship_to_overlaps(relate(p)); + // Polygon relation is exact, not-disjoint means they overlap. + return TriState((relate(p) & DISJOINT) == 0); } TriState ConvexPolygon::overlaps(Ellipse const &e) const { - // Due to approximations we cannot know exact answer. + // Relation with ellipse uses approximations, we cannot know exact answer. return _relationship_to_overlaps(relate(e)); }