anchor module#
Anchor positioning system for shapes and schematic elements#
This module provides anchors, which are used for positioning shapes and schematic elements. Anchors represent the 9 cardinal positions (corners, edges, and center) of a bounding box.
- class Anchor(*values)[source]#
Bases:
EnumEnumeration representing anchor positions for shapes and schematic elements.
Anchors define reference points for positioning elements relative to their bounding boxes. The naming follows compass directions: N (North/Top), S (South/Bottom), E (East/Right), W (West/Left), C (Center).
>>> # Create a rectangle anchored at its top-left corner >>> rect = rectangle(10, 5, anchor=Anchor.NW) >>> # Create a rectangle centered at the origin >>> rect = rectangle(10, 5, anchor=Anchor.C)
- NW = 'NW'#
- N = 'N'#
- NE = 'NE'#
- W = 'W'#
- C = 'C'#
- E = 'E'#
- SW = 'SW'#
- S = 'S'#
- SE = 'SE'#
- horizontal()[source]#
Extract the horizontal component of an Anchor.
- Returns:
The horizontal component (W, C, or E).
- Return type:
>>> Anchor.NW.horizontal() <Anchor.W: 'W'>
- vertical()[source]#
Extract the vertical component of an Anchor.
- Returns:
The vertical component (N, C, or S).
- Return type:
>>> Anchor.NW.vertical() <Anchor.N: 'N'>
- flip()[source]#
Flip the anchor about both X and Y axes.
- Returns:
The diagonally opposite anchor position.
- Return type:
>>> Anchor.NW.flip() <Anchor.SE: 'SE'>
- to_point(bounds)[source]#
Convert an anchor to a point within the given bounding box.
- Parameters:
bounds (
tuple[float,float,float,float]) – Bounding box as (min_x, min_y, max_x, max_y).- Return type:
- Returns:
The (x, y) coordinates of the anchor position within the bounds.
>>> bounds = (0, 0, 10, 5) >>> Anchor.NW.to_point(bounds) (0, 5) >>> Anchor.C.to_point(bounds) (0.0, 0.0)