knit_graphs.loop_sequence module

Module containing the Loop Sequence class.

class Loop_Sequence[source]

Bases: Sequence[LoopT], Generic[LoopT]

Generic class for a series of loops as in a course or a course-face

__init__() None[source]
property loops_in_order: list[LoopT]

Returns: list[Loop]: The list of loops in this course.

property loop_ids: list[int]

Returns: list[int]: The loop ids in the course in the order they occur.

property has_increase: bool

Check if this course contains any yarn overs that start new wales.

Returns:

True if the course has at least one yarn over (loop with no parent loops) to start new wales.

Return type:

bool

property has_decrease: bool

Check if this course contains any decrease stitches that merge wales.

Returns:

True if the course has at least one decrease stitch (loop with multiple parent loops) merging two or more wales.

Return type:

bool

property floats: Iterator[Float_Edge[LoopT]]

Returns: set[Float_Edge[LoopT]]: The set of yarn-floats between loops in this sequence.

property loops_in_front_of_floats: set[LoopT]

Returns: set[LoopT]: The set of loops in front of at least one float in this sequence.

property loops_behind_floats: set[LoopT]

Returns: set[LoopT]: The set of loops behind of at least one float in this sequence.

loop_is_in_front(loop: LoopT) bool[source]
Parameters:

loop (LoopT) – The loop to check for.

Returns:

True if the loop is in front of any float in this sequence.

Return type:

bool

in_front_of_loops(other: Sequence[LoopT]) bool[source]
Parameters:

other (Sequence[LoopT]) – The series of loop to compare to.

Returns:

True if all loops in the other series cross in front of a float in this series.

Return type:

bool

loop_is_behind(loop: LoopT) bool[source]
Parameters:

loop (LoopT) – The loop to check for.

Returns:

True if the loop is behind any float in this sequence.

Return type:

bool

behind_loops(other: Sequence[LoopT]) bool[source]
Parameters:

other (Sequence[LoopT]) – The series of loop to compare to.

Returns:

True if all loops in the other series cross behind a float in this series.

Return type:

bool

loop_crosses_floats(loop: LoopT) bool[source]
Parameters:

[LoopT] (loop) – The loop to check for crossing floats.

Returns:

True if the given loop crosses at least one float in this sequence.

Return type:

bool

tangled_with_loops(other: Sequence[LoopT]) bool[source]
Parameters:

other (Sequence[LoopT]) – The series of loop to compare to.

Returns:

True if some loops in the given sequence fall in-front and others behind this sequence.

Return type:

bool

next_loop_in_sequence(loop: int | LoopT) LoopT | None[source]
Parameters:

loop (int | LoopT) – The index of the loop to find the following loop in the series or the loop to find the next loop in the series.

Returns:

The loop that follows the given loop in this series or None if the given loop is the last loop in the series.

Return type:

LoopT | None

Raises:

ValueError – If the given loop is not a loop in the series.

following_float_in_sequence(loop: int | LoopT) Float_Edge[LoopT] | None[source]
Parameters:

loop (int | LoopT) – The index of the loop to find the following float of or the loop to find the next loop in the series.

Returns:

The float-edge initiated at the given loop and going to a loop in the sequence or None if there is no following loop along the yarn in this sequence.

Return type:

Float_Edge[LoopT] | None

__contains__(loop: object) bool[source]

O(1) membership test backed by the internal loop set.

Parameters:

loop (object) – The object to test for membership.

Returns:

True if loop is in this sequence, False otherwise.

Return type:

bool

__getitem__(index: int) LoopT[source]
__getitem__(index: slice) list[LoopT]
Parameters:

index (int | slice) – The index or slice to retrieve.

Returns:

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

Return type:

Loop | list[Loop]

__iter__() Iterator[LoopT][source]
Returns:

An iterator over the loops in the series in their natural order.

Return type:

Iterator[Loop]

__len__() int[source]

O(1) length backed by the internal loop set.

Returns:

The total number of loops in the series.

Return type:

int

__reversed__() Iterator[LoopT][source]

Iterate over loops in reverse sequence order.

Enables reversed(seq) and communicates that the sequence has a meaningful direction — relevant for knitting since course direction (e.g. left-to-right vs. right-to-left passes) matters structurally.

Returns:

An iterator over the loops in reverse order.

Return type:

Iterator[LoopT]

count(loop: object) int[source]
Parameters:

loop (object) – The object whose occurrences to count.

Returns:

The number of times loop appears in this sequence. 1 if loop is in this sequence, 0 otherwise.

Return type:

int

index(value[, start[, stop]]) integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

isdisjoint(other: Iterable[LoopT]) bool[source]
Parameters:

other (Iterable[LoopT]) – The sequence to test against.

Returns:

True if the two sequences have no loops in common.

Return type:

bool