polygon_in_bbox
Functionpolygon_in_bbox(
states: list[State],
x: float,
y: float,
width: float,
height: float,
sides: int = 6,
rotation: float = 0,
alignment: ElementAlignment = <ElementAlignment.PRESERVE: 'preserve'>,
element_rotation_offset: float = 0,
element_rotation_offset_fn: Optional[Callable[[float], float]] = None
) -> list[State]
Arrange states around a regular polygon inscribed in a bounding box.
Alternative specification to polygon() for users who think in terms of bounding boxes. The polygon will be inscribed in the specified rectangle, with its size limited by the smaller dimension.
Parameters
-
states - List of states to arrange
-
x - X coordinate of bounding box top-left corner
-
y - Y coordinate of bounding box top-left corner
-
width - Width of bounding box
-
height - Height of bounding box
-
sides - Number of polygon sides
-
rotation - Rotation offset in degrees
-
alignment - How to align each element
-
element_rotation_offset - Additional rotation offset
-
element_rotation_offset_fn - Function(edge_angle) -> rotation offset
Returns
New list of states with polygon positions Raises: ValueError: If sides < 3 ValueError: If width or height is zero or negative
Examples
# Hexagon in 400x400 box
polygon_in_bbox(states, 0, 0, 400, 400, sides=6)
# Pentagon in rectangular box (limited by height)
polygon_in_bbox(states, -100, -150, 200, 300, sides=5)
# Equivalent to polygon():
# polygon_in_bbox(states, 0, 0, 400, 400, sides=6)
# == polygon(states, center=Point2D(), radius=200, sides=6)