virtual_knitting_machine.machine_components.Needle_Bed module

Representation module for needle beds on knitting machines. This module provides the Needle_Bed class which represents one bed of needles (front or back) on a knitting machine, managing both regular needles and slider needles with their associated loops and operations.

class Needle_Bed(is_front, knitting_machine)[source]

Bases: object

A structure to hold information about loops held on one bed of needles where increasing indices indicate needles moving from left to right (LEFT -> 0 1 2….N <- RIGHT of Machine). This class manages both regular needles and slider needles, tracks active sliders, and provides methods for loop manipulation and needle access operations.

needles

The needles on this bed ordered from 0 to max.

Type:

list[Needle]

sliders

The slider needles on this bed ordered from 0 to max.

Type:

list[Slider_Needle]

Parameters:
__init__(is_front, knitting_machine)[source]

Initialize a needle bed representation for the machine.

Parameters:
  • is_front (bool) – True if this is the front bed, False if it is the back bed.

  • knitting_machine (Knitting_Machine) – The knitting machine this bed belongs to.

__iter__()[source]

Iterate over the needles in this bed.

Returns:

Iterator over the needles on this bed.

Return type:

Iterator[Needle]

loop_holding_needles()[source]

Get list of needles on bed that actively hold loops.

Returns:

List of needles on bed that actively hold loops.

Return type:

list[Needle]

loop_holding_sliders()[source]

Get list of sliders on bed that actively hold loops.

Returns:

List of sliders on bed that actively hold loops.

Return type:

list[Slider_Needle]

property needle_count: int

Get the number of needles on the bed.

Returns:

The number of needles on the bed.

Return type:

int

__len__()[source]

Get the number of needles on this bed.

Returns:

Number of needles on the bed.

Return type:

int

property is_front: bool

Check if this is the front bed.

Returns:

True if this is the front bed, False if back bed.

Return type:

bool

add_loops(needle, loops, drop_prior_loops=True)[source]

Add loops to a given needle, optionally dropping existing loops as if a knit operation took place.

Parameters:
  • needle (Needle) – The needle to add the loops on.

  • loops (list[Machine_Knit_Loop]) – The loops to put on the needle if not creating with the yarn carrier.

  • drop_prior_loops (bool, optional) – If True, any loops currently held on this needle are dropped. Defaults to True.

Returns:

Returns the list of loops made with the carrier on this needle.

Return type:

list[Machine_Knit_Loop]

Warns:

Needle_Holds_Too_Many_Loops – If adding these loops would exceed maximum loop count.

drop(needle)[source]

Clear the loops held at this position as though a drop operation has been done.

Parameters:

needle (Needle) – The position to drop loops from main and slider needles.

Returns:

List of loops that were dropped.

Return type:

list[Machine_Knit_Loop]

__getitem__(item)[source]

Get an indexed needle on the bed, or find needle holding a specific loop.

Parameters:

item (Machine_Knit_Loop | Needle | slice) – The needle position to get, loop to find needle for, or slice for multiple needles.

Returns:

The needle(s) at the specified position(s) or holding the specified loop.

Return type:

Needle | list[Needle] | None

Raises:

KeyError – If needle position is out of range or item type is not supported.

get_needle_of_loop(loop)[source]

Get the needle that currently holds the specified loop.

Parameters:

loop (Machine_Knit_Loop) – The loop being searched for.

Returns:

None if the bed does not hold the loop, otherwise the needle position that holds it.

Return type:

None | Needle

sliders_are_clear()[source]

Check if no loops are on any slider needle.

Returns:

True if no loops are on a slider needle, False otherwise.

Return type:

bool