knit_graphs.Loop module
Module containing the Loop Class.
This module defines the Loop class which represents individual loops in a knitting pattern. Loops are the fundamental building blocks of knitted structures and maintain relationships with parent loops, yarn connections, and float positions.
- class Loop(yarn: Yarn[Self], loop_id: int | None = None, **_kwargs: Any)[source]
Bases:
objectA class to represent a single loop structure for modeling a single loop in a knitting pattern.
The Loop class manages yarn relationships, parent-child connections for stitches, and float positioning for complex knitting structures. Each loop maintains its position in the yarn sequence and its relationships to other loops through stitch connections and floating elements.
- parent_loops
The list of parent loops that this loop is connected to through stitch edges.
- __init__(yarn: Yarn[Self], loop_id: int | None = None, **_kwargs: Any) None[source]
Construct a Loop object with the specified identifier and yarn.
- property loop_id: int
Get the unique identifier of this loop.
- Returns:
The id of the loop.
- Return type:
- property has_parent_loops: bool
Check if this loop has any parent loops connected through stitch edges.
- Returns:
True if the loop has stitch-edge parents, False otherwise.
- Return type:
- property parent_loop_ids: list[int]
Returns: list[int]: The ids of the parent loops of this loop in their stacking order.
- property pull_directions: list[Pull_Direction]
Returns: list[Pull_Direction]: The pull direction of the stitches formed by this loop and its parents in stacking order of its parents.
- property pull_direction: Pull_Direction
Returns: Pull_Direction: The majority pull-direction of the stitches formed with the parent loops or Back-To-Front (knit-stitch) if this loop has no parents.
- property prior_loop_on_yarn: Self | None
Returns: Loop | None: The prior loop on the yarn, or None if this is the first loop on the yarn.
- property next_loop_on_yarn: Self | None
Returns: Loop | None: The next loop on the yarn, or None if this is the last loop on the yarn.
- property started_float: Float_Edge[Self] | None
Returns: Float_Edge | None: The float-edge connecting this loop to the next loop on its yarn or None if it is at the end of the yarn.
- property ended_float: Float_Edge[Self] | None
Returns: Float_Edge | None: The float-edge connecting the prior loop on the yarn to this loop or None if it is at the beginning of the yarn.
- property loops_in_front_of_floats: set[Self]
Returns: set[Self]: The set of all loops in front of a float that involves this loop.
- property loops_behind_floats: set[Self]
Returns: set[Self]: The set of all loops behind a float that involves this loop.
- property cross_floats: set[Self]
Returns: set[Self]: The set of all loops that cross a float that involves this loop.
- static majority_pull_direction(loops: Sequence[Loop]) Pull_Direction[source]
- Parameters:
loops (Sequence[Loop]) – The loops to find the majority pull direction of.
- Returns:
The majority pull direction of the given loops or Back-to-Front (i.e., knit-stitch) there are no loops.
- Return type:
- add_loop_behind_started_float(back_loop: Self) None[source]
Places the given loop behind the float started by this loop. If this loop is at the end of the yarn, nothing happens.
- Parameters:
back_loop (Loop) – The loop to place the loop behind the float started by this loop.
- add_loop_in_front_of_started_float(front_loop: Self) None[source]
Places the given loop in front of the float started by this loop. If this loop is at the end of the yarn, nothing happens. :param front_loop: The loop to place the loop in front of the float started by this loop. :type front_loop: Loop
- add_parent_loop(parent: Self, stack_position: int | None = None) None[source]
Add a parent loop to this loop’s parent stack.
- remove_parent(parent: Self) None[source]
Removes the given parent loop from the set of parents of this loop. If the given loop is not a parent of this loop, nothing happens. :param parent: The parent loop to remove. :type parent: Loop
- __hash__() int[source]
Return hash value based on loop_id for use in sets and dictionaries.
- Returns:
Hash value of the loop_id.
- Return type:
- __int__() int[source]
Convert loop to integer representation using loop_id.
- Returns:
The loop_id as an integer.
- Return type:
- __eq__(other: object) bool[source]
Check equality with another base loop based on loop_id and type.
- Parameters:
other (Self) – The other loop to compare with.
- Returns:
True if both loops have the same class and loop_id, False otherwise.
- Return type: