Перейти до основного вмісту

raygeo.nest.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: collections.abc.Sequence[collections.abc.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.

Returns: List of (dx, dy) adjustments, one per group.

ParameterTypeDescription
placement_groupscollections.abc.Sequence[collections.abc.Sequence[types.Polygon]]List of placed parts (each a list of polygons).
sheet_polytypes.PolygonSheet polygon.
spacingfloatMinimum spacing between parts.
Returnslist[tuple[float, float]]

find_max_slide()

find_max_slide(polys: collections.abc.Sequence[types.Polygon], other_polys_list: collections.abc.Sequence[collections.abc.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.

Returns: Maximum slide distance.

ParameterTypeDescription
polyscollections.abc.Sequence[types.Polygon]Polygons of the part to slide.
other_polys_listcollections.abc.Sequence[collections.abc.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.
Returnsfloat