knit_graphs.Course module
Course representation of a section of knitting with no parent loops.
This module contains the Course class which represents a horizontal row of loops in a knitting pattern.
- class Course(course_number: int, knit_graph: Knit_Graph[LoopT])[source]
Bases:
Loop_Sequence[LoopT]Course object for organizing loops into knitting rows.
A Course represents a horizontal row of loops in a knitting pattern. It maintains an ordered list of loops and provides methods for analyzing the structure and relationships between courses in the knitted fabric.
- __init__(course_number: int, knit_graph: Knit_Graph[LoopT]) None[source]
Initialize an empty course associated with a knit graph.
- Parameters:
knit_graph (Knit_Graph) – The knit graph that this course belongs to.
- property knit_graph: Knit_Graph[LoopT]
Returns: Knit_Graph: The knit graph that this course belongs to.
- add_loop(loop: LoopT, index: int | None = None) None[source]
Add a loop to the course at the specified index or at the end.
- Parameters:
- Raises:
ValueError – If the loop is a parent to any loops already in the course.
- in_round_with(next_course: Course[LoopT]) bool[source]
Check if the next course connects to this course in a circular pattern.
This method determines if the courses are connected in the round (circular knitting) by checking if the next course starts at the beginning of this course.
- in_row_with(next_course: Course[LoopT]) bool[source]
Check if the next course connects to this course in a flat/row pattern.
This method determines if the courses are connected in flat knitting (back and forth) by checking if the next course starts at the end of this course.
- get_faces() list[Course_Face[LoopT]][source]
- Returns:
A list of all faces that make up this course in the order that they occur in the course.
- Return type:
list[Course_Face[LoopT]]
- __str__() str[source]
Get string representation of this course.
- Returns:
String representation showing the ordered list of loops.
- Return type:
- __repr__() str[source]
Get string representation of this course for debugging.
- Returns:
String representation showing the ordered list of loops.
- Return type:
- __iter__() Iterator[LoopT]
- Returns:
An iterator over the loops in the series in their natural order.
- Return type:
Iterator[Loop]
- __len__() int
O(1) length backed by the internal loop set.
- Returns:
The total number of loops in the series.
- Return type:
- __reversed__() Iterator[LoopT]
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]
- behind_loops(other: Sequence[LoopT]) bool
- 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:
- property floats: Iterator[Float_Edge[LoopT]]
Returns: set[Float_Edge[LoopT]]: The set of yarn-floats between loops in this sequence.
- following_float_in_sequence(loop: int | LoopT) Float_Edge[LoopT] | None
- 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
- 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 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:
- in_front_of_loops(other: Sequence[LoopT]) bool
- 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:
- 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
- Parameters:
other (Iterable[LoopT]) – The sequence to test against.
- Returns:
True if the two sequences have no loops in common.
- Return type:
- loop_crosses_floats(loop: LoopT) bool
- 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:
- property loop_ids: list[int]
Returns: list[int]: The loop ids in the course in the order they occur.
- loop_is_behind(loop: LoopT) bool
- Parameters:
loop (LoopT) – The loop to check for.
- Returns:
True if the loop is behind any float in this sequence.
- Return type:
- loop_is_in_front(loop: LoopT) bool
- Parameters:
loop (LoopT) – The loop to check for.
- Returns:
True if the loop is in front of any float in this sequence.
- Return type:
- property loops_behind_floats: set[LoopT]
Returns: set[LoopT]: The set of loops behind of at least one float 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.
- next_loop_in_sequence(loop: int | LoopT) LoopT | None
- 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.