Polygon geometry¶
Booleans and topology¶
| Call | Result / behavior | What it does and why |
|---|---|---|
and_(a, b) |
Intersection; Region or Edges for matching operands |
Returns the area or edge portions shared by a and b. Use it to clip material to a mask or find common coverage. |
or_(a, b) |
Union; matching geometry types | Returns the combined covered area or edges of both inputs. Use it to form one material set before checking it. |
not_(a, b) |
Subtraction; bounded complement is not_(boundary, a) |
Returns the part of a left after removing b. Use it for cutouts or pre-check exclusions; subtraction can create new boundaries. |
join(a, b, ...) |
Concatenate matching Region, Edges, EdgePairs, or Check; preserves duplicates |
Appends items without merging or removing copies. Use it when all source shapes or finding streams must be kept, including duplicates. |
a.raw() |
Use stored polygons; cannot undo an earlier merge | Uses the stored polygon objects as candidates. Use it when object identity or duplicates matter; it cannot recover shapes already lost in a merge. |
a.merged(point_touch=None) |
Merge polygons using the deck's point-touch policy | Builds the polygon union using the chosen point-touch rule. Use it to remove overlap and internal seams before whole-shape selection or measurement. |
a.implicit(point_touch=None) |
Use union semantics; keep stored contours | Keeps stored outlines but treats their union as material in checks. Use it when checks should ignore internal seams without discarding the stored shapes. |
xor(a, b) |
Symmetric difference; xor(a, b).is_empty() compares coverage |
Returns coverage present in only one input. Use it to locate shape differences; an empty result means equal covered area. |
geometry.unique() |
Remove exact duplicates; keep neighbors separate; Regions, Edges, EdgePairs | Removes exact copies of the same geometry without joining nearby pieces. Use it to avoid duplicate markers while keeping separate neighboring shapes. |
geometry.transformed(...) |
Same type; move, rotate, mirror, or scale geometry | Moves, rotates, mirrors, or scales geometry, and can move it into a named input context. Use it for explicit placement or alignment before cross-input comparisons. |
Region Booleans accept point_touch=.... join() preserves duplicates; Boolean
union combines coverage. .raw() cannot recover objects lost in an earlier merge.
Topology and transforms
GeometryPolicy(point_touch="separate") is the default. "join" allows
point-connected contours; "separate" splits components that meet only at a point.
The policy applies to layer reads, Region Booleans, merging, and square sizing,
including measured grow/shrink. An explicit operation option wins.
Merging after a Boolean with the same policy is redundant. Merging after join()
or marker polygonization can change results. Whole-object selection and density
can observe raw objects versus merged components.
transformed() defaults to translation=(0, 0), rotation=0, mirror=False,
magnification=1, and destination=None. Use destination for an explicit
coordinate-context conversion; input alignment and placement are never inferred.
Polygon selection¶
These methods keep whole source polygons. Use Booleans to construct clipped geometry.
| Call | Selects / options | What it does and why |
|---|---|---|
a.interacting(b), a.not_interacting(b) |
Interaction / inverse; selector can also be Edges | Keeps whole polygons that touch or overlap b; not_interacting() keeps the rest. Use it to select source shapes without changing their outlines. |
a.interacting(b, minimum=1, maximum=3, include_self=False) |
Inclusive counts; also on not_interacting |
Keeps polygons interacting with the allowed number of selector objects. Use it for neighbor-count rules; raw copies count separately and include_self controls self-counting. |
a.inside(b), a.not_inside(b) |
Inside / inverse | Keeps whole polygons inside b; the inverse keeps those not inside. Use it for zone-based rules without cutting shapes at the zone edge. |
a.with_measurement(property, minimum=None, maximum=None, ...) |
Area, perimeter, perimeter_proxy, bbox_width, bbox_height, bbox_min, bbox_max, aspect, vertices, holes |
Keeps polygons by the selected measure, such as perimeter, box size, or hole count. perimeter_proxy is half the perimeter; use the named measure that the rule actually requires. |
a.filter(lambda polygon: predicate) |
Select by a per-polygon condition | Keeps each polygon only when its runtime condition is true. Use it to combine several measurements in one custom selection. |
a.area_between(minimum=None, maximum=None) |
Per-polygon area interval | Keeps whole polygons with area in the chosen range. Use it to target small islands or large shapes while keeping their outlines. |
a.covering(b), a.not_covering(b) |
Covering / inverse | Keeps whole polygons covering selector polygons in b; the inverse keeps the rest. Use it to find source shapes that fully cover required geometry. |
a.overlapping(b), a.not_overlapping(b) |
Positive-area overlap / inverse | Keeps whole polygons sharing positive area with b; the inverse keeps those without it. Use it when boundary touches alone should not select a shape. |
a.outside(b), a.not_outside(b) |
Outside / inverse | Keeps whole polygons outside b; the inverse keeps those not outside. Use it to select material outside a zone rather than subtracting that zone. |
a.with_center_neighbors(reference, radius=..., minimum=...) |
Select by center-neighbor radius and count | Counts reference bounding-box centers strictly within the radius of each source center and keeps sources meeting the minimum. Use it for center-based neighbor rules; coincident copies count. |
a.bbox.width_between(minimum=None, maximum=None) |
Per-polygon bounding-box width | Keeps polygons whose axis-aligned box has the chosen X width. Use it for overall X-size rules, not a narrow neck inside a polygon. |
a.bbox.height_between(minimum=None, maximum=None) |
Per-polygon bounding-box height | Keeps polygons whose axis-aligned box has the chosen Y height. Use it for overall Y-size rules without changing the polygons into rectangles. |
Ranges default to minimum <= value < maximum. Supply at least one bound.
Set include_minimum, include_maximum, or inverse to change the selection.
Equal bounds need both endpoints included; reversed or empty ranges are errors.
with_measurement() also accepts contours="all" / "hull" and normalized=True / False.
Bounding-box selectors measure X/Y extents, not geometric width.
Select by zone without clipping
ordinary_core = core.outside(special_zone)
special_core = core.inside(special_zone)
crossing_core = core.not_inside(special_zone).not_outside(special_zone)
deck.rule("CORE.CROSSING", "Core polygons must not cross zone boundaries", violations=crossing_core)
A polygon crossing the boundary belongs to neither inside nor outside.
The selections may not cover the whole input. Use and_(core, special_zone) or
not_(core, special_zone) to clip instead; this creates new boundaries for
later width/spacing checks. Edge-selection boundary rules differ.
Sizing and morphology¶
All calls return Region. Keep stage order: shrink/grow and grow/shrink differ.
| Call | Behavior / key options | What it does and why |
|---|---|---|
a.offset(dx, dy=None, corner="cutoff_90") |
Contour offset; nonzero axes need matching signs | Moves the polygon outline by the chosen X/Y amounts using a corner cutoff. Use it when the rule requires contour offsets rather than square sizing. |
a.extents(), a.extent() |
Per-polygon boxes / one collection bounding box | extents() makes a bounding rectangle for each polygon; extent() makes one for the whole collection. Use the former for shape boxes and the latter for overall coverage bounds. |
a.grow_directional(north=0, south=0, east=0, west=0, rotation=0) |
Directional structuring element | Grows by separate amounts north, south, east, and west, with optional rotation. Use it for margins that differ by direction. |
a.smooth(tolerance) |
Simplify within tolerance | Reduces outline detail using the given tolerance. Use it to remove small changes in the boundary when the rule explicitly allows that simplification. |
a.hulls(), a.holes() |
Outer hulls / openings | hulls() returns outer outlines with holes filled; holes() returns the openings. Use them to check outer material and inner openings separately; hulls are not convex hulls. |
a.under_over(distance, corner="cutoff_90") |
Offset inward, then outward | Offsets inward and then outward by the same distance. Use it to remove narrow features using the selected contour-corner rule. |
a.over_under(distance, corner="cutoff_90") |
Offset outward, then inward | Offsets outward and then inward by the same distance. Use it to fill narrow gaps using the selected contour-corner rule. |
a.grow(distance, point_touch=None), a.shrink(distance, point_touch=None) |
Square sizing; nonnegative literal or measured length | grow() adds material outward; shrink() removes it inward with square sizing. Use them to build margins or cores; narrow features may disappear when shrinking. |
a.grow_inside(boundary, dx=..., dy=..., steps=..., corner="cutoff_90") |
Clip after every growth stage | Grows in repeated steps and clips to boundary after each step. Use it when material must stay inside a permitted area throughout growth. |
a.opened(distance) |
Square shrink then grow | Shrinks and then grows with a square shape. Use it to remove features too small to survive the shrink, while preserving the required stage order. |
a.closed(distance) |
Square grow then shrink | Grows and then shrinks with a square shape. Use it to close small gaps under the stated square-sizing rule. |
Contour recipes (under_over, over_under) use native offsets. opened and
closed use square sizing. These are morphological tests, not analytic width measurements.
Offset behavior
Distances must be finite and nonnegative for these recipes. Both contour stages use the same distance, corner mode, and grid policy. A zero offset may normalize geometry; it does not guarantee raw duplicates survive. An inward offset can remove narrow features that the outward stage cannot restore. Closing can fill gaps.
Contour corner modes: "cutoff_0", "cutoff_45", "cutoff_90" (default),
"cutoff_135", "cutoff_168", "cutoff_179".