MultiAnchor#

class zeroheliumkit.src.anchors.MultiAnchor(multipoint: list = None)[source]#

Bases: object

Represents a collection of multiple anchor points. Provides methods for manipulating and visualizing multiple anchor points.

Parameters:

multipoint (list) – A list of Anchor objects.

Example

>>> from zeroheliumkit import MultiAnchor, Anchor
>>> anchor1 = Anchor((0, 0), 0, "A")
>>> anchor2 = Anchor((1, 1), 45, "B")
>>> ma = MultiAnchor([anchor1, anchor2])
>>> print(ma)
<MULTIANCHOR ['A', 'B']>
>>> ma.labels
['A', 'B']
>>> ma.label_exist('A')
True
>>> ma.label_exist('C')
False
>>> ma["B]
<ANCHOR (POINT (1 1), 45.0, B)>
>>> ma.add(Anchor((2, 2), 90, "C"))
>>> ma.remove("A")
>>> print(ma)
<MULTIANCHOR ['B', 'C']>

Methods

add([points])

Adds one or more Anchor objects to the MultiAnchor.

copy([upd_labels_with_suffix])

Creates a deep copy of the MultiAnchor instance.

has_label(label)

Checks if a label exists in the list of labels.

mirror([aroundaxis, update_labels, ...])

Mirrors the multipoint anchors around a specified axis.

modify(label[, new_name, new_xy, new_direction])

Modifies the properties of an anchor.

move([xoff, yoff])

Moves the anchors by the specified offsets.

plot([ax, color, draw_direction])

Plots the anchors on a given axis.

remove(*args)

Removes the specified anchors from the multipoint.

rotate(angle[, origin])

Rotates all anchors by a given angle around a specified origin point.

scale([xfact, yfact, origin])

Scales the multipoint by the given factors along the x and y axes.

Attributes

multipoint

The list of Anchor objects.

labels

The list of labels of the anchors in the MultiAnchor.

multipoint#

The list of Anchor objects.

property labels: list#

The list of labels of the anchors in the MultiAnchor.

has_label(label: str | list) bool[source]#

Checks if a label exists in the list of labels.

Parameters:

label (str) – The label to check.

Returns:

True if the label exists, False otherwise.

Return type:

bool

copy(upd_labels_with_suffix: str = None) MultiAnchor[source]#

Creates a deep copy of the MultiAnchor instance. Optionally updates the labels of the anchors with a specified suffix.

Parameters:

upd_labels_with_suffix (str) – The suffix to append to each label.

Returns:

A new instance of MultiAnchor with the same multipoint anchors

Return type:

MultiAnchor

rotate(angle: float, origin: tuple = (0, 0)) MultiAnchor[source]#

Rotates all anchors by a given angle around a specified origin point.

Parameters:
  • angle (float) – The angle of rotation in degrees.

  • origin (tuple, optional) – The origin point of rotation. Defaults to (0, 0).

Returns:

Updated instance (self) of the class with the rotated anchors.

Return type:

MultiAnchor

move(xoff: float = 0, yoff: float = 0) MultiAnchor[source]#

Moves the anchors by the specified offsets.

Parameters:
  • xoff (float) – The horizontal offset to move the anchors by. Default is 0.

  • yoff (float) – The vertical offset to move the anchors by. Default is 0.

Returns:

Updated instance (self) of the class with the moved anchors.

Return type:

MultiAnchor

scale(xfact: float = 1.0, yfact: float = 1.0, origin: tuple = (0, 0)) MultiAnchor[source]#

Scales the multipoint by the given factors along the x and y axes.

Parameters:
  • xfact (float) – The scaling factor along the x-axis. Default is 1.0.

  • yfact (float) – The scaling factor along the y-axis. Default is 1.0.

  • origin (tuple) – The origin point for scaling. Default is (0, 0).

Returns:

Updated instance (self) of the class with the scaled anchors.

Return type:

MultiAnchor

mirror(aroundaxis: str = None, update_labels: bool = True, keep_original: bool = False) MultiAnchor[source]#

Mirrors the multipoint anchors around a specified axis.

Parameters:
  • aroundaxis (str) – The axis around which to mirror the anchors.

  • update_labels (bool) – Whether to update the labels of the mirrored anchors.

  • keep_original (bool) – Whether to keep the original anchors.

Returns:

Updated instance (self) of the class with the mirrored anchors.

Return type:

MultiAnchor

remove(*args: str) MultiAnchor[source]#

Removes the specified anchors from the multipoint.

Parameters:

args (str) – The labels of the anchors to be removed. If no arguments are provided, all anchors will be removed.

Returns:

Updated instance (self) of the class with the specified anchors removed.

Return type:

MultiAnchor

modify(label: str, new_name: str = None, new_xy: tuple = None, new_direction: float | int = None) MultiAnchor[source]#

Modifies the properties of an anchor.

Parameters:
  • label (str) – The anchor to modify.

  • new_name (str, optional) – The new name for the anchor. Defaults to None.

  • new_xy (tuple, optional) – The new coordinates (x, y) for the anchor. Defaults to None.

  • new_direction (float | int, optional) – The new direction for the anchor. Defaults to None.

Returns:

Updated instance (self) of the class with the modified anchor.

Return type:

MultiAnchor

add(points: list[Anchor] | Anchor = []) MultiAnchor[source]#

Adds one or more Anchor objects to the MultiAnchor.

Parameters:

points (list[Anchor] | Anchor, optional) – Anchor object(s) to be added. Defaults to an empty list.

Returns:

Updated instance (self) of the class with the added anchors.

Return type:

MultiAnchor

Raises:

ValueError – If any of the Anchor objects being added have a label that already exists in the MultiAnchor.

plot(ax=None, color: str = None, draw_direction: bool = True) None[source]#

Plots the anchors on a given axis.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – The axis on which to plot the anchors. If not provided, a new axis will be created.

  • color (str, optional) – The color of the anchors.

  • draw_direction (bool, optional) – Whether to draw the direction of the anchors.