knit_graphs.Knit_Graph module
The graph structure used to represent knitted objects.
This module contains the main Knit_Graph class which serves as the central data structure for representing knitted fabrics. It manages the relationships between loops, yarns, and structural elements like courses and wales.
- class Knit_Graph[source]
Bases:
object
A representation of knitted structures as connections between loops on yarns.
The Knit_Graph class is the main data structure for representing knitted fabrics. It maintains a directed graph of loops connected by stitch edges, manages yarn relationships, and provides methods for analyzing the structure of the knitted fabric including courses, wales, and cable crossings.
- property last_loop: None | Loop
Get the most recently added loop in the graph.
- Returns:
The last loop added to the graph, or None if no loops have been added.
- Return type:
None | Loop
- property has_loop: bool
Check if the graph contains any loops.
- Returns:
True if the graph has at least one loop, False otherwise.
- Return type:
- add_crossing(left_loop, right_loop, crossing_direction)[source]
Add a cable crossing between two loops with the specified crossing direction.
- Parameters:
left_loop (Loop) – The loop on the left side of the crossing.
right_loop (Loop) – The loop on the right side of the crossing.
crossing_direction (Crossing_Direction) – The direction of the crossing (over, under, or none) between the loops.
- Return type:
- connect_loops(parent_loop, child_loop, pull_direction=BtF, stack_position=None)[source]
Create a stitch edge by connecting a parent and child loop.
- Parameters:
parent_loop (Loop) – The parent loop to connect to the child loop.
child_loop (Loop) – The child loop to connect to the parent loop.
pull_direction (Pull_Direction) – The direction the child is pulled through the parent. Defaults to Pull_Direction.BtF (knit stitch).
stack_position (int | None, optional) – The position to insert the parent into the child’s parent stack. If None, adds on top of the stack. Defaults to None.
- Raises:
KeyError – If either the parent_loop or child_loop is not already in the knit graph.
- Return type:
- get_wale_starting_with_loop(first_loop)[source]
Get a wale (vertical column of stitches) starting from the specified loop.
- get_wales_ending_with_loop(last_loop)[source]
Get all wales (vertical columns of stitches) that end at the specified loop.
- get_wale_groups()[source]
Get wale groups organized by their terminal loops.
- Returns:
Dictionary mapping terminal loops to the wale groups they terminate. Each wale group represents a collection of wales that end at the same terminal loop.
- Return type:
- __iter__()[source]
- Returns:
An iterator over all loops in the knit graph.
- Return type:
Iterator[Loop]
- get_pull_direction(parent, child)[source]
Get the pull direction of the stitch edge between parent and child loops.
- Parameters:
- Returns:
The pull direction of the stitch-edge between the parent and child, or None if there is no edge between these loops.
- Return type:
Pull_Direction | None