quilt_knit.swatch.course_wise_merging.Course_Wise_Connection module

Module containing the Course Wise Connection class.

class Course_Wise_Connection(left_swatch, right_swatch, first_carriage_pass_on_left=0, last_carriage_pass_on_left=None, first_carriage_pass_on_right=0, last_carriage_pass_on_right=None)[source]

Bases: Swatch_Connection

Class representing the course-wise alignment of two swatches in a quilt.

Parameters:
  • left_swatch (Swatch)

  • right_swatch (Swatch)

  • first_carriage_pass_on_left (int)

  • last_carriage_pass_on_left (Optional[int])

  • first_carriage_pass_on_right (int)

  • last_carriage_pass_on_right (Optional[int])

__init__(left_swatch, right_swatch, first_carriage_pass_on_left=0, last_carriage_pass_on_left=None, first_carriage_pass_on_right=0, last_carriage_pass_on_right=None)[source]
Parameters:
  • left_swatch (Swatch) – The left swatch in the connection.

  • right_swatch (Swatch) – The right swatch in the connection.

  • first_carriage_pass_on_left (int, optional) – The first carriage pass to merge from on the left side. Defaults to 0.

  • last_carriage_pass_on_left (int, optional) – The last carriage pass to merge from on the left side. Defaults to the height of the left swatch.

  • first_carriage_pass_on_right (int, optional) – The first carriage pass to merge from on the right side. Defaults to 0.

  • last_carriage_pass_on_right (int, optional) – The last carriage pass to merge from on the right side. Defaults to the height of the right swatch.

property merge_left_to_end: bool

Returns: bool: True if the connection goes all the way to the end of the left swatch, False otherwise.

property merge_left_from_beginning: bool

Returns: bool: True if the connection starts at the beginning of the left swatch, False otherwise.

property merge_right_to_end: bool

Returns: bool: True if the connection goes all the way to the end of the right swatch, False otherwise.

property merge_right_from_beginning: bool

Returns: bool: True if the connection starts at the beginning of the right swatch, False otherwise.

property left_start_direction: Carriage_Pass_Direction | None

Returns: Carriage_Pass_Direction | None : The direction of the first carriage pass to merge from on the left side, or None if the first carriage pass is a transfer pass.

property right_start_direction: Carriage_Pass_Direction | None

Returns: Carriage_Pass_Direction | None : The direction of the first carriage pass to merge from on the left side, or None if the first carriage pass is a transfer pass.

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_from_swatch_by_carriage_pass_alignment(new_swatch, interval_shift)[source]
Parameters:
  • new_swatch (Swatch) – The new from swatch in the resulting swatch connection. This will be the new left swatch.

  • interval_shift (dict[int, int]) – A dictionary that maps carriage pass indices in the current swatch to new indices in the merged swatch.

Returns:

The connection formed by swapping the left swatch with the given new swatch and adjusting the interval by the given specification.

Return type:

Course_Wise_Connection

swap_to_swatch_by_carriage_pass_alignment(new_swatch, interval_shift)[source]
Parameters:
  • new_swatch (Swatch) – The new to swatch in the resulting swatch connection. This will be the new right swatch.

  • interval_shift (dict[int, int]) – A dictionary that maps carriage pass indices in the current swatch to new indices in the merged swatch.

Returns:

The connection formed by swapping the right swatch with the given new swatch and adjusting the interval by the given specification.

Return type:

Course_Wise_Connection

swap_matching_swatch_by_carriage_pass_alignment(new_swatch, matching_swatch, interval_shift)[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 (dict[int, int]) – A dictionary that maps carriage pass indices in the current swatch to new indices in the merged swatch.

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

property left_swatch: Swatch

Returns: Swatch: The swatch that is merged from course-wise forming the left side of the connection.

property right_swatch: Swatch

Returns: Swatch: The swatch that is merged to course-wise forming the right side of the connection.

property left_bottom_course: int

Returns: int: The bottom carriage pass index of the left swatch.

property left_top_course: int

Returns: int: The top carriage pass index of the left swatch.

property right_bottom_course: int

Returns: int: The bottom carriage pass index of the right swatch.

property right_top_course: int

Returns: int: The top carriage pass index of the right swatch.

__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_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

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