virtual_knitting_machine.machine_constructed_knit_graph.Machine_Knit_Loop module
Module containing the Machine_Knit_Loop class for representing loops created during machine knitting operations.
This module extends the base Loop class to capture machine-specific information including needle history, transfer operations, and machine state tracking for loops created by virtual knitting machines.
- class Machine_Knit_Loop(loop_id, yarn, source_needle)[source]
Bases:
Loop
An extension of the base Loop structure to capture information about the machine knitting process that created it.
This class tracks the complete needle history of a loop including creation, transfers, and drop operations, providing detailed machine state information for each loop throughout its lifecycle on the knitting machine.
- needle_history
The list of needles in the order that they held loops. The last element will be None if the loop is dropped from a needle.
- __init__(loop_id, yarn, source_needle)[source]
Initialize a machine knit loop with yarn and source needle information.
- Parameters:
- Raises:
Slider_Loop_Exception – If attempting to create a loop on a slider needle.
- property holding_needle: Needle | None
Get the needle currently holding this loop or None if not on a needle.
- Returns:
The needle currently holding this loop or None if not on a needle.
- Return type:
Needle | None
- property last_needle: Needle
Get the last needle that held this loop before it was dropped.
- Returns:
The last needle that held this loop before it was dropped.
- Return type:
- Raises:
AssertionError – If no needle history exists (should never happen for machine knit loops).
- property on_needle: bool
Check if loop is currently on a holding needle.
- Returns:
True if loop is currently on a holding needle, False otherwise.
- Return type:
- property dropped: bool
Check if loop is not on a holding needle (has been dropped).
- Returns:
True if loop is not on a holding needle, False otherwise.
- Return type:
- property source_needle: Needle
Get the needle this loop was created on.
- Returns:
The needle this loop was created on.
- Return type:
- transfer_loop(target_needle)[source]
Add target needle to the end of needle history for loop transfer operation.
- Parameters:
target_needle (Needle) – The needle the loop is transferred to.
- Raises:
Xfer_Dropped_Loop_Exception – If attempting to transfer a dropped loop.
- Return type:
- reverse_drop()[source]
Removes dropped status from this loop. Used for transferring needles without recording a dropped action.
- Return type:
- __eq__(other)
Check equality with another base loop based on loop_id and type.
- Parameters:
other (Loop) – The other loop to compare with.
- Returns:
True if both loops have the same class and loop_id, False otherwise.
- Return type:
- __hash__()
Return hash value based on loop_id for use in sets and dictionaries.
- Returns:
Hash value of the loop_id.
- Return type:
- __int__()
Convert loop to integer representation using loop_id.
- Returns:
The loop_id as an integer.
- Return type:
- __lt__(other)
Compare loop_id with another loop or integer for ordering.
- __repr__()
Return string representation of the loop.
- Returns:
String representation showing “Loop {loop_id}”.
- Return type:
- add_loop_behind_float(u, v)
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.
- Parameters:
u (Loop) – The first loop in the float pair.
v (Loop) – The second loop in the float pair.
- Return type:
- add_loop_in_front_of_float(u, v)
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.
- Parameters:
u (Loop) – The first loop in the float pair.
v (Loop) – The second loop in the float pair.
- Return type:
- add_parent_loop(parent, stack_position=None)
Add a parent loop to this loop’s parent stack.
- has_parent_loops()
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:
- is_behind_float(u, v)
Check if this loop is positioned behind the float between loops u and v.
- Parameters:
u (Loop) – The first loop in the float pair.
v (Loop) – The second loop in the float pair.
- Returns:
True if the float between u and v passes in front of this loop, False otherwise.
- Return type:
- is_in_front_of_float(u, v)
Check if this loop is positioned in front of the float between loops u and v.
- Parameters:
u (Loop) – The first loop in the float pair.
v (Loop) – The second loop in the float pair.
- Returns:
True if the float between u and v passes behind this loop, False otherwise.
- Return type:
- property loop_id: int
Get the unique identifier of this loop.
- Returns:
The id of the loop.
- Return type:
- next_loop_on_yarn()
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:
Loop
- prior_loop_on_yarn()
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