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_ConnectionA Class for tracking the needle ranges between two swatches to be merged wale-wise (bottom to top).
- Parameters:
- __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 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_right_needle_position: int
Returns: int: The bottom right needle slot to merge from.
- __contains__(swatch)
- __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:
- __hash__()
- Returns:
Hash of the tuple of the from_swatch, to_swatch, from_interval, and to_interval.
- Return type:
- __post_init__()
Checks that the intervals are correct after the connection has been initialized.
- 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:
- 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:
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:
- 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:
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:
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:
- Returns:
A new connection with the same intervals and the from-swatch swapped for the new given swatch.
- Return type:
- 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:
- swap_to_swatch(new_swatch, interval_shift=0)
- Parameters:
- Returns:
A new connection with the same intervals and the from-swatch swapped for the new given swatch.
- Return type:
- 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:
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