pyboxbuilder.compartments.builder.CompartmentBuilder¶
-
class pyboxbuilder.compartments.builder.CompartmentBuilder(label: str, size: tuple[float, float] | None =
None, width_ratio: float | None =None, length_ratio: float | None =None, depth: float | None =None, rounded_corners: float =0.0, holds_pieces: bool =False, cut: Cut | None =None, no_rotate: bool =False, is_card: bool =False, shape_file: str | None =None, position: tuple[float, float] | None =None, count: int | None =None, component: str | None =None, allocates: tuple[tuple[str, int], ...] =(), elements: tuple[CompartmentElement, ...] =(), element_margin: float =0.0, growable: bool =False)[source]¶ Bases:
objectConfiguration for a single interior compartment.
Size can be specified as absolute millimetres (size=) or as ratios of the box interior (width_ratio=, length_ratio=). Ratios must be in range (0.0, 1.0]. At least one sizing mode is required.
- min_footprint() tuple[str, float, float, float] | None[source]¶
Return what this compartment demands of a box that has no size yet.
- Returns:¶
(label, width, length, depth)in mm, orNonewhen the well fills whatever it is given and so demands nothing — a box whose wells all fill needs an explicit size, and says so.
- resolve_depth(interior_h: float) float[source]¶
How deep this well is cut.
Card compartments (
is_card=True) always expand to fillinterior_hwhen the box grows taller (e.g. via vertical gap absorption), giving more room for cards/sleeves. Fixed-depth piece wells always keep their exact declareddepthregardless of how tall the box becomes.
-
resolve_size(interior_w: float, interior_l: float, siblings: int =
1, *, x_tracks: int | None =None, y_tracks: int | None =None) tuple[float, float][source]¶ Resolve absolute size from ratios and/or absolute dimensions.
A ratio is a share of the room compartments actually have, not of the raw interior: the auto-layout puts a wall’s worth of spacing before, between and after them, so two wells asking for half each have to share interior - 3 × spacing. Read against the raw interior instead, ratios summing to exactly 1.0 — which FR-003a explicitly permits — overflowed every time, and the only way to make them fit was to guess the layout’s spacing at the call site (FR-000b).
- Parameters:¶
- interior_w: float¶
Box interior width in mm.
- interior_l: float¶
Box interior length in mm.
- siblings: int =
1¶ How many compartments share the interior. One well takes the interior whole, since the layout gives a lone compartment no spacing at all.
- x_tracks: int | None =
None¶ Explicit column count across width; inferred from siblings when None.
- y_tracks: int | None =
None¶ Explicit row count along length; inferred as 1 (or siblings for length-only ratios) when None.
- Returns:¶
(width, length) in mm.
-
resolved(interior_w: float, interior_l: float, interior_h: float, siblings: int =
1, *, x_tracks: int | None =None, y_tracks: int | None =None) tuple[str, float, float, float, str | None, tuple[float, float] | None, tuple[CompartmentElement, ...]][source]¶ Return this compartment as the layout engine takes it.
- Parameters:¶
- interior_w: float¶
Box interior width in mm.
- interior_l: float¶
Box interior length in mm.
- interior_h: float¶
Box interior height in mm, used when
depthisNone— the well then runs to the box’s floor.- siblings: int =
1¶ How many compartments share the interior, so a ratio can be read against the room left once the dividing walls are taken out (see
resolve_size()).- x_tracks: int | None =
None¶ Number of horizontal columns across the width (optional).
- y_tracks: int | None =
None¶ Number of vertical rows along the length (optional).
- Returns:¶
(label, width, length, depth, shape_file, position, elements).
-
allocates : tuple[tuple[str, int], ...] =
()¶ Optional explicit
((component_name, qty), ...)allocations from the project inventory.
-
component : str | None =
None¶ Optional declared inventory component name stored in this compartment.
-
count : int | None =
None¶ Optional explicit count of game pieces stored in this compartment (for summaries & packing sheets).
-
cut : Cut | None =
None¶ How this compartment’s contents come out;
Nonemeans no cut.One setting rather than three (FR-006). It used to be a flag to ask for a cut, a second to choose its kind and a third for its side — and the first two said the same thing twice, so finger_scoop=True, finger_cut=SCOOP was the way to ask for one scoop.
-
depth : float | None =
None¶ Well depth in mm.
Noneruns the well to the box’s floor.Filling the interior is what a well normally does, so it is what happens when nothing is said (FR-000). The alternative was a fixed 10mm, which is right for no box in particular and quietly wrong for every deep one.
- property derives_size : bool¶
True when this well’s footprint comes from the box, not the caller.
A ratio or a bare fill is measured on the interior’s own axes, so the layout must not rotate it afterwards — that would ask the length to hold a number worked out for the width.
-
element_margin : float =
0.0¶ Clearance added around an element pack’s bounding box when size is derived from the elements.
-
elements : tuple[CompartmentElement, ...] =
()¶ Physical game components nested inside this compartment (FR-004b).
A compartment carrying elements is an element pack: the elements are laid out in the compartment’s local frame and the pack’s bounding box is what the box-level layout engine sees, so it packs like any other rectangle.
- property fills_interior : bool¶
True when this well takes whatever footprint the box has left.
A well with no size, no ratio and no elements is one the user did not want to measure — the common case of “one well, the whole box”.
-
growable : bool =
False¶ Whether this well’s width/length may expand into leftover row slack (FR-004).
-
holds_pieces : bool =
False¶ Whether this well holds loose pieces that have to be picked out.
Off by default, which means square corners and a square floor. Rounding is opt-in rather than opt-out because most wells are shaped by what they hold — a card slot, a token silhouette, a board recess — and softening those changes a fit rather than improving it. Setting this marks the well as a tray: its corners and floor round to
depth × 2/3so a finger can sweep a piece up the curve and out (FR-044f).
-
is_card : bool =
False¶ Whether this compartment holds cards, enforcing short-wall finger cutouts (FR-068).
-
no_rotate : bool =
False¶ Prevent the layout algorithm from rotating this compartment (e.g. directional card slots).
-
position : tuple[float, float] | None =
None¶ Manual coordinate override (x, y) in mm within the interior frame.
-
shape_file : str | None =
None¶ Path to an SVG file defining the custom shape of the compartment cutout.