Skip to content

Reject the points outside the bounding box of the element in ShapeElement::contains - #154

Merged
fontanf merged 1 commit into
mainfrom
element-contains-bounding-box
Nov 8, 2026
Merged

fontanf merged 1 commit into
mainfrom
element-contains-bounding-box

Conversation

@fontanf

@fontanf fontanf commented Nov 8, 2026

Copy link
Copy Markdown
Owner

ShapeElement::contains projects the point on the element and compares it with the closest point of the element, which needs a square root (hypot) for the length of the element and a call to ShapeElement::point. Shape::contains calls it on every element of the shape to check whether the point is on the boundary, so most of these calls are for elements far from the point.

The points of a line segment are in the bounding box of its ends, and the points of a circular arc in the bounding box of its circle, whose radius is at most |dx| + |dy|. A point farther than twice the tolerance from this bounding box is now rejected before the projection. The margin is twice the tolerance so that the rounding errors of ShapeElement::point can't make a rejected point contained.

Measurements

On the 62 no-fit polygons computed by the periodic packings of packingsolver on alma_02 (alma2025 dataset, item types of up to 153 vertices), no_fit_polygon goes from 23.6 s to 15.7 s in total, with the same outputs (number of components and of elements of the NFP, number of feasible elements and points). Before this change, ShapeElement::contains took 54% of the time of no_fit_polygon, mostly through Shape::contains in compute_feasible_elements_and_points.

All 714 tests pass.

…ment::contains

ShapeElement::contains projects the point on the element and compares it
with the closest point of the element, which needs a square root for the
length of the element and a call to ShapeElement::point. Shape::contains
calls it on every element of the shape to check if the point is on the
boundary, so for most of the elements, the point is far from them.

The points of a line segment are in the bounding box of its ends, and the
points of a circular arc in the bounding box of its circle, whose radius
is at most |dx| + |dy|. A point farther than twice the tolerance from this
bounding box is now rejected before the projection.
@fontanf
fontanf force-pushed the element-contains-bounding-box branch from 9a55347 to b99f18d Compare November 8, 2026 16:49
@fontanf
fontanf merged commit e18e246 into main Nov 8, 2026
3 checks passed
@fontanf
fontanf deleted the element-contains-bounding-box branch November 8, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant