quilt_knit.swatch.wale_wise_merging.Wale_Wise_Connection module

Module containing the Wale_Wise_Connection class.

class Wale_Wise_Connection(bottom_swatch, top_swatch, bottom_leftmost_needle_position=0, bottom_rightmost_needle_position=None, top_leftmost_needle_position=0, top_rightmost_needle_position=None, remove_cast_ons=True)[source]

Bases: Swatch_Connection

A Class for tracking the needle ranges between two swatches to be merged wale-wise (bottom to top).

Parameters:
  • bottom_swatch (Swatch)

  • top_swatch (Swatch)

  • bottom_leftmost_needle_position (int)

  • bottom_rightmost_needle_position (Optional[int])

  • top_leftmost_needle_position (int)

  • top_rightmost_needle_position (Optional[int])

  • remove_cast_ons (bool)

__init__(bottom_swatch, top_swatch, bottom_leftmost_needle_position=0, bottom_rightmost_needle_position=None, top_leftmost_needle_position=0, top_rightmost_needle_position=None, remove_cast_ons=True)[source]
Parameters:
  • bottom_swatch (Swatch) – The bottom swatch in the connection.

  • top_swatch (Swatch) – The top swatch in the connection.

  • bottom_leftmost_needle_position (int, optional) – The leftmost needle position to merge from the bottom swatch. Defaults to 0.

  • bottom_rightmost_needle_position (int, optional) – The rightmost needle position to merge from the bottom swatch. Defaults to the width of the bottom swatch.

  • top_leftmost_needle_position (int, optional) – The leftmost needle position to merge into the top swatch. Defaults to 0.

  • top_rightmost_needle_position (int, optional) – The rightmost needle position to merge into the top swatch. Defaults to the width of the top swatch.

  • remove_cast_ons (bool, optional) – Whether to remove cast-on operations from the top swatch before merging. Defaults to True.

property top_swatch: Swatch

Returns: Swatch: The top swatch merged into by this connection.

property bottom_swatch: Swatch

Returns: Swatch: The bottom swatch merged from by this connection.

property bottom_interval: Interval

Returns: Interval: The interval of needle slots to merge from the bottom swatch.

property top_interval: Interval

Returns: Interval: The interval of needle slots to merge to the top swatch.

property bottom_left_needle_position: int

Returns: int: The bottom left needle slot to merge from.

property bottom_right_needle_position: int

Returns: int: The bottom right needle slot to merge from.

property top_left_needle_position: int

Returns: int: The top left needle slot to merge to.

property top_right_needle_position: int

Returns: int: The top right needle slot to merge to.

__contains__(swatch)
Parameters:

swatch (Swatch | None) – The swatch to check for in this connection. A None value will return False.

Returns:

True if the swatch is involved in this connection. False, otherwise.

Return type:

bool

__eq__(other_connection)
Parameters:

other_connection (Swatch_Connection) – The other swatch connection to compare to.

Returns:

True if other_connection is of the same type and connects the same swatches and has the same intervals. False, otherwise.

Return type:

bool

__hash__()
Returns:

Hash of the tuple of the from_swatch, to_swatch, from_interval, and to_interval.

Return type:

int

__post_init__()

Checks that the intervals are correct after the connection has been initialized.

Raises:

TypeError – If the intervals are incorrect.

Return type:

None

__repr__()
Returns:

The string representation of this connection.

Return type:

str

__str__()
Returns:

The string representation of this connection.

Return type:

str

connects_same_swatches(other_connection)
Parameters:

other_connection (Swatch_Connection) – The other swatch connection to compare to.

Returns:

True if this and the other connection connect the same swatches. False, otherwise.

Return type:

bool

envelops(other_connection)
Parameters:

other_connection (Swatch_Connection) – The other swatch connection to compare to.

Returns:

True if the range of needle connections of this swatch’s intervals envelops the intervals in the other connection. False otherwise.

Return type:

bool

Notes

  • This method does not test for equality of the swatches in this and the other connection.

property from_interval: Interval

Returns: Interval: The interval of connection on the from-swatch.

merged_connection(other_connection)
Parameters:

other_connection (Swatch_Connection) – The other connection to merge with.

Returns:

The merged swatch connection.

Return type:

Swatch_Connection

Raises:

NotImplementedError – Implemented in subclass.

Notes

  • This method does not test for equality of the swatches merged into the interval.

  • This method does not test for overlap or gaps between the intervals.

overlaps(other_connection)
Parameters:

other_connection (Swatch_Connection) – The other swatch connection to compare to.

Returns:

True if the range of needle connections overlaps the intervals in the other connection. False otherwise.

Return type:

bool

Notes

  • This method does not test for equality of the swatches in this and the other connection.

range_matches(other_connection)
Parameters:

other_connection (Swatch_Connection) – The other swatch connection to compare to.

Returns:

True if the range of needle connections to and from intervals are identical. False otherwise.

Return type:

bool

Notes

  • This method does not test for equality of the swatches in this and the other connection.

swap_from_swatch(new_swatch, interval_shift=0)
Parameters:
  • new_swatch (Swatch) – The new from swatch in the resulting swatch connection.

  • interval_shift (int, optional) – The amount to shift the interval by when swapping the from_swatch. Negative will shift the interval down. Defaults to 0.

Returns:

A new connection with the same intervals and the from-swatch swapped for the new given swatch.

Return type:

Swatch_Connection

swap_matching_swatch(new_swatch, matching_swatch, interval_shift=0)
Parameters:
  • new_swatch (Swatch) – The new swatch to swap into the place of the matching swatch.

  • matching_swatch (Swatch) – The matching swatch to swap out of the connection.

  • interval_shift (int, optional) – The amount to shift the interval on the matching swatch side. Negative will shift the interval down. Defaults to 0.

Returns:

The swatch connection formed by swapping the new swatch into place of the matched swatch and shifting it by the given interval. If this connection does not contain the matching swatch, this connection is returned unchanged.

Return type:

Swatch_Connection

swap_to_swatch(new_swatch, interval_shift=0)
Parameters:
  • new_swatch (Swatch) – The new to-swatch in the resulting swatch connection.

  • interval_shift (int, optional) – The amount to shift the interval by when swapping the to_swatch. Negative will shift the interval down. Defaults to 0.

Returns:

A new connection with the same intervals and the from-swatch swapped for the new given swatch.

Return type:

Swatch_Connection

property to_interval: Interval

Returns: Interval: The interval of connection on the to-swatch.

touches(other_connection)
Parameters:

other_connection (Swatch_Connection) – The other swatch connection to compare to.

Returns:

True if the range of needle connections of this connection touches the intervals in the other connection. False otherwise.

Return type:

bool

Notes

  • This method does not test for equality of the swatches in this and the other connection.

update_connection(prior_connection)
Parameters:

prior_connection (Swatch_Connection | None) – The prior connection to consider replacing this connection with.

Returns:

The connection to replace the prior connection given this connection. * If the prior connection is None or does not involve these swatches, this connection is returned unchanged. * If the prior connection subsumes this connection, None is returned and no updated connection is needed. * If the prior connection overlaps this connection, a connection that merges both connection is returned. * Otherwise, the two connections do not touch and this connection is returned unchanged to replace the prior connection.

Return type:

Swatch_Connection | None

from_swatch: Swatch
to_swatch: Swatch
from_begin: int
from_end: int
to_begin: int
to_end: int