Anchor#

class zeroheliumkit.src.anchors.Anchor(point: Point | tuple = <POINT EMPTY>, direction: float = 0, label: str = None)[source]#

Bases: object

Represents a single anchor point with attributes such as coordinates, orientation/direction, and label. Provides methods for manipulating and visualizing the anchor point.

Parameters:
  • point (tuple | Point) – The coordinates of the anchor point.

  • direction (float) – The orientation/direction of the anchor point.

  • label (str) – The label of the anchor point.

Example

>>> from zeroheliumkit import Anchor
>>> anchor = Anchor((0, 0), 45, "A")
>>> print(anchor)
<ANCHOR (POINT (0 0), 45.0, A)>
>>> anchor.properties  # prints the properties of the anchor
-----  ----------  ---------
label  coords      direction
A      (0.0, 0.0)  45.0
-----  ----------  ---------
>>> anchor.x
0.0
>>> anchor.y
0.0
>>> anchor.coords
(0.0, 0.0)
>>> anchor.direction
45.0
>>> anchor.label
'A'

Methods

distance_to(point)

Calculates the unitless distance between this anchor and another point.

mirror([aroundaxis, update_label])

Mirrors the anchor object around the specified axis.

move([xoff, yoff])

Moves the anchor point by the specified offset in the x and y directions.

offset(distance, angle)

Moves the anchor point by the specified distance and angle.

plot([ax, color, draw_direction])

Plots the anchor point on the given axes.

rename(newlabel)

Renames the anchor with a new label.

rotate(angle[, origin])

Rotates the point and arrow direction by the specified angle around the given origin.

rotate_dir(angle)

Rotates the direction of the only the anchor by the specified angle.

scale([xfact, yfact, origin])

Scales the anchor point by the given factors along the x and y axes.

Attributes

point

direction

label

coords

The (x, y) coordinates of the anchor point as a tuple.

properties

The attributes of the anchor in a tabular format.

x

The x-coordinate of the anchor point.

y

The y-coordinate of the anchor point.

property x#

The x-coordinate of the anchor point.

property y#

The y-coordinate of the anchor point.

property coords#

The (x, y) coordinates of the anchor point as a tuple.

property properties#

The attributes of the anchor in a tabular format.

rename(newlabel: str) None[source]#

Renames the anchor with a new label.

Parameters:

newlabel (str) – The new label for the anchor.

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

Rotates the point and arrow direction by the specified angle around the given origin.

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 point and direction.

rotate_dir(angle: float) Anchor[source]#

Rotates the direction of the only the anchor by the specified angle.

Parameters:

angle (float) – The angle (in radians) by which to rotate the direction.

Returns:

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

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

Moves the anchor point by the specified offset in the x and y directions.

Parameters:
  • xoff (float) – The offset in the x direction. Default is 0.

  • yoff (float) – The offset in the y direction. Default is 0.

Returns:

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

offset(distance: float, angle: float) Anchor[source]#

Moves the anchor point by the specified distance and angle.

Parameters:
  • distance (float) – The distance to move the anchor point.

  • angle (float) – The angle in degrees at which to move the anchor point.

Returns:

Updated instance (self) of the class with the moved anchor point.

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

Scales the anchor point 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 point and direction.

mirror(aroundaxis: str = None, update_label: str = None) Anchor[source]#

Mirrors the anchor object around the specified axis.

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

  • update_label (str) – The updated label for the mirrored anchor.

Raises:

ValueError – If the aroundaxis parameter is not ‘x’, ‘y’, or None.

Returns:

Updated instance (self) of the class with the mirrored point and direction.

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

Plots the anchor point on the given axes.

Parameters:
  • ax (optional) – The axes on which to plot the anchor point. Defaults to the default axes.

  • color (str, optional) – The color of the anchor point and annotation box edge. Defaults to the default color.

  • draw_direction (bool, optional) – Whether to draw an arrow indicating the direction of the anchor. Defaults to True.

distance_to(point: tuple | Point) float[source]#

Calculates the unitless distance between this anchor and another point.

Parameters:

point (tuple | Point) – The other point to calculate the distance to.

Returns:

The distance between this anchor and a given point.

Return type:

float