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.

Type:

list[Needle | None]

Parameters:
  • loop_id (int)

  • yarn (Yarn)

  • source_needle (Needle)

__init__(loop_id, yarn, source_needle)[source]

Initialize a machine knit loop with yarn and source needle information.

Parameters:
  • loop_id (int) – Unique identifier for this loop.

  • yarn (Yarn) – The yarn this loop is part of.

  • source_needle (Needle) – The needle this loop was created on.

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:

Needle

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:

bool

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:

bool

property source_needle: Needle

Get the needle this loop was created on.

Returns:

The needle this loop was created on.

Return type:

Needle

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:

None

drop()[source]

Mark the loop as dropped by adding None to end of needle history.

Return type:

None

reverse_drop()[source]

Removes dropped status from this loop. Used for transferring needles without recording a dropped action.

Return type:

None

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

bool

__hash__()

Return hash value based on loop_id for use in sets and dictionaries.

Returns:

Hash value of the loop_id.

Return type:

int

__int__()

Convert loop to integer representation using loop_id.

Returns:

The loop_id as an integer.

Return type:

int

__lt__(other)

Compare loop_id with another loop or integer for ordering.

Parameters:

other (Loop | int) – The other loop or integer to compare with.

Returns:

True if this loop’s id is less than the other’s id.

Return type:

bool

__repr__()

Return string representation of the loop.

Returns:

String representation showing “Loop {loop_id}”.

Return type:

str

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:

None

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:

None

add_parent_loop(parent, stack_position=None)

Add a parent loop to this loop’s parent stack.

Parameters:
  • parent (Loop) – The loop to be added as a parent to this loop.

  • stack_position (int | None, optional) – The position to insert the parent into the parent stack. If None, adds the parent on top of the stack. Defaults to None.

Return type:

None

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:

bool

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:

bool

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:

bool

property loop_id: int

Get the unique identifier of this loop.

Returns:

The id of the loop.

Return type:

int

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