knit_graphs.Loop module
Module containing the Loop Class.
This module defines the Loop class which represents individual loops in a knitting pattern. Loops are the fundamental building blocks of knitted structures and maintain relationships with parent loops, yarn connections, and float positions.
- class Loop(loop_id, yarn)[source]
Bases:
object
A class to represent a single loop structure for modeling a single loop in a knitting pattern.
The Loop class manages yarn relationships, parent-child connections for stitches, and float positioning for complex knitting structures. Each loop maintains its position in the yarn sequence and its relationships to other loops through stitch connections and floating elements.
- parent_loops
The list of parent loops that this loop is connected to through stitch edges.
- front_floats
A dictionary tracking loops that this loop floats in front of.
- add_loop_in_front_of_float(u, v)[source]
Set this loop to be in front of the float between loops u and v.
This method establishes that this loop passes in front of a floating yarn segment between two other loops.
- add_loop_behind_float(u, v)[source]
Set this loop to be behind the float between loops u and v.
This method establishes that this loop passes behind a floating yarn segment between two other loops.
- is_in_front_of_float(u, v)[source]
Check if this loop is positioned in front of the float between loops u and v.
- is_behind_float(u, v)[source]
Check if this loop is positioned behind the float between loops u and v.
- prior_loop_on_yarn()[source]
Get the loop that precedes this loop on the same yarn.
- Returns:
The prior loop on the yarn, or None if this is the first loop on the yarn.
- Return type:
Loop | None
- next_loop_on_yarn()[source]
Get the loop that follows this loop on the same yarn.
- Returns:
The next loop on the yarn, or None if this is the last loop on the yarn.
- Return type:
- has_parent_loops()[source]
Check if this loop has any parent loops connected through stitch edges.
- Returns:
True if the loop has stitch-edge parents, False otherwise.
- Return type:
- add_parent_loop(parent, stack_position=None)[source]
Add a parent loop to this loop’s parent stack.
- property loop_id: int
Get the unique identifier of this loop.
- Returns:
The id of the loop.
- Return type:
- __hash__()[source]
Return hash value based on loop_id for use in sets and dictionaries.
- Returns:
Hash value of the loop_id.
- Return type:
- __int__()[source]
Convert loop to integer representation using loop_id.
- Returns:
The loop_id as an integer.
- Return type: