Skip to content

Measurements and runtime logic

Measurements

Measurements return runtime Numbers, not Python values. Query singleton measurements inside a per-object builder.

Property / call Dimension / scope What it does and why
e.angle, corner.angle Angle in degrees; singleton where applicable Edge angle describes one segment's direction; corner angle describes the interior turn at a vertex. Use the appropriate angle for direction rules or corner-shape rules.
n == m, n != m, n < m, n <= m, n > m, n >= m Predicate; named equality alternatives n.equal(m), n.unequal(m) Builds a true/false runtime comparison. Use it in check(), choose(), or collection filters; do not pass it to Python if.
a.area, a.grid_area Area; geometry area / integer-grid area accounting area measures polygon area; grid_area uses input-grid area accounting. Use the form required by an area or density calculation, since grid rounding can change the result.
a.perimeter, e.length Length perimeter measures polygon boundary length; edge length adds segment lengths. Use them for boundary-based requirements or a measured rule threshold.
a.vertices, a.hole_count, collection.count Count Counts vertices, holes, or collection items. Use the matching count for complexity limits, opening limits, or minimum object counts.
deck.number(value, dimension="ratio") Constant Number; dimensions "length", "area", "angle", "count", "ratio" Creates a fixed number with a declared physical unit or a unit-free ratio/count. Use it when a runtime expression needs an explicit constant of the right kind.
n + m, n - m, n * m, n / m, -n, n % m Arithmetic with unit checks; modulo requires ratios Builds arithmetic to run on measured values; % gives a remainder for ratios with a positive divisor. Use it to derive thresholds while keeping unit checks.
n.minimum(m), n.maximum(m), n.rounded(places) Numeric expressions minimum()/maximum() choose between two values; rounded() rounds decimal places. Use them to bound or round a calculated value without converting it to local Python data.
geometry.bbox_width, geometry.bbox_height, geometry.bbox_min, geometry.bbox_max Length; bounding-box dimensions of the whole collection Reads the whole collection's box width, height, shorter side, or longer side. Use these for overall size limits; they do not measure each polygon separately.
geometry.measure(property, contours="all", normalized=True) Area, perimeter, vertices, holes, length, grid_area, grid_distance, radial_ratio; available properties depend on type Reads the named property with the chosen hole/outline and normalization policy. radial_ratio compares inner and outer radii about the mean outer-vertex position; use it as the defined shape test, not an exact circle fit.
box(xmin, ymin, xmax, ymax) Measured rectangle Region; all arguments are length Numbers Creates a rectangle whose coordinates come from runtime lengths. Use it for markers or search boxes whose bounds depend on layout measurements.
geometry.xmin, geometry.ymin, geometry.xmax, geometry.ymax Length; collection bounds Reads the left, bottom, right, and top coordinates of the collection box. Use them to build a measured box or compare overall placement.
n.floored() Floor a ratio; divide physical coordinates by a grid first Rounds a ratio down to the nearest integer. Use it for grid indices after dividing a physical length by the grid spacing.
geometry.aspect Ratio Divides the longer bounding-box side by the shorter side. Use it to select elongated geometry; an empty or zero-width box has no valid aspect ratio.
n.dimension Static dimension label Reads whether a Number represents length, area, angle, count, or ratio. Use it to inspect units while building helpers, before layout execution.
quantize_length(value, units=..., dbu_um=..., rounding="error") Local GridValue: authored value, steps, effective value, units, rounding Converts one physical length to integer grid steps using a chosen rounding rule. Use it when an integration already knows the real input DBU and needs an exact conversion.

Bare addition/comparison values inherit the Number's unit. Multiplication and division constants are ratios. See units and precision for accepted numeric inputs, grid rounding, and tolerances.

Runtime logic and collections

Use graph predicates for layout-dependent decisions; Python if, and, or, not, and truth conversion cannot evaluate them.

Call Result / behavior What it does and why
and_(p, q), or_(p, q), not_(p), xor(p, q) Predicate logic for Predicate operands Combines runtime conditions with AND, OR, NOT, or XOR. Use these functions because Python Boolean operators try to decide the result before the layout is known.
choose(predicate, when_true, when_false) Choose a branch at runtime; types and units must match Evaluates the selected branch based on a runtime condition. Use it when geometry or a measured value depends on layout data; both choices must have matching types and units.
collection.is_empty() Predicate Tests whether the collection has no items at execution. Use it to express absence, or to compare coverage with an empty XOR result.
collection.filter(lambda item: predicate) Same collection type where supported Tests each item and keeps the ones whose condition is true. Use it to describe custom per-object selection without a Python loop over layout shapes.
collection.map_regions(lambda item: region) Region built from each item where supported Builds polygons for each item and combines them into a Region. Use it to turn measurements or bound objects into custom marker geometry.
collection.maximum(lambda item: number, default=0) Number; default required for empty input Finds the largest chosen per-item measurement, or uses default if empty. Use it for a maximum size or a threshold based on the largest object.
collection.any(lambda item: predicate) Predicate; empty identity False Tests whether at least one item satisfies a condition; empty input gives false. Use it to trigger a rule when a matching feature exists.
collection.map_edges(lambda item: edges) Mapped Edges on collections Builds Edges for each item and combines the results. Use it when later checks need custom edge output instead of filled polygons.
collection.map_pairs(lambda item: pairs) Mapped EdgePairs on collections Builds EdgePairs for each item and combines the results. Use it to keep the two-sided marker form for custom distance or corner work.
a.map_tiles(lambda tile: region, size=(50, 50)) Region; tile size in deck units Splits the area into tiles and builds a Region from each tile. Use it for bounded local calculations with an explicit physical tile size.
collection.minimum(lambda item: number, default=0) Number; default required for empty input Finds the smallest chosen per-item measurement, or uses default if empty. Use it for a minimum size or a threshold based on the smallest object.
collection.all(lambda item: predicate) Predicate; empty identity True Tests whether every item satisfies a condition; empty input gives true. Use it for a universal requirement, adding a separate nonempty check if existence is also required.
collection.sum(lambda item: number) Number; empty identity 0 Adds one chosen measurement per item, returning zero for no items. Use it for total area, length, or other numeric totals.

Builders run once locally with symbolic items. Execution currently supports Regions, Edges, EdgePairs, Texts, and Corners.

Keep layer/rule declarations outside builders, and do not use a bound item outside its scope. Division by zero, negative measured sizing, and invalid singleton queries are execution errors.