virtual_knitting_machine.machine_components.carriage_system.Carriage_Pass_Direction module

Enumerator module for possible carriage pass directions on knitting machines.

This module defines the two directions a carriage can move across the needle bed and provides utility functions for needle positioning, comparison, and sorting operations relative to carriage movement direction.

class Carriage_Pass_Direction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

An enumerator for the two directions the carriage can pass on the knitting machine.

Needles are oriented on the machine left to right in ascending order: Left -> 0 1 2 … N <- Right. This enum provides methods for needle comparison, positioning, and sorting operations relative to carriage movement direction.

Leftward = '-'
Rightward = '+'
opposite()[source]

Get the opposite pass direction of this direction.

Returns:

The opposite pass direction of this direction.

Return type:

Carriage_Pass_Direction

__neg__()[source]

Get the opposite direction using unary minus operator.

Returns:

The opposite pass direction.

Return type:

Carriage_Pass_Direction

__invert__()[source]

Get the opposite direction using bitwise invert operator.

Returns:

The opposite pass direction.

Return type:

Carriage_Pass_Direction

next_needle_position(needle_pos)[source]

Get the next needle position in the given direction.

Parameters:

needle_pos (int) – The needle position that we are looking for the next neighbor of.

Returns:

The next needle position in the pass direction.

Return type:

int

prior_needle_position(needle_pos)[source]

Get the prior needle position in the given direction.

Parameters:

needle_pos (int) – The needle position that we are looking for the prior neighbor of.

Returns:

The prior needle position in the pass direction.

Return type:

int

static rightward_needles_comparison(first_needle, second_needle, rack=0, all_needle_rack=False)[source]

Compare two needles for rightward carriage movement ordering.

Parameters:
  • first_needle (Needle) – First needle to test ordering.

  • second_needle (Needle) – Second needle to test order.

  • rack (int, optional) – Rack value of machine. Defaults to 0.

  • all_needle_rack (bool, optional) – True if allowing all_needle knitting on ordering. Defaults to False.

Returns:

1 if first_needle is left of second needle (rightward order), 0 if needles are in equal position at given racking, or -1 if first_needle is right of second needle (leftward order).

Return type:

int

static leftward_needles_comparison(first_needle, second_needle, rack=0, all_needle_rack=False)[source]

Compare two needles for leftward carriage movement ordering.

Parameters:
  • first_needle (Needle) – First needle to test ordering.

  • second_needle (Needle) – Second needle to test order.

  • rack (int, optional) – Rack value of machine. Defaults to 0.

  • all_needle_rack (bool, optional) – True if allowing all_needle knitting on ordering. Defaults to False.

Returns:

-1 if first_needle is to the left of second needle (rightward order), 0 if needles are in equal position at given racking, or 1 if first_needle is right of second needle (leftward order).

Return type:

int

needle_direction_comparison(first_needle, second_needle, rack=0, all_needle_rack=False)[source]

Compare two needles based on their order in this carriage pass direction.

Parameters:
  • first_needle (Needle) – First needle to test ordering.

  • second_needle (Needle) – Second needle to test order.

  • rack (int, optional) – Rack value of machine. Defaults to 0.

  • all_needle_rack (bool, optional) – True if allowing all_needle knitting on ordering. Defaults to False.

Returns:

-1 if first_needle comes after second_needle in pass direction, 0 if needles are at equal alignment given the racking, 1 if first needle comes before second_needle in pass direction.

Return type:

int

needles_are_in_pass_direction(first_needle, second_needle, rack=0, all_needle_rack=False)[source]

Check if the first needle comes before the second needle in the given pass direction.

Parameters:
  • first_needle (Needle) – First needle to test this pass direction.

  • second_needle (Needle) – Second needle to test this pass direction.

  • rack (int, optional) – Rack value of machine. Defaults to 0.

  • all_needle_rack (bool, optional) – True if allowing all_needle knitting on ordering. Defaults to False.

Returns:

True if the first needle comes before the second needle in the given pass direction, False otherwise.

Return type:

bool

static get_direction(dir_str)[source]

Return a Pass direction enum given a valid string representation.

Parameters:

dir_str (str) – String to convert to direction (“-” for Leftward, anything else for Rightward).

Returns:

Pass direction corresponding to the string.

Return type:

Carriage_Pass_Direction

sort_needles(needles, racking=0)[source]

Return needles sorted in this direction at given racking.

Parameters:
  • needles (Iterable[Needle]) – Needles to be sorted in pass direction.

  • racking (int, optional) – The racking to sort needles in, sets back bed offset. Defaults to 0.

Returns:

List of needles sorted in the pass direction.

Return type:

list[Needle]

__str__()[source]

Return string representation of the carriage pass direction.

Returns:

String representation of the direction value.

Return type:

str

__repr__()[source]

Return string representation of the carriage pass direction.

Returns:

String representation of the direction value.

Return type:

str

classmethod __contains__(member)

Return True if member is a member of this enum raises TypeError if member is not an enum member

note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum

classmethod __getitem__(name)

Return the member matching name.

classmethod __iter__()

Return members in definition order.

classmethod __len__()

Return the number of members (no aliases)