Repository navigation
Conversation
… intersect The tree computed the bounding boxes of the shapes when built, but didn't keep them: all the pairs of shapes of the same leaf were then tested with 'intersect', which is expensive. The boxes are now stored and used to skip the pairs of shapes which can't intersect, in 'compute_intersecting_shapes' and in the 'intersect' queries. For strict intersections, the interiors of the boxes must overlap; otherwise, boxes closer than the tolerance are still tested.
The strict intersection test of two shapes with holes computed their boolean intersection. For shapes made of line segments, it now: - returns false if the bounding boxes don't intersect, or if an edge of the convex hull of an outline separates it from the other one; - splits each boundary (outline and holes) of each shape at its contacts with the boundary of the other shape, and returns true if the middle of a part is strictly inside the other shape; - otherwise, the interiors are either disjoint or equal: tests a point strictly inside each shape. The shapes with circular arcs still use the boolean intersection. Add a test comparing it with the boolean intersection on random pairs of polygons with holes on a grid (touching edges, shared vertices and colinear overlapping edges).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Speeds up the strict intersection tests between shapes with holes made of line segments, used e.g. by PackingSolver's
Solution::compute_overlapping_items.On a solution of the alma_02 instance (15 bins, 542 polygons of up to 1044 vertices),
compute_overlapping_itemsgoes from 3.33 s to 0.165 s.Changes
IntersectionTree: the bounding boxes of the shapes, computed when building the tree, are now stored and used to skip the pairs of shapes which can't intersect, incompute_intersecting_shapesand in theintersectqueries. For strict intersections, the interiors of the boxes must overlap; otherwise, boxes closer than the tolerance are still tested. alma_02: 3.33 s → 2.19 s.intersect(ShapeWithHoles, ShapeWithHoles, strict = true): it computed the boolean intersection of the shapes. For shapes made of line segments (outline and holes), it now:compute_intersectionson the pairs of edges whose boxes intersect), and returns true if the middle of a part is strictly inside the other shape (ShapeWithHoles::contains(point, true)); two consecutive edges without contacts are on the same side, only one of them is tested;find_point_strictly_inside).The shapes with circular arcs still use the boolean intersection. alma_02: 2.19 s → 0.165 s (2.8 ms → 0.17 ms per pair).
Tests
StrictPolygonsSameAsBooleanIntersection: 20000 random pairs of polygons with holes on a grid (rectangles, L, U and comb shapes, triangles, a diamond, shapes with one or two holes, a frame), rotated by multiples of 90 degrees and shifted by half units, so that touching edges, shared vertices and colinear overlapping edges are frequent. The result is compared with the boolean intersection: no mismatch (2993 intersecting pairs). Also run once with 200000 pairs and another seed: no mismatch (29471 intersecting pairs).