virtual_knitting_machine.machine_components.needles.Sheet_Needle module

Module for managing sheet needle construction for multi-sheet knitting operations.

This module provides classes for managing needles in a layered gauging schema used in multi-sheet knitting. It includes the Sheet_Needle class which extends the base Needle class to support gauge-based positioning, and the Slider_Sheet_Needle class for slider operations within sheets.

class Sheet_Needle(is_front, sheet_pos, sheet, gauge)[source]

Bases: Needle

A needle class for managing needles in a layered gauging schema.

Sheet needles are used in multi-sheet knitting where multiple layers of knitting are created simultaneously. This class extends the base Needle class to provide sheet-aware positioning and operations.

recorded_loops

List of loops that have been recorded for this needle.

Type:

list[Machine_Knit_Loop]

Parameters:
__init__(is_front, sheet_pos, sheet, gauge)[source]

Initialize a sheet needle.

Parameters:
  • is_front (bool) – True if this is a front bed needle, False for back bed.

  • sheet_pos (int) – The position of the needle within the sheet.

  • sheet (int) – The sheet number within the gauge.

  • gauge (int) – The number of layers supported by the gauge.

property gauge: int

Get the gauge currently being used for knitting.

Returns:

The gauge (number of layers) currently knitting in.

Return type:

int

property sheet_pos: int

Get the position of the needle within its sheet.

Returns:

The position of the needle within the sheet.

Return type:

int

property sheet: int

Get the sheet number of this needle.

Returns:

The position of the sheet in the gauge.

Return type:

int

static get_sheet_pos(actual_pos, gauge)[source]

Get the sheet position from an actual needle position at a given gauge.

Parameters:
  • actual_pos (int) – The needle position on the bed.

  • gauge (int) – The number of layers supported by the gauge.

Returns:

The position in the sheet of a given needle position at a specific gauge.

Return type:

int

static get_sheet(actual_pos, sheet_pos, gauge)[source]

Get the sheet number from needle position and sheet position at a given gauge.

Parameters:
  • actual_pos (int) – The needle position on the bed.

  • sheet_pos (int) – The position in the sheet.

  • gauge (int) – The number of sheets supported by the gauge.

Returns:

The sheet of the needle given the gauging.

Return type:

int

static get_actual_pos(sheet_pos, sheet, gauge)[source]

Get the actual needle position from sheet needle components.

Parameters:
  • sheet_pos (int) – The position in the sheet.

  • sheet (int) – The sheet being used.

  • gauge (int) – The number of sheets supported by the gauge.

Returns:

The position of the needle on the bed.

Return type:

int

offset_in_sheet(offset)[source]

Get a needle offset within the same sheet.

Parameters:

offset (int) – Number of sheet positions to move.

Returns:

The needle offset by the given value in the sheet (not actual needle positions).

Return type:

Sheet_Needle

main_needle()[source]

Get the non-slider needle at this needle position.

Returns:

The non-slider needle at this needle position. If this is not a slider, this instance is returned.

Return type:

Sheet_Needle

gauge_neighbors()[source]

Get list of needles that neighbor this needle in other sheets of the same gauge.

Returns:

List of needles that neighbor this loop in other gauges.

Return type:

list[Sheet_Needle]

__add__(other)[source]

Add to this sheet needle’s position.

Parameters:

other (Sheet_Needle | Needle | int) – The needle or integer to add.

Returns:

New sheet needle with the sum position.

Return type:

Sheet_Needle

__radd__(other)[source]

Right-hand add operation for sheet needle.

Parameters:

other (Sheet_Needle | Needle | int) – The needle or integer to add.

Returns:

New sheet needle with the sum position.

Return type:

Sheet_Needle

__sub__(other)[source]

Subtract from this sheet needle’s position.

Parameters:

other (Sheet_Needle | Needle | int) – The needle or integer to subtract.

Returns:

New sheet needle with the difference position.

Return type:

Sheet_Needle

__rsub__(other)[source]

Right-hand subtract operation for sheet needle.

Parameters:

other (Sheet_Needle | Needle | int) – The needle or integer to subtract from.

Returns:

New sheet needle with the difference position.

Return type:

Sheet_Needle

__eq__(other)

Check equality with another needle.

Parameters:

other (Needle) – The other needle to compare with.

Returns:

True if needles are equal (same bed, position, and slider status).

Return type:

bool

__hash__()

Return hash value for the needle.

Returns:

Hash value based on position (negative for back needles).

Return type:

int

__index__()

Return index representation of the needle position.

Returns:

The needle position as an index.

Return type:

int

__int__()

Return integer representation of the needle position.

Returns:

The needle position.

Return type:

int

__lshift__(other)

Left shift operation (equivalent to subtraction).

Parameters:

other (Needle | int) – The needle or integer to shift by.

Returns:

New needle shifted left (position decreased).

Return type:

Needle

__lt__(other)

Compare if this needle is less than another needle or number.

Parameters:

other (Needle | int | float) – The other needle or number to compare with.

Returns:

True if this needle’s position is less than the other value. If the needles are at the same location but in opposite positions (back vs. front), the front needle is considered less than the back. This orders needles as front-to-back in a leftward carriage pass.

Return type:

bool

Raises:

TypeError – If other is not a Needle or number.

__repr__()

Return string representation of the needle.

Returns:

String representation of the needle.

Return type:

str

__rlshift__(other)

Right-hand left shift operation.

Parameters:

other (Needle | int) – The needle or integer to shift.

Returns:

New needle with shifted position.

Return type:

Needle

__rrshift__(other)

Right-hand right shift operation.

Parameters:

other (Needle | int) – The needle or integer to shift.

Returns:

New needle with shifted position.

Return type:

Needle

__rshift__(other)

Right shift operation (equivalent to addition).

Parameters:

other (Needle | int) – The needle or integer to shift by.

Returns:

New needle shifted right (position increased).

Return type:

Needle

__str__()

Return string representation of the needle.

Returns:

String representation (e.g., ‘f5’ for front needle at position 5).

Return type:

str

active_floats()

Get active floats connecting to loops on this needle.

Returns:

Dictionary of loops that are active keyed to active yarn-wise neighbors. Each key-value pair represents a directed float where key comes before value on the yarns in the system.

Return type:

dict[Machine_Knit_Loop, Machine_Knit_Loop]

add_loop(loop)

Add a loop to the set of currently held loops.

Parameters:

loop (Machine_Knit_Loop) – Loop to add onto needle.

Return type:

None

add_loops(loops)

Add multiple loops to the held set.

Parameters:

loops (list[Machine_Knit_Loop]) – List of loops to place onto needle.

Return type:

None

at_racking_comparison(other, rack=0, all_needle_racking=False)

Compare needle positions at a given racking.

Parameters:
  • other (Needle) – The other needle to compare positions with.

  • rack (int, optional) – Racking value to compare between. Defaults to 0.

  • all_needle_racking (bool, optional) – If true, account for front back alignment in all needle knitting. Defaults to False.

Returns:

1 if self > other, 0 if equal, -1 if self < other.

Return type:

int

Note

At an all needle racking, the front needle is always < the back needle, regardless of direction.

drop()

Drop all held loops by releasing them from the needle.

Returns:

The loops that were dropped.

Return type:

list[Machine_Knit_Loop]

float_overlaps_needle(u, v)

Check if a float between two loops overlaps this needle’s position.

Parameters:
Returns:

True if the float between u and v overlaps the position of this needle.

Return type:

bool

property has_loops: bool

Check if the needle is currently holding any loops.

Returns:

True if needle is holding loops, False otherwise.

Return type:

bool

property is_back: bool

Check if needle is on the back bed.

Returns:

True if needle is on the back bed, False otherwise.

Return type:

bool

property is_front: bool

Check if needle is on the front bed.

Returns:

True if needle is on front bed, False otherwise.

Return type:

bool

property is_slider: bool

Check if the needle is a slider needle.

Returns:

True if the needle is a slider, False otherwise.

Return type:

bool

static needle_at_racking_cmp(n1, n2, racking=0, all_needle_racking=False)

Static method to compare two needles at a given racking.

Parameters:
  • n1 (Needle) – First needle in comparison.

  • n2 (Needle) – Second needle in comparison.

  • racking (int, optional) – Racking value to compare between. Defaults to 0.

  • all_needle_racking (bool, optional) – If true, account for front back alignment in all needle knitting. Defaults to False.

Returns:

1 if n1 > n2, 0 if equal, -1 if n1 < n2.

Return type:

int

Note

At an all needle racking, the front needle is always < the back needle, regardless of direction.

offset(offset)

Get a needle offset by the specified amount on the same bed.

Parameters:

offset (int) – The amount to offset the needle position.

Returns:

The needle offset spaces away on the same bed.

Return type:

Needle

opposite()

Get the needle on the opposite bed at the same position.

Returns:

The needle on the opposite bed at the same position.

Return type:

Needle

property position: int

Get the index position of the needle on the machine bed.

Returns:

The index on the machine bed of the needle.

Return type:

int

property pull_direction: Pull_Direction

Get the direction this needle pulls loops during knit operations.

Returns:

BtF (Back to Front) for front needles, FtB (Front to Back) for back needles.

Return type:

Pull_Direction

racked_position_on_front(rack)

Get the position of the needle on the front bed at a given racking.

Parameters:

rack (int) – The racking value.

Returns:

The front needle position given a racking (no change for front bed needles).

Return type:

int

transfer_loops(target_needle)

Transfer all loops from this needle to a target needle.

Parameters:

target_needle (Needle) – Needle to transfer loops to.

Returns:

Loops that were transferred.

Return type:

list[Machine_Knit_Loop]

class Slider_Sheet_Needle(is_front, sheet_pos, sheet, gauge)[source]

Bases: Sheet_Needle, Slider_Needle

A slider needle class for use in gauging schema.

This class combines the functionality of Sheet_Needle and Slider_Needle to provide slider needle capabilities within a multi-sheet knitting environment.

Parameters:
__init__(is_front, sheet_pos, sheet, gauge)[source]

Initialize a slider sheet needle.

Parameters:
  • is_front (bool) – True if this is a front bed needle, False for back bed.

  • sheet_pos (int) – The position of the needle within the sheet.

  • sheet (int) – The sheet number within the gauge.

  • gauge (int) – The number of layers supported by the gauge.

__add__(other)

Add to this sheet needle’s position.

Parameters:

other (Sheet_Needle | Needle | int) – The needle or integer to add.

Returns:

New sheet needle with the sum position.

Return type:

Sheet_Needle

__eq__(other)

Check equality with another needle.

Parameters:

other (Needle) – The other needle to compare with.

Returns:

True if needles are equal (same bed, position, and slider status).

Return type:

bool

__hash__()

Return hash value for the needle.

Returns:

Hash value based on position (negative for back needles).

Return type:

int

__index__()

Return index representation of the needle position.

Returns:

The needle position as an index.

Return type:

int

__int__()

Return integer representation of the needle position.

Returns:

The needle position.

Return type:

int

__lshift__(other)

Left shift operation (equivalent to subtraction).

Parameters:

other (Needle | int) – The needle or integer to shift by.

Returns:

New needle shifted left (position decreased).

Return type:

Needle

__lt__(other)

Compare if this needle is less than another needle or number.

Parameters:

other (Needle | int | float) – The other needle or number to compare with.

Returns:

True if this needle’s position is less than the other value. If the needles are at the same location but in opposite positions (back vs. front), the front needle is considered less than the back. This orders needles as front-to-back in a leftward carriage pass.

Return type:

bool

Raises:

TypeError – If other is not a Needle or number.

__radd__(other)

Right-hand add operation for sheet needle.

Parameters:

other (Sheet_Needle | Needle | int) – The needle or integer to add.

Returns:

New sheet needle with the sum position.

Return type:

Sheet_Needle

__repr__()

Return string representation of the needle.

Returns:

String representation of the needle.

Return type:

str

__rlshift__(other)

Right-hand left shift operation.

Parameters:

other (Needle | int) – The needle or integer to shift.

Returns:

New needle with shifted position.

Return type:

Needle

__rrshift__(other)

Right-hand right shift operation.

Parameters:

other (Needle | int) – The needle or integer to shift.

Returns:

New needle with shifted position.

Return type:

Needle

__rshift__(other)

Right shift operation (equivalent to addition).

Parameters:

other (Needle | int) – The needle or integer to shift by.

Returns:

New needle shifted right (position increased).

Return type:

Needle

__rsub__(other)

Right-hand subtract operation for sheet needle.

Parameters:

other (Sheet_Needle | Needle | int) – The needle or integer to subtract from.

Returns:

New sheet needle with the difference position.

Return type:

Sheet_Needle

__str__()

Return string representation of the slider needle.

Returns:

String representation with ‘s’ suffix (e.g., ‘fs5’ for front slider at position 5, ‘bs3’ for back slider at position 3).

Return type:

str

__sub__(other)

Subtract from this sheet needle’s position.

Parameters:

other (Sheet_Needle | Needle | int) – The needle or integer to subtract.

Returns:

New sheet needle with the difference position.

Return type:

Sheet_Needle

active_floats()

Get active floats connecting to loops on this needle.

Returns:

Dictionary of loops that are active keyed to active yarn-wise neighbors. Each key-value pair represents a directed float where key comes before value on the yarns in the system.

Return type:

dict[Machine_Knit_Loop, Machine_Knit_Loop]

add_loop(loop)

Add a loop to the set of currently held loops.

Parameters:

loop (Machine_Knit_Loop) – Loop to add onto needle.

Return type:

None

add_loops(loops)

Add multiple loops to the held set.

Parameters:

loops (list[Machine_Knit_Loop]) – List of loops to place onto needle.

Return type:

None

at_racking_comparison(other, rack=0, all_needle_racking=False)

Compare needle positions at a given racking.

Parameters:
  • other (Needle) – The other needle to compare positions with.

  • rack (int, optional) – Racking value to compare between. Defaults to 0.

  • all_needle_racking (bool, optional) – If true, account for front back alignment in all needle knitting. Defaults to False.

Returns:

1 if self > other, 0 if equal, -1 if self < other.

Return type:

int

Note

At an all needle racking, the front needle is always < the back needle, regardless of direction.

drop()

Drop all held loops by releasing them from the needle.

Returns:

The loops that were dropped.

Return type:

list[Machine_Knit_Loop]

float_overlaps_needle(u, v)

Check if a float between two loops overlaps this needle’s position.

Parameters:
Returns:

True if the float between u and v overlaps the position of this needle.

Return type:

bool

property gauge: int

Get the gauge currently being used for knitting.

Returns:

The gauge (number of layers) currently knitting in.

Return type:

int

gauge_neighbors()

Get list of needles that neighbor this needle in other sheets of the same gauge.

Returns:

List of needles that neighbor this loop in other gauges.

Return type:

list[Sheet_Needle]

static get_actual_pos(sheet_pos, sheet, gauge)

Get the actual needle position from sheet needle components.

Parameters:
  • sheet_pos (int) – The position in the sheet.

  • sheet (int) – The sheet being used.

  • gauge (int) – The number of sheets supported by the gauge.

Returns:

The position of the needle on the bed.

Return type:

int

static get_sheet(actual_pos, sheet_pos, gauge)

Get the sheet number from needle position and sheet position at a given gauge.

Parameters:
  • actual_pos (int) – The needle position on the bed.

  • sheet_pos (int) – The position in the sheet.

  • gauge (int) – The number of sheets supported by the gauge.

Returns:

The sheet of the needle given the gauging.

Return type:

int

static get_sheet_pos(actual_pos, gauge)

Get the sheet position from an actual needle position at a given gauge.

Parameters:
  • actual_pos (int) – The needle position on the bed.

  • gauge (int) – The number of layers supported by the gauge.

Returns:

The position in the sheet of a given needle position at a specific gauge.

Return type:

int

property has_loops: bool

Check if the needle is currently holding any loops.

Returns:

True if needle is holding loops, False otherwise.

Return type:

bool

property is_back: bool

Check if needle is on the back bed.

Returns:

True if needle is on the back bed, False otherwise.

Return type:

bool

property is_front: bool

Check if needle is on the front bed.

Returns:

True if needle is on front bed, False otherwise.

Return type:

bool

property is_slider: bool

Check if the needle is a slider needle.

Returns:

Always returns True for Slider_Needle instances.

Return type:

bool

main_needle()

Get the non-slider needle at this needle position.

Returns:

The non-slider needle at this needle position. If this is not a slider, this instance is returned.

Return type:

Sheet_Needle

static needle_at_racking_cmp(n1, n2, racking=0, all_needle_racking=False)

Static method to compare two needles at a given racking.

Parameters:
  • n1 (Needle) – First needle in comparison.

  • n2 (Needle) – Second needle in comparison.

  • racking (int, optional) – Racking value to compare between. Defaults to 0.

  • all_needle_racking (bool, optional) – If true, account for front back alignment in all needle knitting. Defaults to False.

Returns:

1 if n1 > n2, 0 if equal, -1 if n1 < n2.

Return type:

int

Note

At an all needle racking, the front needle is always < the back needle, regardless of direction.

offset(offset)

Get a needle offset by the specified amount on the same bed.

Parameters:

offset (int) – The amount to offset the needle position.

Returns:

The needle offset spaces away on the same bed.

Return type:

Needle

offset_in_sheet(offset)

Get a needle offset within the same sheet.

Parameters:

offset (int) – Number of sheet positions to move.

Returns:

The needle offset by the given value in the sheet (not actual needle positions).

Return type:

Sheet_Needle

opposite()

Get the needle on the opposite bed at the same position.

Returns:

The needle on the opposite bed at the same position.

Return type:

Needle

property position: int

Get the index position of the needle on the machine bed.

Returns:

The index on the machine bed of the needle.

Return type:

int

property pull_direction: Pull_Direction

Get the direction this needle pulls loops during knit operations.

Returns:

BtF (Back to Front) for front needles, FtB (Front to Back) for back needles.

Return type:

Pull_Direction

racked_position_on_front(rack)

Get the position of the needle on the front bed at a given racking.

Parameters:

rack (int) – The racking value.

Returns:

The front needle position given a racking (no change for front bed needles).

Return type:

int

property sheet: int

Get the sheet number of this needle.

Returns:

The position of the sheet in the gauge.

Return type:

int

property sheet_pos: int

Get the position of the needle within its sheet.

Returns:

The position of the needle within the sheet.

Return type:

int

transfer_loops(target_needle)

Transfer all loops from this needle to a target needle.

Parameters:

target_needle (Needle) – Needle to transfer loops to.

Returns:

Loops that were transferred.

Return type:

list[Machine_Knit_Loop]

get_sheet_needle(needle, gauge, slider=False)[source]

Convert a standard needle to a sheet needle with the given gauge.

Parameters:
  • needle (Needle) – The original needle to convert.

  • gauge (int) – The gauge of the sheet.

  • slider (bool, optional) – True if returning a slider needle. Defaults to False.

Returns:

Sheet needle created from the standard needle given the gauging schema.

Return type:

Sheet_Needle