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
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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
- __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:
- __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]
- 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.