knitout_interpreter.knitout_execution_structures.knitout_loops module

Module containing the Knitout_Loop subclass of Machine_Knit_Loop

class Knitout_Loop(source_needle, yarn, **_loop_kwargs)[source]

Bases: Machine_Knit_Loop

__init__(source_needle, yarn, **_loop_kwargs)[source]

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

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

  • yarn (Machine_Knit_Yarn[Self]) – The yarn this loop is part of.

  • loop_id (int, optional) – A unique identifier for the loop, must be non-negative. Defaults to the next id of the knitgraph that owns the given yarn.

Raises:

Slider_Loop_Exception – If attempting to create a loop on a slider needle.

property source_instruction: Loop_Making_Instruction
Returns:

The instruction that formed this loop.

Return type:

Loop_Making_Instruction

Raises:

ValueError – If the source instruction was not set.

property dropping_instruction: Dropping_Instruction | None

Returns: Drop_Instruction | Knit_Instruction | None: The instruction that dropped this loop from the needle bed or None if the loop is still active.

property last_instruction: Dropping_Instruction | Two_Needle_Instruction | Loop_Making_Instruction

Returns: Dropping_Instruction | Two_Needle_Instruction | Loop_Making_Instruction: The last instruction to operate on this loop.

property forming_carriage_direction: Carriage_Pass_Direction

Returns: Carriage_Pass_Direction: The direction that this loop was formed in.

set_source(instruction)[source]
Parameters:

instruction (Loop_Making_Instruction) – The instruction that formed this loop.

Raises:

ValueError – If this is called when a source instruction is already known

add_transfer_instruction(xfer)[source]

Adds the given split or xfer to the transfer history of this loop. :param xfer: The split or xfer to be added to the transfer history of this loop. :type xfer: Two_Needle_Instruction

drop_from_bed(drop)[source]

Sets the instruction that drops this loop from the needle bed. :param drop: The instruction that caused the loop to drop from the needle bed. :type drop: Drop_Instruction | Knit_Instruction

Raises:

ValueError – If this loop as already dropped from the needle bed.

__lt__(other)[source]

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

__eq__(other)
Parameters:

other (Machine_Knit_Loop) – The machine knit loop to compare to.

Returns:

True if these loops have the same id and source carrier needle, False otherwise.

Return type:

bool

__hash__()
Returns:

A hash value of the tuple of the loop id, the yarn, and the source needle.

Return type:

int

__int__()

Convert loop to integer representation using loop_id.

Returns:

The loop_id as an integer.

Return type:

int

__repr__()

Return string representation of the loop.

Returns:

String representation showing “Loop {loop_id}”.

Return type:

str

add_loop_behind_started_float(back_loop)

Places the given loop behind the float started by this loop. If this loop is at the end of the yarn, nothing happens. :param back_loop: The loop to place the loop behind the float started by this loop. :type back_loop: Loop

add_loop_in_front_of_started_float(front_loop)

Places the given loop in front of the float started by this loop. If this loop is at the end of the yarn, nothing happens. :param front_loop: The loop to place the loop in front of the float started by this loop. :type front_loop: Loop

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.

drop()

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

property dropped: bool

Check if loop has been dropped from a holding needle.

Returns:

True if loop has been dropped from a holding needle, False otherwise.

Return type:

bool

property ended_float: Float_Edge[Self] | None

Returns: Float_Edge | None: The float-edge connecting the prior loop on the yarn to this loop or None if it is at the beginning of the yarn.

property has_parent_loops: bool

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

property holding_needle: Needle[Self] | 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

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 knitting_machine: Knitting_Machine_State[Self, Any]

Returns: Knitting_Machine_State[Self, Any]: The knitting machine state that made this loop.

property last_needle: Needle[Self]

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

property left_original_needle: bool

Returns: bool: True if at any point this loop was held on a needle other than its source needle.

property loop_count_on_machine: int

Returns: int: The number of loops that had been created prior to forming this loop. Use this for a time-series comparison of loops across yarns.

property loop_id: int

Get the unique identifier of this loop.

Returns:

The id of the loop.

Return type:

int

static majority_pull_direction(loops)
Parameters:

loops (Sequence[Loop]) – The loops to find the majority pull direction of.

Returns:

The majority pull direction of the given loops or Back-to-Front (i.e., knit-stitch) there are no loops.

Return type:

Pull_Direction

property next_loop_on_yarn: Self | None

Returns: Loop | None: The next loop on the yarn, or None if this is the last loop on the yarn.

property on_needle: bool

Check if loop is currently on a holding needle.

Returns:

True if loop is currently on a holding needle (i.e., has not been dropped), False otherwise.

Return type:

bool

property parent_loop_ids: list[int]

Returns: list[int]: The ids of the parent loops of this loop in their stacking order.

property prior_loop_on_yarn: Self | None

Returns: Loop | None: The prior loop on the yarn, or None if this is the first loop on the yarn.

property pull_direction: Pull_Direction

Returns: Pull_Direction: The direction that the loop was formed in based on its source needle.

property pull_directions: list[Pull_Direction]

Returns: list[Pull_Direction]: The pull direction of the stitches formed by this loop and its parents in stacking order of its parents.

put_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.

Raises:

ValueError – If u and v are not on the same yarn.

put_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.

Raises:

ValueError – If u and v are not on the same yarn.

remove_parent(parent)

Removes the given parent loop from the set of parents of this loop. If the given loop is not a parent of this loop, nothing happens. :param parent: The parent loop to remove. :type parent: Loop

property returns_to_original_needle: bool
Returns:

True if this loop returns to its source needle. False otherwise.

Return type:

bool

Notes

This does not imply that the loop never left the source needle. The loop may still be held by a needle and moved (changing this property). If the loop has been dropped, this property will be frozen in the state of the last needle that held this loop before the drop.

reverse_drop()

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

property source_needle: Needle[Self]

Get the needle this loop was created on.

Returns:

The needle this loop was created on.

Return type:

Needle

property started_float: Float_Edge[Self] | None

Returns: Float_Edge | None: The float-edge connecting this loop to the next loop on its yarn or None if it is at the end of the yarn.

transfer_loop(target_needle)

Add target needle to the end of needle history for loop transfer operation.

Parameters:

target_needle (Needle) – The needle the loop is transferred to.