Positioning
momapy.positioning
Functions for positioning layout elements and related objects relatively to other objects.
This module provides utilities for calculating positions relative to layout elements, fitting bounding boxes around collections of elements, and setting positions of builder objects. Functions support Points, Bboxes, Nodes, and their builder variants.
Example
from momapy.positioning import right_of, fit from momapy.geometry import Point point = Point(0, 0) new_point = right_of(point, 10) print(new_point) Point(x=10, y=0)
Functions:
| Name | Description |
|---|---|
above_left_of |
Return a point above and to the left of the given object. |
above_of |
Return a point above the given object at the specified distance. |
above_right_of |
Return a point above and to the right of the given object. |
below_left_of |
Return a point below and to the left of the given object. |
below_of |
Return a point below the given object at the specified distance. |
below_right_of |
Return a point below and to the right of the given object. |
cross_hv_of |
Return the point at the horizontal cross of obj1 and vertical cross of obj2. |
cross_vh_of |
Return the point at the vertical cross of obj1 and horizontal cross of obj2. |
fit |
Compute a bounding box that fits the given elements with optional margins. |
fraction_of |
Return the position and angle at a given fraction along an arc. |
left_of |
Return a point to the left of the given object at the specified distance. |
mid_of |
Return the midpoint between two objects. |
right_of |
Return a point to the right of the given object at the specified distance. |
set_above_left_of |
Set obj1's position above and to the left of obj2. |
set_above_of |
Set obj1's position above obj2 at the specified distance. |
set_above_right_of |
Set obj1's position above and to the right of obj2. |
set_below_left_of |
Set obj1's position below and to the left of obj2. |
set_below_of |
Set obj1's position below obj2 at the specified distance. |
set_below_right_of |
Set obj1's position below and to the right of obj2. |
set_cross_hv_of |
Set obj1's position at the horizontal-vertical cross of obj2 and obj3. |
set_cross_vh_of |
Set obj1's position at the vertical-horizontal cross of obj2 and obj3. |
set_fit |
Set obj's dimensions and position to fit the given elements. |
set_fraction_of |
Set obj's position and rotation along an arc at the given fraction. |
set_left_of |
Set obj1's position to the left of obj2 at the specified distance. |
set_mid_of |
Set obj1's position to the midpoint between obj2 and obj3. |
set_position |
Set the position of a builder object. |
set_right_of |
Set obj1's position to the right of obj2 at the specified distance. |
above_left_of
above_left_of(obj: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance1: float, distance2: float | None = None) -> Point
Return a point above and to the left of the given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
A Point, Bbox, LayoutElement, or their builder variants. For Nodes, uses the north-west anchor point. |
required |
distance1
|
float
|
The vertical distance (northward) from the object. |
required |
distance2
|
float | None
|
The horizontal distance (westward) from the object. If None, defaults to distance1. |
None
|
Returns:
| Type | Description |
|---|---|
Point
|
A new Point located above and to the left of the object. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If obj is not a supported type. |
Example
point = momapy.geometry.Point(10, 10) above_left_of(point, 5) Point(x=5, y=5)
Source code in src/momapy/positioning.py
above_of
above_of(obj: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance: float) -> Point
Return a point above the given object at the specified distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
A Point, Bbox, LayoutElement, or their builder variants. For Nodes, uses the north anchor point. |
required |
distance
|
float
|
The vertical distance from the object's reference point. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
A new Point located above the object. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If obj is not a supported type. |
Example
point = momapy.geometry.Point(0, 10) above_of(point, 5) Point(x=0, y=5)
Source code in src/momapy/positioning.py
above_right_of
above_right_of(obj: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance1: float, distance2: float | None = None) -> Point
Return a point above and to the right of the given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
A Point, Bbox, LayoutElement, or their builder variants. For Nodes, uses the north-east anchor point. |
required |
distance1
|
float
|
The vertical distance (northward) from the object. |
required |
distance2
|
float | None
|
The horizontal distance (eastward) from the object. If None, defaults to distance1. |
None
|
Returns:
| Type | Description |
|---|---|
Point
|
A new Point located above and to the right of the object. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If obj is not a supported type. |
Example
point = momapy.geometry.Point(0, 10) above_right_of(point, 5, 10) Point(x=10, y=5)
Source code in src/momapy/positioning.py
below_left_of
below_left_of(obj: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance1: float, distance2: float | None = None) -> Point
Return a point below and to the left of the given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
A Point, Bbox, LayoutElement, or their builder variants. For Nodes, uses the south-west anchor point. |
required |
distance1
|
float
|
The vertical distance (southward) from the object. |
required |
distance2
|
float | None
|
The horizontal distance (westward) from the object. If None, defaults to distance1. |
None
|
Returns:
| Type | Description |
|---|---|
Point
|
A new Point located below and to the left of the object. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If obj is not a supported type. |
Example
point = momapy.geometry.Point(10, 0) below_left_of(point, 5) Point(x=5, y=5)
Source code in src/momapy/positioning.py
below_of
below_of(obj: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance: float) -> Point
Return a point below the given object at the specified distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
A Point, Bbox, LayoutElement, or their builder variants. For Nodes, uses the south anchor point. |
required |
distance
|
float
|
The vertical distance from the object's reference point. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
A new Point located below the object. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If obj is not a supported type. |
Example
point = momapy.geometry.Point(0, 0) below_of(point, 10) Point(x=0, y=10)
Source code in src/momapy/positioning.py
below_right_of
below_right_of(obj: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance1: float, distance2: float | None = None) -> Point
Return a point below and to the right of the given object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
A Point, Bbox, LayoutElement, or their builder variants. For Nodes, uses the south-east anchor point. |
required |
distance1
|
float
|
The vertical distance (southward) from the object. |
required |
distance2
|
float | None
|
The horizontal distance (eastward) from the object. If None, defaults to distance1. |
None
|
Returns:
| Type | Description |
|---|---|
Point
|
A new Point located below and to the right of the object. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If obj is not a supported type. |
Example
point = momapy.geometry.Point(0, 0) below_right_of(point, 5, 10) Point(x=10, y=5)
Source code in src/momapy/positioning.py
cross_hv_of
cross_hv_of(obj1: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder) -> Point
Return the point at the horizontal cross of obj1 and vertical cross of obj2.
Creates a point using obj1's y-coordinate and obj2's x-coordinate. Useful for creating elbow connector points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Object providing the y-coordinate (Point, Bbox, Node, or builder). |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Object providing the x-coordinate (Point, Bbox, Node, or builder). For Bboxes and Nodes, uses their center points. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
A Point at (obj2.x, obj1.y). |
Example
p1 = momapy.geometry.Point(0, 5) p2 = momapy.geometry.Point(10, 0) cross_hv_of(p1, p2) Point(x=10, y=5)
Source code in src/momapy/positioning.py
cross_vh_of
cross_vh_of(obj1: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder) -> Point
Return the point at the vertical cross of obj1 and horizontal cross of obj2.
Creates a point using obj1's x-coordinate and obj2's y-coordinate. Useful for creating elbow connector points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Object providing the x-coordinate (Point, Bbox, Node, or builder). |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Object providing the y-coordinate (Point, Bbox, Node, or builder). For Bboxes and Nodes, uses their center points. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
A Point at (obj1.x, obj2.y). |
Example
p1 = momapy.geometry.Point(5, 0) p2 = momapy.geometry.Point(0, 10) cross_vh_of(p1, p2) Point(x=5, y=10)
Source code in src/momapy/positioning.py
fit
fit(elements: Collection[LayoutElement | LayoutElementBuilder | Bbox | BboxBuilder | Point | PointBuilder], xsep: float = 0, ysep: float = 0) -> Bbox
Compute a bounding box that fits the given elements with optional margins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
Collection[LayoutElement | LayoutElementBuilder | Bbox | BboxBuilder | Point | PointBuilder]
|
A collection of Points, Bboxes, LayoutElements, or their builder variants to fit within the bounding box. |
required |
xsep
|
float
|
Horizontal margin to add to both sides of the bounding box. |
0
|
ysep
|
float
|
Vertical margin to add to both sides of the bounding box. |
0
|
Returns:
| Type | Description |
|---|---|
Bbox
|
A Bbox that tightly contains all elements plus the specified margins. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If elements is empty. |
TypeError
|
If an element has an unsupported type. |
Example
points = [momapy.geometry.Point(0, 0), momapy.geometry.Point(10, 10)] bbox = fit(points, xsep=2, ysep=2) print(bbox.position) Point(x=5.0, y=5.0)
Source code in src/momapy/positioning.py
fraction_of
fraction_of(arc_layout_element: SingleHeadedArc | DoubleHeadedArc, fraction: float) -> tuple[Point, float]
Return the position and angle at a given fraction along an arc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arc_layout_element
|
SingleHeadedArc | DoubleHeadedArc
|
An arc layout element (SingleHeadedArc or DoubleHeadedArc). |
required |
fraction
|
float
|
A value between 0.0 and 1.0 representing the position along the arc. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Point, float]
|
A tuple containing: - The Point at the specified fraction along the arc. - The angle (in radians) of the tangent at that position. |
Example
arc = some_single_headed_arc pos, angle = fraction_of(arc, 0.5) # Midpoint of arc
Source code in src/momapy/positioning.py
left_of
left_of(obj: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance: float) -> Point
Return a point to the left of the given object at the specified distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
A Point, Bbox, LayoutElement, or their builder variants. For Nodes, uses the west anchor point. |
required |
distance
|
float
|
The horizontal distance from the object's reference point. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
A new Point located to the left of the object. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If obj is not a supported type. |
Example
point = momapy.geometry.Point(10, 0) left_of(point, 5) Point(x=5, y=0)
Source code in src/momapy/positioning.py
mid_of
mid_of(obj1: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder) -> Point
Return the midpoint between two objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
First object (Point, Bbox, Node, or builder). |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Second object (Point, Bbox, Node, or builder). For Bboxes and Nodes, uses their center points. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
A Point at the midpoint between the two objects. |
Example
p1 = momapy.geometry.Point(0, 0) p2 = momapy.geometry.Point(10, 10) mid_of(p1, p2) Point(x=5.0, y=5.0)
Source code in src/momapy/positioning.py
right_of
right_of(obj: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance: float) -> Point
Return a point to the right of the given object at the specified distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
A Point, Bbox, LayoutElement, or their builder variants. For Nodes, uses the east anchor point. |
required |
distance
|
float
|
The horizontal distance from the object's reference point. |
required |
Returns:
| Type | Description |
|---|---|
Point
|
A new Point located to the right of the object. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If obj is not a supported type. |
Example
point = momapy.geometry.Point(0, 0) right_of(point, 10) Point(x=10, y=0)
Source code in src/momapy/positioning.py
set_above_left_of
set_above_left_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance1: float, distance2: float | None = None, anchor: str | None = None)
Set obj1's position above and to the left of obj2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
The reference object to position relative to. |
required |
distance1
|
float
|
The vertical distance from obj2. |
required |
distance2
|
float | None
|
The horizontal distance from obj2. Defaults to distance1 if None. |
None
|
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_above_of
set_above_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance: float, anchor: str | None = None)
Set obj1's position above obj2 at the specified distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
The reference object to position relative to. |
required |
distance
|
float
|
The vertical distance from obj2. |
required |
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_above_right_of
set_above_right_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance1: float, distance2: float | None = None, anchor: str | None = None)
Set obj1's position above and to the right of obj2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
The reference object to position relative to. |
required |
distance1
|
float
|
The vertical distance from obj2. |
required |
distance2
|
float | None
|
The horizontal distance from obj2. Defaults to distance1 if None. |
None
|
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_below_left_of
set_below_left_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance1: float, distance2: float | None = None, anchor: str | None = None)
Set obj1's position below and to the left of obj2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
The reference object to position relative to. |
required |
distance1
|
float
|
The vertical distance from obj2. |
required |
distance2
|
float | None
|
The horizontal distance from obj2. Defaults to distance1 if None. |
None
|
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_below_of
set_below_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance: float, anchor: str | None = None)
Set obj1's position below obj2 at the specified distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
The reference object to position relative to. |
required |
distance
|
float
|
The vertical distance from obj2. |
required |
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_below_right_of
set_below_right_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance1: float, distance2: float | None = None, anchor: str | None = None)
Set obj1's position below and to the right of obj2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
The reference object to position relative to. |
required |
distance1
|
float
|
The vertical distance from obj2. |
required |
distance2
|
float | None
|
The horizontal distance from obj2. Defaults to distance1 if None. |
None
|
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_cross_hv_of
set_cross_hv_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder, obj3: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder, anchor: str | None = None)
Set obj1's position at the horizontal-vertical cross of obj2 and obj3.
Creates a point using obj2's y-coordinate and obj3's x-coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Object providing the y-coordinate. |
required |
obj3
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Object providing the x-coordinate. |
required |
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_cross_vh_of
set_cross_vh_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder, obj3: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder, anchor: str | None = None)
Set obj1's position at the vertical-horizontal cross of obj2 and obj3.
Creates a point using obj2's x-coordinate and obj3's y-coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Object providing the x-coordinate. |
required |
obj3
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Object providing the y-coordinate. |
required |
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_fit
set_fit(obj: NodeBuilder | BboxBuilder, elements: Collection[Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder], xsep: float = 0, ysep: float = 0, anchor: str | None = None)
Set obj's dimensions and position to fit the given elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
NodeBuilder | BboxBuilder
|
The builder object to resize and position. |
required |
elements
|
Collection[Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder]
|
Collection of elements to fit within obj. |
required |
xsep
|
float
|
Horizontal margin around the fitted elements. |
0
|
ysep
|
float
|
Vertical margin around the fitted elements. |
0
|
anchor
|
str | None
|
Optional anchor name on obj to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_fraction_of
set_fraction_of(obj: NodeBuilder, arc_layout_element: SingleHeadedArc | DoubleHeadedArc, fraction: float, anchor: str | None = None)
Set obj's position and rotation along an arc at the given fraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
NodeBuilder
|
The node builder to position and rotate. |
required |
arc_layout_element
|
SingleHeadedArc | DoubleHeadedArc
|
The arc to position along. |
required |
fraction
|
float
|
Position along the arc (0.0 to 1.0). |
required |
anchor
|
str | None
|
Optional anchor name on obj to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_left_of
set_left_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance: float, anchor: str | None = None)
Set obj1's position to the left of obj2 at the specified distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
The reference object to position relative to. |
required |
distance
|
float
|
The horizontal distance from obj2. |
required |
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_mid_of
set_mid_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder, obj3: Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder, anchor: str | None = None)
Set obj1's position to the midpoint between obj2 and obj3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
First reference object. |
required |
obj3
|
Point | PointBuilder | Bbox | BboxBuilder | Node | NodeBuilder
|
Second reference object. |
required |
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|
Source code in src/momapy/positioning.py
set_position
set_position(obj: NodeBuilder | BboxBuilder, position: Point | PointBuilder, anchor: str | None = None)
Set the position of a builder object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
NodeBuilder | BboxBuilder
|
The builder object to position (NodeBuilder or BboxBuilder). |
required |
position
|
Point | PointBuilder
|
The target position as a Point or PointBuilder. |
required |
anchor
|
str | None
|
Optional anchor name to align with the position. If specified, the object is shifted so that its anchor point aligns with the given position. |
None
|
Example
builder = momapy.builder.get_or_make_builder_cls(MyNode)() set_position(builder, momapy.geometry.Point(100, 100), anchor="center")
Source code in src/momapy/positioning.py
set_right_of
set_right_of(obj1: NodeBuilder | BboxBuilder, obj2: Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder, distance: float, anchor: str | None = None)
Set obj1's position to the right of obj2 at the specified distance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
NodeBuilder | BboxBuilder
|
The builder object to position. |
required |
obj2
|
Point | PointBuilder | Bbox | BboxBuilder | LayoutElement | LayoutElementBuilder
|
The reference object to position relative to. |
required |
distance
|
float
|
The horizontal distance from obj2. |
required |
anchor
|
str | None
|
Optional anchor name on obj1 to align with the calculated position. |
None
|