Skeletone#

class zeroheliumkit.src.anchors.Skeletone(lines: MultiLineString = <MULTILINESTRING EMPTY>)[source]#

Bases: object

Represents a collection of connected lines for routing and wireframe geometry. Provides methods for creating and manipulating MultiLineString objects.

Parameters:

lines (MultiLineString) – A collection of LineString objects representing the skeletone.

Example

>>> from zeroheliumkit import Skeletone
>>> from zeroheliumkit.settings import DARKGRAY
>>> from shapely.geometry import MultiLineString, LineString
>>> skeletone = Skeletone(MultiLineString([LineString([(0, 0), (1, 1)])]))
<SKELETONE MULTILINESTRING ((0 0, 1 1))>
>>> skeletone.add(LineString([(1, 1), (2, 2)]))
>>> print(skeletone.length)
2.8284271247461903
>>> skeletone.rotate(90, origin=(0, 0))
>>> skeletone.move(xoff=1, yoff=1)
>>> skeletone.plot(color=DARKGRAY)

Methods

add(line[, direction, ignore_crossing, chaining])

Appends a LineString to the skeleton.

buffer(offset, **kwargs)

Creates a Polygon by buffering the skeleton

copy()

Creates a deep copy of the Skeletone instance.

fix()

Fixes the skeletone by merging lines that are connected end-to-end.

mirror([aroundaxis, keep_original])

Mirrors the skeletone around the specified axis.

move([dx, dy])

Moves the skeletone by the specified offsets.

plot([ax, color])

Plots the skeleton on the given axes.

remove([line_id])

Remove a line from the skeletone

rotate([angle, origin])

Rotates the skeletone by the given angle around the origin.

scale([xfact, yfact, origin])

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

trim_line(polygon)

Cuts the skeletone with a polygon.

Attributes

boundary

The boundary points of the skeletone as a list of Point objects.

length

The total length of all lines in the skeletone.

lines

numlines

The number of lines in the skeletone.

property length: float#

The total length of all lines in the skeletone.

property boundary: list#

The boundary points of the skeletone as a list of Point objects.

property numlines: int#

The number of lines in the skeletone.

copy() Skeletone[source]#

Creates a deep copy of the Skeletone instance.

Returns:

A new instance of Skeletone with the same lines.

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

Rotates the skeletone by the given angle around the origin.

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

  • origin (tuple) – The origin point of rotation.

Returns:

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

move(dx: float = 0, dy: float = 0) Skeletone[source]#

Moves the skeletone by the specified offsets.

Parameters:
  • dx (float) – The horizontal offset to move the skeletone by.

  • dy (float) – The vertical offset to move the skeletone by.

Returns:

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

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

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

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

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

  • origin (tuple) – The origin point for scaling.

Returns:

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

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

Mirrors the skeletone around the specified axis.

Parameters:
  • aroundaxis (str, optional) – The axis around which to mirror the skeletone. Defaults to None.

  • keep_original (bool, optional) – Whether to keep the original lines after mirroring. Defaults to False.

Returns:

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

add(line: LineString, direction: float = None, ignore_crossing=False, chaining=True) Skeletone[source]#

Appends a LineString to the skeleton.

Parameters:
  • line (LineString) – The LineString to append.

  • direction (float, optional) – The direction of the LineString. Defaults to None.

  • ignore_crossing (bool, optional) – Whether to ignore crossing lines. Defaults to False.

  • chaining (bool, optional) – Whether to chain lines. Defaults to True.

Returns:

Updated instance (self) of the class with the appended line.

remove(line_id: int | tuple | list = None) Skeletone[source]#

Remove a line from the skeletone

Parameters:

line_id (int | tuple | list) – The index of the line to be removed.

Returns:

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

fix() Skeletone[source]#

Fixes the skeletone by merging lines that are connected end-to-end.

Returns:

Updated instance (self) of the class with the fixed lines.

trim_line(polygon) Skeletone[source]#

Cuts the skeletone with a polygon.

Parameters:

polygon (Polygon) – The polygon to cut the skeletone with.

Returns:

Updated instance (self) of the class with the lines cut by the polygon.

buffer(offset: float, **kwargs) Polygon[source]#

Creates a Polygon by buffering the skeleton

Parameters:
  • offset (float) – Buffering skeleton by offset

  • **kwargs – Additional keyword arguments to be passed to the buffer method

  • arguments. (See Shapely buffer docs for additional keyword)

Returns:

A polygon representing the buffered skeleton.

Return type:

Polygon

plot(ax=None, color: str = '#333333') Axes[source]#

Plots the skeleton on the given axes.

Parameters:
  • ax (matplotlib.axes.Axes, optional) – The axes on which to plot the skeleton. Defaults to None.

  • color (str, optional) – The color of the skeleton. Defaults to DARKGRAY.

Returns:

The axes with the plotted skeleton.

Return type:

matplotlib.axes.Axes