quilt_knit.swatch.Swatch_Connection module

The module containing the Swatch_Connection class.

class Swatch_Connection(from_swatch, to_swatch, from_begin, from_end, to_begin, to_end, connection_symbol='->')[source]

Bases: object

A class used as a super class to wale-wise and course-wise swatch connections for merging.

Parameters:
__post_init__()[source]

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

Raises:

TypeError – If the intervals are incorrect.

Return type:

None

__init__(from_swatch, to_swatch, from_begin, from_end, to_begin, to_end, connection_symbol='->')[source]
Parameters:
to_end: int
to_begin: int
from_end: int
from_begin: int
from_swatch: Swatch
to_swatch: Swatch
__hash__()[source]
Returns:

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

Return type:

int

connects_same_swatches(other_connection)[source]
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

__contains__(swatch)[source]
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)[source]
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

__repr__()[source]
Returns:

The string representation of this connection.

Return type:

str

__str__()[source]
Returns:

The string representation of this connection.

Return type:

str

property from_interval: Interval

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

property to_interval: Interval

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

range_matches(other_connection)[source]
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.

envelops(other_connection)[source]
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.

overlaps(other_connection)[source]
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.

touches(other_connection)[source]
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.

merged_connection(other_connection)[source]
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.

swap_from_swatch(new_swatch, interval_shift=0)[source]
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_to_swatch(new_swatch, interval_shift=0)[source]
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

swap_matching_swatch(new_swatch, matching_swatch, interval_shift=0)[source]
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

update_connection(prior_connection)[source]
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