Repository navigation
Return the feasible positions of null area of the general NFP - #151
Merged
Merged
Conversation
The NFP of two general shapes is the union of the convex NFPs of their convex parts. But a position on the boundaries of several convex NFPs, strictly inside none of them, doesn't make the shapes overlap, even if it is strictly inside their union. The union, a MultiShapeWithHoles, can't represent these positions: when the orbiting shape fits exactly a hole of the fixed shape, the NFP had no hole instead of a single feasible point, and when it fits exactly the width of a slot, the NFP had no slit instead of a feasible line segment. no_fit_polygon now returns a NoFitPolygonOutput, with the union in nfp, and the feasible line segments and points strictly inside it in feasible_elements and feasible_points. A feasible line segment is on the parts of the boundaries of two convex NFPs which overlap in opposite directions, and a feasible point is at an intersection of the boundaries of convex NFPs, so only these candidates are checked. The elements of the convex NFPs strictly inside the union of the other ones are removed first, and IntersectionTree::find_shape, which stops at the first shape containing a point, makes the checks fast enough: on the sawtooth self-pairing test, no_fit_polygon goes from about 4.6 s to about 10.5 s.
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.
Problem
The general
no_fit_polygon(shapes with holes) is the union of the convex NFPs of the convex parts of the shapes. A position on the boundaries of several convex NFPs, but strictly inside none of them, doesn't make the shapes overlap, even though it is strictly inside their union. AMultiShapeWithHolescan't represent these positions of null area, so they were lost:Changes
no_fit_polygon(const ShapeWithHoles&, const ShapeWithHoles&)now returns aNoFitPolygonOutput:nfp: the regions, as before;feasible_elements: line segments strictly insidenfpwhose points don't make the shapes overlap;feasible_points: isolated points strictly insidenfpwhich don't make the shapes overlap.Callers need to use
.nfpto get the previous result.A feasible line segment lies on the parts of the boundaries of two convex NFPs which overlap in opposite directions (always line segments, the convex NFPs being convex). A feasible point lies at an intersection of the boundaries of convex NFPs. Only these candidates are checked: not strictly inside any convex NFP, and strictly inside
nfp. The last check matters because the boundaries of the convex NFPs may be slightly outside of the computed union.Before computing the intersections, the elements of the convex NFPs strictly inside the union of the other convex NFPs are removed, by walking along each element from one convex NFP to the next.
New
IntersectionTree::find_shape(point, strict, condition), which stops at the first shape containing the point, with a condition evaluated before the containment check (used here as a cheap bounding-box filter).Performance
Simple cases are barely affected. On the sawtooth self-pairing test (
Issue558SawtoothSelfPairing, 442 vertices, ~13k convex NFPs),no_fit_polygongoes from about 4.6 s to about 10.5 s, mostly spent computing the ~7M intersections between the remaining elements.Tests
New
NoFitPolygonFeasibleTestsuite: square and disk in holes, slots and notches of exactly their size, plus a loose-fit control. Each test checks the expected feasible elements and points, that these positions don't make the shapes overlap, and that the positions strictly inside the NFP around them do. All 714 tests pass.