virtual_knitting_machine.machine_components.needles.slotted_position_protocol module

Module containing the Slotted_Position protocol.

class Slotted_Position(*args, **kwargs)[source]

Bases: Machine_Component[Machine_LoopT], Protocol

Protocol for machine components that have a known position relative to a needle bed slot

property slot_number: int

The slot number indicates the front-bed alignment of the given needle. For front bed needles this is equivalent to the position. For back bed needles this is dependent on the racking alignment of the beds.

Returns:

The slot number of the given component for the given racking.

Return type:

int

Notes

Racking Calculations: * R = F - B * F = R + B * B = F - R.

aligned_with_slot(slot)[source]
Parameters:

slot (int | Slotted_Position) – The slot to compare to.

Returns:

True if this is positioned at the same slot, False otherwise.

Return type:

bool

left_of_slot(slot)[source]
Parameters:

slot (int | Slotted_Position) – The slot to compare to.

Returns:

True if this is positioned left of the given slot, False otherwise.

Return type:

bool

right_of_slot(slot)[source]
Parameters:

slot (int | Slotted_Position) – The slot to compare to.

Returns:

True if this is positioned right of the given slot, False otherwise.

Return type:

bool

direction_to_slot(slot)[source]
Parameters:

slot (int) – The slot to find a direction towards.

Returns:

The direction of carriage movement from this component to the slot or None if the slots are aligned.

Return type:

Carriage_Pass_Direction | None

in_pass_direction(slot, direction)[source]
Parameters:
Returns:

True if the given slot is after this slot in the given direction. False otherwise.

Return type:

bool

__int__()[source]
Returns:

The slot number of this position.

Return type:

int

classmethod __class_getitem__(params)

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….

__init__(*args, **kwargs)
handle_violations(response_policy=None, handler=None)

Context manager that catches exceptions and routes them through the violation policy.

Parameters:
  • response_policy (ViolationResponse | Violation, optional) – The ViolationResponse policy for this code block. If given a Violation, the response will be the policy assigned to that violation in the violation policy. Defaults to the response will be the default response of the violation policy.

  • handler (Callable[..., Any], optional) – Optional handler to attempt before falling back to the policy response.

property knitting_machine: Knitting_Machine_State[Machine_LoopT, Any]

Returns: Knitting_Machine_State: The knitting machine that owns this component.

property machine_is_all_needle_racked: bool

Returns: bool: True if the knitting machine is racked for all needle knitting.

property machine_racking: int

Returns: int: The racking of the knitting machine.

property machine_specification: Knitting_Machine_Specification[Machine_LoopT]

Returns: Knitting_Machine_Specification[Machine_LoopT]: The machine specification of the machine associated with this component.

property needle_count_of_machine: int

Returns: int: The number of needles on each bed of the knitting machine. Defaults to the bed size in the knitting machine specification.

property rightmost_slot_on_machine: int

Returns: int: The rightmost slot on this knitting machine. Defaults to the standard bed size in the knitting machine specification.

set_response_for(violation, response=None)

Sets the response for the given violation to the given response.

Parameters:
  • violation (Violation) – The violation to set the response for.

  • response (ViolationResponse, optional) – The response to set for the given violation. Defaults to the default response of this policy.

property violation_policy: Knitting_Machine_Error_Policy

Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.