quilt_knit.swatch.Swatch module

Module containing the Swatch Class

class Swatch(name, knitout_program, prior_machine_state=None)[source]

Bases: object

Class that associates a knitout program with the resulting knit graph. Used for linking swatches to form Quilts.

carriage_passes

An ordered list of carriage passes in the swatch.

Type:

list[Carriage_Pass]

wale_entrances

The instructions on the bottom boundary of the swatch.

Type:

list[Wale_Boundary_Instruction]

wale_exits

The instructions on the top boundary of the swatch.

Type:

list[Wale_Boundary_Instruction]

Parameters:
  • name (str)

  • knitout_program (str | list[Knitout_Line])

  • prior_machine_state (Optional[Knitting_Machine])

__init__(name, knitout_program, prior_machine_state=None)[source]
Parameters:
  • name (str)

  • knitout_program (str | list[Knitout_Line])

  • prior_machine_state (Optional[Knitting_Machine])

get_instruction_pass(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction to find the owning carriage pass.

Returns:

None if the instruction does not belong to a carriage pass. Otherwise, the carriage pass that owns the instruction.

Return type:

Carriage_Pass | None

get_cp_index_of_instruction(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction to find the carriage pass index.

Returns:

None if the instruction does not belong to a carriage pass. Otherwise, the index of the carriage pass that owns the instruction.

Return type:

int | None

get_cp_by_index(index)[source]
Parameters:

index (int) – The index of the carriage pass.

Returns:

The carriage pass at the given index.

Return type:

Carriage_Pass

property execution_knitting_machine: Knitting_Machine

Returns: Knitting_Machine: The knitting machine state after knitout execution.

property execution_knit_graph: Knit_Graph

Returns: Knit_Graph: The knitgraph that results from the execution of the knitout program.

instruction_on_course_boundary(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction to determine if it lies on the course boundary of the swatch.

Returns:

True if the instruction is on the course boundary of the swatch, False otherwise.

Return type:

bool

instruction_on_wale_boundary(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction to determine if it lies on the wale boundary of the swatch.

Returns:

True if the instruction is on the wale boundary of the swatch, False otherwise.

Return type:

bool

get_course_boundary_instruction(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction owned by a boundary instruction.

Returns:

The course boundary instruction that owns the given instruction or None if the instruction is not on the course boundary.

Return type:

None | Course_Boundary_Instruction

get_wale_boundary_instruction(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction owned by a boundary instruction.

Returns:

The wale boundary instruction that owns the given instruction.

Return type:

Wale_Boundary_Instruction

Raises:

KeyError – If the given instruction is not on the wale boundary.

instruction_is_left_exit(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction owned by a boundary instruction.

Returns:

True if the instruction is an exit to the left boundary. False, otherwise.

Return type:

bool

instruction_is_left_entrance(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction owned by a boundary instruction.

Returns:

True if the instruction is an entrance to the left boundary. False, otherwise.

Return type:

bool

instruction_is_right_exit(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction owned by a boundary instruction.

Returns:

True if the instruction is an exit from the right boundary. False, otherwise.

Return type:

bool

instruction_is_right_entrance(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction owned by a boundary instruction.

Returns:

True if the instruction is an entrance to the right boundary. False, otherwise.

Return type:

bool

property name: str

Returns: str: The name of the swatch.

property min_needle: int

Returns: int: The position of the leftmost needle used in swatch construction.

property max_needle: int

Returns: int: The position of the rightmost needle used in swatch construction.

property width: int

Returns: int: The number of needles used in the swatch at its greatest width.

property height: int

Returns: int: The number of carriage passes in the swatch.

property constructed_height: int

Returns: int: The number of carriage passes in the swatch that create new loops. This excludes xfer passes.

property left_entrances: list[Course_Boundary_Instruction]

Returns: list[Course_Boundary_Instruction]: The boundary entrances of the left side of the swatch.

property left_exits: list[Course_Boundary_Instruction]

Returns: list[Course_Boundary_Instruction]: The boundary exits of the left side of the swatch.

property left_boundary: list[Course_Boundary_Instruction]

Returns: list[Course_Boundary_Instruction]: The boundary instructions of the left side of the swatch.

property right_entrances: list[Course_Boundary_Instruction]

Returns: list[Course_Boundary_Instruction]: The boundary entrances of the right side of the swatch.

property right_exits: list[Course_Boundary_Instruction]

Returns: list[Course_Boundary_Instruction]: The boundary exits of the right side of the swatch.

property right_boundary: list[Course_Boundary_Instruction]

Returns: list[Course_Boundary_Instruction]: The boundary instructions of the right side of the swatch.

get_carriage_pass_index_of_instruction(instruction)[source]
Parameters:

instruction (Knitout_Line) – The instruction to find the index of its owning carriage pass.

Returns:

The index of the carriage pass that executes the instruction or None if the instruction does not belong to a carriage pass.

Return type:

int | None

split_swatch_at_carriage_pass(carriage_pass_index, bottom_swatch_name, top_swatch_name)[source]
Parameters:
  • carriage_pass_index (int) – The carriage pass to start the top swatch on.

  • bottom_swatch_name (str) – The name to give the bottom swatch.

  • top_swatch_name (str) – The name to give the top swatch

Returns:

A tuple containing the following: * The bottom swatch created by the split or None if the split did not create a bottom swatch. * The top swatch created by the split or None if the split did not create a top swatch. * True if the top swatch has initial transfer pass carriage passes removed. False, otherwise.

Return type:

tuple[Swatch | None, Swatch | None, bool]

Notes

  • If the carriage pass index is less than or equal to 0, then the swatch is not split. The bottom swatch will be None and the top swatch will be this swatch.

  • If the carriage pass index is greater than the height of the swatch, then teh swatch is not split. The bottom swatch will be this swatch and the top swatch will be None.

compile_to_knitout(knitout_name=None)[source]

Writes a knitout file of the given name that executes this swatch program. :type knitout_name: Optional[str] :param knitout_name: The name of the knitout file to write. Defaults to the name of the swatch. :type knitout_name: str, option

Return type:

None

compile_to_dat(dat_name=None)[source]

Writes a shima-seiki dat file of the given name that executes this swatch program.

Parameters:

dat_name (str, optional) – The name of the dat to write. Defaults to the name of the swatch.

Return type:

None

__hash__()[source]
Returns:

The hash value of this swatch’s name.

Return type:

int

__repr__()[source]
Returns:

A string representation of this swatch based on its name.

Return type:

str

__eq__(other)[source]
Parameters:

other (Swatch) – The other swatch to compare to this swatch.

Returns:

True if this and the other swatch, share the same name. False, otherwise.

Return type:

bool

shift_swatch_rightward_on_needle_bed(shift_needle_count=0)[source]
Parameters:

shift_needle_count (int, optional) – The number of needles to shift this swatch program rightward by. Defaults to 0.

Returns:

The shifted swatch program. All needle operations will have their needle slot shifted over by the shift value.

Return type:

Swatch

Notes

  • If the shifted needle count is 0, then this returns this swatch.

find_carriage_pass_from_course_passes(course_pass_count)[source]
Parameters:

course_pass_count (int) – The target number of carriage passes that form courses by creating new loops.

Returns:

The number of carriage passes required to reach the target number of courses. If that course target is not reached, this will be the full height of the swatch.

Return type:

int

remove_cast_on_boundary()[source]

Re-initializes this swatch without the tuck operations at the bottom of each wale.

Return type:

None