quilt_knit.quilt.Quilt module
The module containing the Quilt class.
- exception Blocked_Swatch_Connection_Exception(connection, blocking_connections)[source]
Bases:
ExceptionAn Exception raised when attempting to add a blocked connection to a quilt.
- connection
The blocked connection.
- Type:
- blocking_connections
The connections in the quilt that blocked the new connection.
- Type:
- Parameters:
connection (
Swatch_Connection)blocking_connections (
set[Swatch_Connection])
- __init__(connection, blocking_connections)[source]
- Parameters:
connection (Swatch_Connection) – The blocked connection.
blocking_connections (set[Swatch_Connection]) – The connections in the quilt that blocked the new connection.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception Unconnected_Swatches_Exception(a_swatch, b_swatch)[source]
Bases:
ExceptionAn Exception raised when attempting to merge two unconnected swatches in a quilt.
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class Quilt[source]
Bases:
objectA data structure of a dynamic grid of connected swatches which can be merged to form a unified swatch.
- course_wise_connections
A directed graph of the course wise connections between swatches in the quilt.
- Type:
DiGraph
- wale_wise_connections
A directed graph of the wale wise connections between swatches in the quilt.
- Type:
DiGraph
- swatch_neighborhoods
A dictionary of swatches keyed to their neighborhoods.
- Type:
- swatches_to_rightward_shifts
A dictionary of swatches keyed to the number of needles to shift them by rightward when merging the quilt.
- connect_swatches_wale_wise(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]
Forms a wale-wise connection with the given specification and adds it to the Quilt.
- 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.
- Returns:
The connection formed and added to the quilt.
- Return type:
- Raises:
Blocked_Swatch_Connection_Exception – If the new connection is blocked by existing connections in the quilt.
- connect_swatches_course_wise(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]
Forms a course-wise connection with the given specification and adds it to the Quilt. :type left_swatch:
Swatch:param left_swatch: The left swatch in the connection. :type left_swatch: Swatch :type right_swatch:Swatch:param right_swatch: The right swatch in the connection. :type right_swatch: Swatch :type first_carriage_pass_on_left:int:param first_carriage_pass_on_left: The first carriage pass to merge from on the left side. Defaults to 0. :type first_carriage_pass_on_left: int, optional :type last_carriage_pass_on_left:Optional[int] :param last_carriage_pass_on_left: The last carriage pass to merge from on the left side. Defaults to the height of the left swatch. :type last_carriage_pass_on_left: int, optional :type first_carriage_pass_on_right:int:param first_carriage_pass_on_right: The first carriage pass to merge from on the right side. Defaults to 0. :type first_carriage_pass_on_right: int, optional :type last_carriage_pass_on_right:Optional[int] :param last_carriage_pass_on_right: The last carriage pass to merge from on the right side. Defaults to the height of the right swatch. :type last_carriage_pass_on_right: int, optional- Returns:
The connection formed and added to the quilt.
- Return type:
- Raises:
Blocked_Swatch_Connection_Exception – If the new connection is blocked by existing connections in the quilt.
- __contains__(item)[source]
- Parameters:
item (None | Swatch | tuple[Swatch, Swatch] | Swatch_Neighborhood | Swatch_Connection) – The item to search for in the swatch.
- Returns:
True if the item is in the quilt. False otherwise. * A None item returns False. * If given a swatch, returns True if the swatch is in the quilt. * If given a tuple of two swatches, returns True if there is a wale-wise or course-wise connection between these swatches in the quilt. * If given a swatch neighborhood, returns True if the swatch of that neighborhood is in the quilt. * If given a swatch connections, returns True if the connections is in the quilt.
- Return type:
- get_connection(a_swatch, b_swatch, force_direction=True)[source]
- Parameters:
- Returns:
The connection in the quilt between the given swatches or None if no connection exists.
- Return type:
Swatch_Connection | None
- get_course_wise_connection(a_swatch, b_swatch, force_direction=True)[source]
- Parameters:
- Returns:
The course wise connection in the quilt between the given swatches or None if no connection exists.
- Return type:
Course_Wise_Connection | None
- get_wale_wise_connection(a_swatch, b_swatch, force_direction=True)[source]
- Parameters:
- Returns:
The wale-wise connection in the quilt between the given swatches or None if no connection exists.
- Return type:
Wale_Wise_Connection | None
- add_swatch(swatch)[source]
Adds the given swatch to the quilt with no connections to other swatches.
- merge_swatches_course_wise(left_swatch, right_swatch, discard_unconnected_lower_courses=False, discard_unconnected_upper_courses=False)[source]
Merges the given swatches based on their connection in the quilt. The merged swatch is re-attached to the quilt in their place.
- Parameters:
left_swatch (Swatch) – The left swatch to merge.
right_swatch (Swatch) – The right swatch to merge.
discard_unconnected_lower_courses (bool, optional) – If True, The lower courses of the swatch that have no connections in the quilt will be discarded. Defaults to False.
discard_unconnected_upper_courses (bool, optional) – If True, The upper courses of the swatch that have no connections in the quilt will be discarded. Defaults to False.
- Returns:
A tuple containing: * The swatch resulting from the merge. * The set of swatches created by slicing off the lower portions of the merging swatches. These remain in the quilt. * The set of swatches created by slicing off the upper portions of the merging swatches. These remain in the quilt.
- Return type:
- Raises:
Unconnected_Swatches_Exception – If the given swatches are not connected in the quilt.
- convert_quilt_to_course_bands()[source]
Merge all the swatches in course-wise bands of the quilt until there are no more course wise connections to merge.