knit_graphs.artin_wale_braids.Wale module

Module containing the Wale Class.

This module defines the Wale class which represents a vertical column of stitches in a knitted structure, maintaining the sequence and relationships between loops in that column.

class Wale(first_loop, knit_graph, end_loop=None)[source]

Bases: object

A data structure representing stitch relationships between loops in a vertical column of a knitted structure.

A wale represents a vertical sequence of loops connected by stitch edges, forming a column in the knitted fabric. This class manages the sequential relationships between loops and tracks the pull directions of stitches within the wale.

first_loop

The first (bottom) loop in the wale sequence.

Type:

Loop | None

last_loop

The last (top) loop in the wale sequence.

Type:

Loop | None

stitches

Stores the directed graph of stitch connections within this wale.

Type:

DiGraph

Parameters:
__init__(first_loop, knit_graph, end_loop=None)[source]

Initialize a wale optionally starting with a specified loop.

Parameters:
  • first_loop (Loop) – The initial loop to start the wale with.

  • knit_graph (Knit_Graph) – The knit graph that owns this wale.

  • end_loop (Loop, optional) – The loop to terminate the wale with. If no loop is provided or this loop is not found, the wale will terminate at the first loop with no child.

add_loop_to_end(loop)[source]

Add a loop to the end (top) of the wale with the specified pull direction.

Parameters:

loop (Loop) – The loop to add to the end of the wale.

Return type:

None

get_stitch_pull_direction(u, v)[source]

Get the pull direction of the stitch edge between two loops in this wale.

Parameters:
  • u (Loop) – The parent loop in the stitch connection.

  • v (Loop) – The child loop in the stitch connection.

Returns:

The pull direction of the stitch between loops u and v.

Return type:

Pull_Direction

split_wale(split_loop)[source]

Split this wale at the specified loop into two separate wales.

The split loop becomes the last loop of the first wale and the first loop of the second wale.

Parameters:

split_loop (Loop) – The loop at which to split the wale. This loop will appear in both resulting wales.

Returns:

A tuple containing: * The first wale (from start to split_loop). This will be the whole wale if the split_loop is not found. * The second wale (from split_loop to end). This will be None if the split_loop is not found.

Return type:

tuple[Wale, Wale | None]

__eq__(other)[source]
Parameters:

other (Wale) – The wale to compare.

Returns:

True if all the loops in both wales are present and in the same order. False, otherwise.

Return type:

bool

__len__()[source]

Get the number of loops in this wale.

Returns:

The total number of loops in this wale.

Return type:

int

__iter__()[source]

Iterate over loops in this wale from first to last.

Returns:

An iterator over the loops in this wale in their sequential order from bottom to top.

Return type:

Iterator[Loop]

__getitem__(item)[source]

Get loop(s) at the specified index or slice within this wale.

Parameters:

item (int | slice) – The index of a single loop or a slice for multiple loops.

Returns:

The loop at the specified index, or a list of loops for a slice.

Return type:

Loop | list[Loop]

__contains__(item)[source]

Check if a loop is contained in this wale.

Parameters:

item (Loop) – The loop to check for membership in this wale.

Returns:

True if the loop is in this wale, False otherwise.

Return type:

bool

__hash__()[source]

Get the hash value of this wale based on its first loop.

Returns:

Hash value based on the first loop in this wale.

Return type:

int

__str__()[source]
Returns:

The string representation of this wale.

Return type:

str

__repr__()[source]
Returns:

The string representation of this wale.

Return type:

str

overlaps(other)[source]

Check if this wale has any loops in common with another wale.

Parameters:

other (Wale) – The other wale to compare against for overlapping loops.

Returns:

True if the other wale has any overlapping loop(s) with this wale, False otherwise.

Return type:

bool