simetri.lace package

Submodules

simetri.lace.lace module

Simetri library’s interlace objects.

class simetri.lace.lace.Division(p1, p2, xform_matrix=None, **kwargs)[source]

Bases: Shape

A division is a line segment between two intersections.

Parameters:
  • p1 (tuple) – Start point.

  • p2 (tuple) – End point.

  • xform_matrix (array, optional) – Transformation matrix. Defaults to None.

  • **kwargs – Additional attributes for cosmetic/drawing purposes.

copy(section: Section | None = None, twin: Section | None = None)[source]

Create a copy of the division.

Parameters:
  • section (Section, optional) – Section object. Defaults to None.

  • twin (Section, optional) – Twin section. Defaults to None.

Returns:

A copy of the division.

Return type:

Division

property end: Intersection

Return the end intersection of the division.

Returns:

End intersection.

Return type:

Intersection

property end_points

Return the end points of the division.

Returns:

List of end points.

Return type:

list

is_connected(other: Division) bool[source]

Return True if the division is connected to another division.

Parameters:

other (Division) – Another division.

Returns:

True if connected, False otherwise.

Return type:

bool

property start: Intersection

Return the start intersection of the division.

Returns:

Start intersection.

Return type:

Intersection

class simetri.lace.lace.Fragment(points, **kwargs)[source]

Bases: Shape

A Fragment is a collection of section objects that are connected to each other. These sections are already defined. They belong to the polyline objects in a lace. Fragments can be open or closed. They are created by the lace object.

Parameters:
  • points (list) – List of points defining the fragment.

  • **kwargs – Additional attributes for cosmetic/drawing purposes.

property center

Return the center of the fragment.

Returns:

Center coordinates.

Return type:

list

property divisions

Return the divisions of the fragment.

Returns:

List of divisions.

Return type:

list

class simetri.lace.lace.Intersection(point: tuple, division1: Division, division2: Division | None = None, endpoint: bool = False, **kwargs)[source]

Bases: Shape

Intersection of two divisions. They are at the endpoints of Section objects. A division can have multiple sections and multiple intersections. They can be located at the end of a division.

Parameters:
  • point (tuple) – (x, y) coordinates of the intersection point.

  • division1 (Division) – First division.

  • division2 (Division, optional) – Second division. Defaults to None.

  • endpoint (bool, optional) – If the intersection is at the end of a division, then endpoint is True. Defaults to False.

  • **kwargs – Additional attributes for cosmetic/drawing purposes.

copy()[source]

Create a copy of the intersection.

Returns:

A copy of the intersection.

Return type:

Intersection

property point

Return the intersection point.

Returns:

Intersection point coordinates.

Return type:

list

class simetri.lace.lace.Lace(polygon_shapes: Batch | list[Shape] | None = None, polyline_shapes: Batch | list[Shape] | None = None, offset: float = 2, rtol: float | None = None, swatch: list | None = None, breakpoints: list | None = None, plait_color: Color | None = None, draw_fragments: bool = True, palette: list | None = None, color_step: int = 1, with_plaits: bool = True, area_threshold: float | None = None, radius_threshold: float | None = None, **kwargs)[source]

Bases: Batch

A Lace is a collection of ParallelPolylines objects. They are used to create interlace patterns.

Parameters:
  • polygon_shapes (Union[Batch, list[Shape]], optional) – List of polygon shapes. Defaults to None.

  • polyline_shapes (Union[Batch, list[Shape]], optional) – List of polyline shapes. Defaults to None.

  • offset (float, optional) – Offset value. Defaults to 2.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • swatch (list, optional) – Swatch list. Defaults to None.

  • breakpoints (list, optional) – Breakpoints list. Defaults to None.

  • plait_color (colors.Color, optional) – Plait color. Defaults to None.

  • draw_fragments (bool, optional) – If fragments should be drawn. Defaults to True.

  • palette (list, optional) – Palette list. Defaults to None.

  • color_step (int, optional) – Color step. Defaults to 1.

  • with_plaits (bool, optional) – If plaits should be included. Defaults to True.

  • area_threshold (float, optional) – Area threshold. Defaults to None.

  • radius_threshold (float, optional) – Radius threshold. Defaults to None.

  • **kwargs – Additional attributes for cosmetic/drawing purposes.

property all_divisions: List

Return a list of all the divisions (both main and offset) in the lace.

Returns:

List of all divisions.

Return type:

list

property center

Return the center of the lace.

Returns:

Center coordinates.

Return type:

list

copy()[source]

Returns a copy of the batch.

Returns:

A copy of the batch.

Return type:

Batch

fragment_edge_graph() Graph[source]

Return a networkx graph of the connected fragments. If two fragments have a “common” division then they are connected.

Returns:

Graph of connected fragments.

Return type:

nx.Graph

property fragment_groups

Return the fragment groups of the lace.

Returns:

Dictionary of fragment groups.

Return type:

dict

fragment_vertex_graph() Graph[source]

Return a networkx graph of the connected fragments. If two fragments have a “common” vertex then they are connected.

Returns:

Graph of connected fragments.

Return type:

nx.Graph

get_fragment_cycles()[source]

Iterate over the offset sections and create a graph of the intersections (start and end of the sections). Then find the cycles in the graph. self.d_intersections is used to map the graph nodes to the actual intersection points.

Returns:

List of fragment cycles.

Return type:

list

get_sketch()[source]

Create and return a Sketch object. Sketch is a Batch object with Shape elements corresponding to the vertices of the plaits and fragments of the Lace instance. They have ‘plaits’ and ‘fragments’ attributes to hold lists of Shape objects populated with plait and fragment vertices of the Lace instance respectively. They are used for drawing multiple copies of the original lace pattern. They are light-weight compared to the Lace objects since they only contain sufficient data to draw the lace objects. Hundreds of these objects can be used to create wallpaper patterns or other patterns without having to contain unnecessary data. They do not share points with the original Lace object.

Arguments:

None

Prerequisites:

  • A lace object to be copied.

Side effects:

None

Return:

A Sketch object.

group_fragments(tol=None)[source]

Group the fragments by the number of vertices and the area.

Parameters:

tol (float, optional) – Tolerance value. Defaults to None.

Returns:

List of grouped fragments.

Return type:

list

property intersections: List[Intersection]

Return all the intersections in the parallel_poly_list.

Returns:

List of intersections.

Return type:

list

iter_main_divisions() Iterator[source]

Iterate over the main divisions.

Yields:

Division – Division object.

iter_main_intersections() Iterator[source]

Iterate over the main intersections.

Yields:

Intersection – Intersection object.

iter_main_sections() Iterator[source]

Iterate over the main sections.

Yields:

Section – Section object.

iter_offset_divisions() Iterator[source]

Iterate over the offset divisions.

Yields:

Division – Division object.

iter_offset_intersections() Iterator[source]

Iterate over the offset intersections.

Yields:

Intersection – Intersection object.

iter_offset_sections() Iterator[source]

Iterate over the offset sections.

Yields:

Section – Section object.

property main_divisions: List[Division]

Main divisions are the divisions of the main polyline.

Returns:

List of main divisions.

Return type:

list

property offset_divisions: List[Division]

Offset divisions are the divisions of the offset polylines.

Returns:

List of offset divisions.

Return type:

list

set_fragment_groups()[source]
set_fragment_lines(n: int, offset: float, line_color: Color = Color(0.012, 0.263, 0.875), line_width=1) None[source]

Create offset lines inside the fragments of the lace.

Parameters:
  • n (int) – Number of lines.

  • offset (float) – Offset value.

  • line_color (colors.Color, optional) – Line color. Defaults to colors.blue.

  • line_width (int, optional) – Line width. Defaults to 1.

set_plait_lines(n, offset, line_color=Color(0.012, 0.263, 0.875), line_width=1)[source]

Create offset lines inside the plaits of the lace.

Parameters:
  • n (int) – Number of lines.

  • offset (float) – Offset value.

  • line_color (colors.Color, optional) – Line color. Defaults to colors.blue.

  • line_width (int, optional) – Line width. Defaults to 1.

set_plaits()[source]

Populate the self.plaits list with Plait objects. Plaits are optional for drawing. They form the under/over interlacing. They are created if the “with_plaits” argument is set to be True in the constructor. with_plaits is True by default but this can be changed by setting the auto_plaits value to False in the settings.py This method can be called by the user to create the plaits after the creation of the Lace object if they were not created initally.

  • Can be called by users.

Arguments:

None

Return:

None

Side Effects:

  • self.plaits is populated with Plait objects.

Prerequisites:

self.polyline and self.parallel_poly_list must be populated. self.divisions and self.intersections must be populated. self.overlaps must be populated.

Where used:

Lace.__init__

Notes:

This method is called by the Lace constructor. It is not for users to call directly. Without this method, the Lace object cannot be created.

class simetri.lace.lace.Overlap(intersections: list[Intersection] | None = None, sections: list[Section] | None = None, visited=False, drawable=True, **kwargs)[source]

Bases: Batch

An overlap is a collection of four connected sections.

Parameters:
  • intersections (list[Intersection], optional) – List of intersections. Defaults to None.

  • sections (list[Section], optional) – List of sections. Defaults to None.

  • visited (bool, optional) – If the overlap is visited. Defaults to False.

  • drawable (bool, optional) – If the overlap is drawable. Defaults to True.

  • **kwargs – Additional attributes for cosmetic/drawing purposes.

class simetri.lace.lace.ParallelPolyline(polyline, offset, lace, under=False, closed=True, dist_tol=None, **kwargs)[source]

Bases: Batch

A ParallelPolylines is a collection of parallel Polylines. They are defined by a main polyline and a list of offset values (that can be negative or positive).

Parameters:
  • polyline (Polyline) – Main polyline.

  • offset (float) – Offset value.

  • lace (Lace) – Lace object.

  • under (bool, optional) – If the polyline is under. Defaults to False.

  • closed (bool, optional) – If the polyline is closed. Defaults to True.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

  • **kwargs – Additional attributes for cosmetic/drawing purposes.

property sections: List[Section]

Return the sections of the parallel polyline.

Returns:

List of sections.

Return type:

list

class simetri.lace.lace.Partition(points, **kwargs)[source]

Bases: Shape

These are the polygons of the non-interlaced geometry. Fragments and partitions are scaled versions of each other.

Parameters:
  • points (list) – List of points defining the partition.

  • **kwargs – Additional attributes for cosmetic/drawing purposes.

class simetri.lace.lace.Polyline(points, closed=True, xform_matrix=None, **kwargs)[source]

Bases: Shape

Connected points, similar to Shape objects. They can be closed or open. They are defined by a sequence of points. They have divisions, sections, and intersections.

Parameters:
  • points (list) – List of points defining the polyline.

  • closed (bool, optional) – If the polyline is closed. Defaults to True.

  • xform_matrix (array, optional) – Transformation matrix. Defaults to None.

  • **kwargs – Additional attributes for cosmetic/drawing purposes.

property area

Return the area of the polygon.

Returns:

Area of the polygon.

Return type:

float

property divisions

Return the divisions of the polyline.

Returns:

List of divisions.

Return type:

list

property intersections

Return the intersections of the polyline.

Returns:

List of intersections.

Return type:

list

iter_intersections()[source]

Iterate over the intersections of the polyline.

Yields:

Intersection – Intersection object.

iter_sections() Iterator[source]

Iterate over the sections of the polyline.

Yields:

Section – Section object.

property sections

Return the sections of the polyline.

Returns:

List of sections.

Return type:

list

class simetri.lace.lace.Section(start: Intersection | None = None, end: Intersection | None = None, is_overlap: bool = False, overlap: Overlap | None = None, is_over: bool = False, twin: Section | None = None, fragment: Fragment | None = None, **kwargs)[source]

Bases: Shape

A section is a line segment between two intersections. A division can have multiple sections. Sections are used to draw the over/under plaits.

Parameters:
  • start (Intersection) – Start intersection.

  • end (Intersection) – End intersection.

  • is_overlap (bool, optional) – If the section is an overlap. Defaults to False.

  • overlap (Overlap, optional) – Overlap object. Defaults to None.

  • is_over (bool, optional) – If the section is over. Defaults to False.

  • twin (Section, optional) – Twin section. Defaults to None.

  • fragment (Fragment, optional) – Fragment object. Defaults to None.

  • **kwargs – Additional attributes for cosmetic/drawing purposes.

copy()[source]

Create a copy of the section.

Returns:

A copy of the section.

Return type:

Section

end_point()[source]

Return the end point of the section.

Returns:

End intersection.

Return type:

Intersection

property is_endpoint

Return True if the section is an endpoint.

Returns:

True if endpoint, False otherwise.

Return type:

bool

simetri.lace.lace.all_intersections(division_list: list[Division], d_intersections: dict[int, Intersection], d_connections: dict[frozenset, Intersection], loom=False) list[Intersection][source]

Find all intersections of the given divisions. Sweep-line algorithm without a self-balancing tree. Instead of a self-balancing tree, it uses a numpy array to sort and filter the divisions. For the number of divisions that are commonly needed in a lace, this is sufficiently fast. It is also more robust and much easier to understand and debug. Tested with tens of thousands of divisions but not millions. The book has a section on this algorithm. simetri.geometry.py has another version (called all_intersections) for finding intersections among a given list of divisions.

Arguments:

division_list: list of Division objects.

Side Effects:

  • Modifies the given division objects (in the division_list) in place

    by adding the intersections to the divisions’ “intersections” attribute.

  • Updates the d_intersections

  • Updates the d_connections

Return:

A list of all intersection objects among the given division list.

simetri.lace.lace.merge_nodes(division_list: list[Division], d_intersections: dict[int, Intersection], d_connections: dict[frozenset, Intersection], loom=False) list[Intersection][source]

Find all intersections of the given divisions. Sweep-line algorithm without a self-balancing tree. Instead of a self-balancing tree, it uses a numpy array to sort and filter the divisions. For the number of divisions that are commonly needed in a lace, this is sufficiently fast. It is also more robust and much easier to understand and debug. Tested with tens of thousands of divisions but not millions. The book has a section on this algorithm. simetri.geometry.py has another version (called all_intersections) for finding intersections among a given list of divisions.

Arguments:

division_list: list of division objects.

Side Effects:

  • Modifies the given division objects (in the division_list) in place

    by adding the intersections to the divisions’ “intersections” attribute.

  • Updates the d_intersections

  • Updates the d_connections

Return:

A list of all intersection objects among the given division list.

Module contents