ContinuousLineBuilder#

class zeroheliumkit.src.supercore.ContinuousLineBuilder(routing: RoutingConfig = None, layers: dict = None, objs_along: ObjsAlongConfig = None)[source]#

Bases: object

Class for building continuous lines and structures.

Parameters:
  • routing (RoutingConfig) – The routing configuration.

  • layers (dict) – A dictionary containing layer names as keys and buffer widths as values.

  • objs_along (ObjsAlongConfig) – The configuration for adding objects along the skeleton line.

Example

>>> s = Structure()
>>> s.add_layer("l1", Square(10))
>>> clb = ContinuousLineBuilder(routing=RoutingConfig(radius=10, num_segments=10),
                                layers={"l1": 2, "l2": 4},
                                objs_along=ObjsAlongConfig(structure=s, spacing=40))
>>> a = Anchor((100,0), 0, "b")
>>> clb.start(Anchor((1,2), 30, "a")).turn(-60,14).go(23,65).routeto(a).go(30,110).forward(36).build_all()

Methods

add_along_skeletone(**kwargs)

Add objects along the skeleton line.

add_anchor(name[, angle, type])

Adds an Anchor at the location of the skeletone end point with given angle and type.

add_obj(obj[, dir_snap, add_rotation])

Adds a copy of the given Structure object to the current point in a Line, applying optional rotation and directional snapping.

build_all()

Build all the layers and add objects along the skeleton line.

build_layers([layers, cap_style])

Build layers for the structure.

end(name)

Adds an anchor at the end of the skeletone

forward([length])

Creates a line and adds to a skeletone.

go([length, angle])

Combines the forward and turn methods in one action.

routeto(anchor, **kwargs)

Routes the last point in the skeletone with given anchor.

start(anchor)

Adds the given anchor to the set of anchors and initializes the starting coordinates and absolute angle.

taper(length, layers)

turn([angle, radius, num_segments])

Creates an arcline and appends to a skeletone.

Attributes

routing

The routing configuration.

layers

A dictionary containing layer names as keys and buffer widths as values.

objs_along

The configuration for adding objects along the skeleton line.

absolute_angle

The current absolute angle of the line being built.

skeletone

anchors

starting_coords

structure

routing#

The routing configuration.

layers#

A dictionary containing layer names as keys and buffer widths as values.

objs_along#

The configuration for adding objects along the skeleton line.

absolute_angle#

The current absolute angle of the line being built.

start(anchor: Anchor) ContinuousLineBuilder[source]#

Adds the given anchor to the set of anchors and initializes the starting coordinates and absolute angle.

Parameters:

anchor (Anchor) – The anchor object to be added. It should have ‘direction’ and ‘coords’ Args.

Returns:

The instance of the ContinuousLineBuilder with the updated state.

Return type:

ContinuousLineBuilder

Example

>>> anchor = Anchor(coords=(10,20), direction=90, "a")
>>> instance = ContinuousLineBuilder()
>>> instance.start(anchor)
    <MyClass object at 0x...>
forward(length: float = 1) ContinuousLineBuilder[source]#

Creates a line and adds to a skeletone.

Parameters:

length (float) – The length of the line. Default is 1.

Returns:

The instance of the ContinuousLineBuilder with the updated line.

Return type:

ContinuousLineBuilder

turn(angle: float = 90, radius: float = 1, num_segments: int = 13) ContinuousLineBuilder[source]#

Creates an arcline and appends to a skeletone.

Parameters:
  • angle (float) – turn angle of the arcline. Default is 90.

  • radius (float) – radius of the arcline. Default is 1.

  • num_segments (int) – number of segments of the arcline. Default is 13.

Returns:

The instance of the ContinuousLineBuilder with the updated arcline.

Return type:

ContinuousLineBuilder

add_anchor(name: str, angle: float = None, type: str = None) ContinuousLineBuilder[source]#

Adds an Anchor at the location of the skeletone end point with given angle and type.

Parameters:
  • name (str) – The name of the anchor.

  • angle (float, optional) – The angle of the anchor. Defaults to None.

  • type (str, optional) – The type of angle calculation. Can be “absolute”, “relative”, or None. Defaults to None.

Returns:

The instance of the ContinuousLineBuilder with the updated anchor.

Return type:

ContinuousLineBuilder

end(name: str) None[source]#

Adds an anchor at the end of the skeletone

Parameters:

name (str) – The name of the anchor to be added at the end of the skeletone.

go(length: float = 1, angle: float = 90) ContinuousLineBuilder[source]#
Combines the forward and turn methods in one action.

Routing should be set before using this method.

Parameters:
  • length (float) – The length of the straight section. Default is 1.

  • angle (float) – The angle of the turn. Default is 90.

Returns:

The instance of the ContinuousLineBuilder with the updated line and turn.

Return type:

ContinuousLineBuilder

Error

Raises ValueError if routing config is not set.

routeto(anchor: Anchor, **kwargs) ContinuousLineBuilder[source]#

Routes the last point in the skeletone with given anchor. routing should be set before using this method.

Parameters:
  • anchor (Anchor) – the anchor point to which the route will be created.

  • **kwargs – additional parameters to be passed to create_route method.

Returns:

The instance of the ContinuousLineBuilder with the updated route.

Return type:

ContinuousLineBuilder

Error

Raises ValueError if routing config is not set.

build_layers(layers: dict = None, cap_style: str = 'round', **kwargs) ContinuousLineBuilder[source]#

Build layers for the structure.

Parameters:
  • layers (dict, optional) – A dictionary containing layer names as keys and buffer widths as values. If not provided, the layers from the object’s attribute layers will be used.

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

Returns:

The instance of the ContinuousLineBuilder with the updated layers.

Return type:

ContinuousLineBuilder

add_along_skeletone(**kwargs) ContinuousLineBuilder[source]#

Add objects along the skeleton line.

Parameters:
  • structure (object) – The structure to be added along the skeleton line.

  • spacing (float) – The spacing between the added objects.

  • endpoints (tuple or bool) – The endpoints of the skeleton line where the objects should be added. If a tuple is provided, it should contain the indices of the desired endpoints. If True, the objects will be added along the entire skeleton line.

  • additional_rotation (float) – Additional rotation to be applied to the added objects.

Returns:

The instance of the ContinuousLineBuilder with the updated structure.

Return type:

ContinuousLineBuilder

build_all() ContinuousLineBuilder[source]#

Build all the layers and add objects along the skeleton line.

Returns:

The instance of the ContinuousLineBuilder with the updated structure.

Return type:

ContinuousLineBuilder

add_obj(obj: Structure, dir_snap: bool = True, add_rotation: float = None)[source]#

Adds a copy of the given Structure object to the current point in a Line, applying optional rotation and directional snapping.

Parameters:
  • obj (Structure) – The structure object to be added.

  • dir_snap (bool, optional) – If True, aligns the object’s rotation to the absolute angle of the current instance. Defaults to True.

  • add_rotation (float, optional) – An additional rotation (in degrees) to apply to the object before snapping. Defaults to None.

Returns:

None