Pular para o conteúdo principal

raygeo.geo.algo.nest2d.gravity

Gravity optimization for nesting layouts.

Provides binary-search gravity sliding to tighten packing by sliding parts down and left as far as possible without overlapping.

Functions

apply_gravity()

apply_gravity(
placement_groups: Sequence[Sequence[types.Polygon]],
sheet_poly: types.Polygon,
spacing: float,
) -> list[tuple[float, float]]

Apply gravity sliding to tighten a nesting layout.

Iterates Y and X passes until no movement occurs (max 10 passes). Returns a (dx, dy) adjustment for each input group in order.

ParameterTypeDescription
placement_groupsSequence[Sequence[types.Polygon]]List of placed parts (each a list of polygons).
sheet_polytypes.PolygonSheet polygon.
spacingfloatMinimum spacing between parts.
Returnslist[tuple[float, float]]List of (dx, dy) adjustments, one per group.
ComplexityO(passes * n * m) where passes ≤ 10.

Gravity tightening: before vs after

Gravity tightening: before vs after

find_max_slide()

find_max_slide(
polys: Sequence[types.Polygon],
other_polys_list: Sequence[Sequence[types.Polygon]],
sheet_bounds: tuple[float, float, float, float],
sheet_poly: types.Polygon,
axis: str,
spacing: float,
) -> float

Find the maximum distance a part can slide in the negative axis direction.

Uses binary search with polygon overlap and containment checks.

ParameterTypeDescription
polysSequence[types.Polygon]Polygons of the part to slide.
other_polys_listSequence[Sequence[types.Polygon]]Polygons of all other placed parts (grouped).
sheet_boundstuple[float, float, float, float]Sheet bounding box (min_x, min_y, max_x, max_y).
sheet_polytypes.PolygonSheet polygon.
axisstr"x" or "y" — axis to slide along.
spacingfloatMinimum spacing between parts.
ReturnsfloatMaximum slide distance.
ComplexityO(log range * n * m) for binary search with overlap checks.