knit-graphs 0.0.6__py3-none-any.whl → 0.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- knit_graphs-0.0.6.dist-info/licenses/LICENSE → LICENSE +21 -21
- README.md +75 -0
- docs/Makefile +20 -0
- docs/make.bat +35 -0
- docs/source/api/knit_graphs.artin_wale_braids.rst +58 -0
- docs/source/api/knit_graphs.rst +74 -0
- docs/source/conf.py +335 -0
- docs/source/index.rst +71 -0
- docs/source/installation.rst +67 -0
- knit_graphs/Course.py +156 -104
- knit_graphs/Knit_Graph.py +249 -186
- knit_graphs/Knit_Graph_Visualizer.py +680 -0
- knit_graphs/Loop.py +141 -155
- knit_graphs/Pull_Direction.py +68 -23
- knit_graphs/Yarn.py +424 -267
- knit_graphs/__init__.py +3 -3
- knit_graphs/_base_classes.py +173 -0
- knit_graphs/artin_wale_braids/Crossing_Direction.py +74 -15
- knit_graphs/artin_wale_braids/Loop_Braid_Graph.py +95 -62
- knit_graphs/artin_wale_braids/Wale.py +169 -93
- knit_graphs/artin_wale_braids/Wale_Braid.py +50 -30
- knit_graphs/artin_wale_braids/Wale_Braid_Word.py +99 -54
- knit_graphs/artin_wale_braids/Wale_Group.py +136 -88
- knit_graphs/{knit_graph_generators/basic_knit_graph_generators.py → basic_knit_graph_generators.py} +302 -248
- knit_graphs-0.0.7.dist-info/LICENSE +21 -0
- {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.7.dist-info}/METADATA +33 -24
- knit_graphs-0.0.7.dist-info/RECORD +29 -0
- {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.7.dist-info}/WHEEL +1 -1
- knit_graphs/__about__.py +0 -4
- knit_graphs/knit_graph_generators/__init__.py +0 -0
- knit_graphs/knit_graph_visualizer/Stitch_Visualizer.py +0 -427
- knit_graphs/knit_graph_visualizer/__init__.py +0 -0
- knit_graphs-0.0.6.dist-info/RECORD +0 -22
knit_graphs/Loop.py
CHANGED
|
@@ -1,155 +1,141 @@
|
|
|
1
|
-
"""Module containing the Loop Class
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
self.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
self.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def next_loop_on_yarn(self):
|
|
108
|
-
"""
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"""
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"""
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
"""
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return
|
|
142
|
-
|
|
143
|
-
def __lt__(self, other):
|
|
144
|
-
assert isinstance(other, Loop)
|
|
145
|
-
return self.loop_id < other.loop_id
|
|
146
|
-
|
|
147
|
-
def __gt__(self, other):
|
|
148
|
-
assert isinstance(other, Loop)
|
|
149
|
-
return self.loop_id > other.loop_id
|
|
150
|
-
|
|
151
|
-
def __str__(self):
|
|
152
|
-
return f"{self.loop_id} on yarn {self.yarn}"
|
|
153
|
-
|
|
154
|
-
def __repr__(self):
|
|
155
|
-
return str(self.loop_id)
|
|
1
|
+
"""Module containing the Loop Class.
|
|
2
|
+
|
|
3
|
+
This module defines the Loop class which represents individual loops in a knitting pattern.
|
|
4
|
+
Loops are the fundamental building blocks of knitted structures and maintain relationships with parent loops, yarn connections, and float positions.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import cast
|
|
9
|
+
|
|
10
|
+
from knit_graphs._base_classes import _Base_Loop, _Base_Yarn
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Loop(_Base_Loop):
|
|
14
|
+
"""A class to represent a single loop structure for modeling a single loop in a knitting pattern.
|
|
15
|
+
|
|
16
|
+
The Loop class manages yarn relationships, parent-child connections for stitches, and float positioning for complex knitting structures.
|
|
17
|
+
Each loop maintains its position in the yarn sequence and its relationships to other loops through stitch connections and floating elements.
|
|
18
|
+
|
|
19
|
+
Attributes:
|
|
20
|
+
yarn (Yarn): The yarn that creates and holds this loop.
|
|
21
|
+
parent_loops (list[Loop]): The list of parent loops that this loop is connected to through stitch edges.
|
|
22
|
+
front_floats (dict[Loop, set[Loop]]): A dictionary tracking loops that this loop floats in front of.
|
|
23
|
+
back_floats (dict[Loop, set[Loop]]): A dictionary tracking loops that this loop floats behind.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, loop_id: int, yarn: _Base_Yarn) -> None:
|
|
27
|
+
"""Construct a Loop object with the specified identifier and yarn.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
loop_id (int): A unique identifier for the loop, must be non-negative.
|
|
31
|
+
yarn (_Base_Yarn): The yarn that creates and holds this loop.
|
|
32
|
+
"""
|
|
33
|
+
super().__init__(loop_id)
|
|
34
|
+
self.yarn: _Base_Yarn = yarn
|
|
35
|
+
self.parent_loops: list[Loop] = []
|
|
36
|
+
self.front_floats: dict[Loop, set[Loop]] = {}
|
|
37
|
+
self.back_floats: dict[Loop, set[Loop]] = {}
|
|
38
|
+
|
|
39
|
+
def add_loop_in_front_of_float(self, u: Loop, v: Loop) -> None:
|
|
40
|
+
"""Set this loop to be in front of the float between loops u and v.
|
|
41
|
+
|
|
42
|
+
This method establishes that this loop passes in front of a floating yarn segment between two other loops.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
u (Loop): The first loop in the float pair.
|
|
46
|
+
v (Loop): The second loop in the float pair.
|
|
47
|
+
"""
|
|
48
|
+
if u not in self.back_floats:
|
|
49
|
+
self.back_floats[u] = set()
|
|
50
|
+
if v not in self.back_floats:
|
|
51
|
+
self.back_floats[v] = set()
|
|
52
|
+
self.back_floats[u].add(v)
|
|
53
|
+
self.back_floats[v].add(u)
|
|
54
|
+
|
|
55
|
+
def add_loop_behind_float(self, u: Loop, v: Loop) -> None:
|
|
56
|
+
"""Set this loop to be behind the float between loops u and v.
|
|
57
|
+
|
|
58
|
+
This method establishes that this loop passes behind a floating yarn segment between two other loops.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
u (Loop): The first loop in the float pair.
|
|
62
|
+
v (Loop): The second loop in the float pair.
|
|
63
|
+
"""
|
|
64
|
+
if u not in self.front_floats:
|
|
65
|
+
self.front_floats[u] = set()
|
|
66
|
+
if v not in self.front_floats:
|
|
67
|
+
self.front_floats[v] = set()
|
|
68
|
+
self.front_floats[u].add(v)
|
|
69
|
+
self.front_floats[v].add(u)
|
|
70
|
+
|
|
71
|
+
def is_in_front_of_float(self, u: Loop, v: Loop) -> bool:
|
|
72
|
+
"""Check if this loop is positioned in front of the float between loops u and v.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
u (Loop): The first loop in the float pair.
|
|
76
|
+
v (Loop): The second loop in the float pair.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
bool: True if the float between u and v passes behind this loop, False otherwise.
|
|
80
|
+
"""
|
|
81
|
+
return u in self.back_floats and v in self.back_floats and v in self.back_floats[u]
|
|
82
|
+
|
|
83
|
+
def is_behind_float(self, u: Loop, v: Loop) -> bool:
|
|
84
|
+
"""Check if this loop is positioned behind the float between loops u and v.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
u (Loop): The first loop in the float pair.
|
|
88
|
+
v (Loop): The second loop in the float pair.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
bool: True if the float between u and v passes in front of this loop, False otherwise.
|
|
92
|
+
"""
|
|
93
|
+
return u in self.front_floats and v in self.front_floats and v in self.front_floats[u]
|
|
94
|
+
|
|
95
|
+
def prior_loop_on_yarn(self) -> Loop | None:
|
|
96
|
+
"""Get the loop that precedes this loop on the same yarn.
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
Loop | None: The prior loop on the yarn, or None if this is the first loop on the yarn.
|
|
100
|
+
"""
|
|
101
|
+
loop = self.yarn.prior_loop(self)
|
|
102
|
+
if loop is None:
|
|
103
|
+
return None
|
|
104
|
+
else:
|
|
105
|
+
return cast(Loop, loop)
|
|
106
|
+
|
|
107
|
+
def next_loop_on_yarn(self) -> Loop:
|
|
108
|
+
"""Get the loop that follows this loop on the same yarn.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
Loop: The next loop on the yarn, or None if this is the last loop on the yarn.
|
|
112
|
+
"""
|
|
113
|
+
return cast(Loop, self.yarn.next_loop(self))
|
|
114
|
+
|
|
115
|
+
def has_parent_loops(self) -> bool:
|
|
116
|
+
"""Check if this loop has any parent loops connected through stitch edges.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
bool: True if the loop has stitch-edge parents, False otherwise.
|
|
120
|
+
"""
|
|
121
|
+
return len(self.parent_loops) > 0
|
|
122
|
+
|
|
123
|
+
def add_parent_loop(self, parent: Loop, stack_position: int | None = None) -> None:
|
|
124
|
+
"""Add a parent loop to this loop's parent stack.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
parent (Loop): The loop to be added as a parent to this loop.
|
|
128
|
+
stack_position (int | None, optional): The position to insert the parent into the parent stack. If None, adds the parent on top of the stack. Defaults to None.
|
|
129
|
+
"""
|
|
130
|
+
if stack_position is not None:
|
|
131
|
+
self.parent_loops.insert(stack_position, parent)
|
|
132
|
+
else:
|
|
133
|
+
self.parent_loops.append(parent)
|
|
134
|
+
|
|
135
|
+
def __str__(self) -> str:
|
|
136
|
+
"""Get a string representation of this loop.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
str: String representation showing the loop ID and associated yarn.
|
|
140
|
+
"""
|
|
141
|
+
return f"{self.loop_id} on yarn {self.yarn}"
|
knit_graphs/Pull_Direction.py
CHANGED
|
@@ -1,23 +1,68 @@
|
|
|
1
|
-
"""Enumerator used to define the two pull-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
"""Enumerator used to define the two pull-directions of a loop through other loops.
|
|
2
|
+
|
|
3
|
+
This module defines the Pull_Direction enumeration which represents the two ways a loop can be pulled through other loops in knitting: from back to front (knit) or from front to back (purl).
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from enum import Enum
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Pull_Direction(Enum):
|
|
11
|
+
"""An enumerator of the two pull-directions of a loop in knitting operations.
|
|
12
|
+
|
|
13
|
+
This enumeration represents the two directions that yarn can be pulled through loops to create different stitch types.
|
|
14
|
+
BtF (Back to Front) creates knit stitches, while FtB (Front to Back) creates purl stitches.
|
|
15
|
+
"""
|
|
16
|
+
BtF = "Knit"
|
|
17
|
+
FtB = "Purl"
|
|
18
|
+
|
|
19
|
+
def opposite(self) -> Pull_Direction:
|
|
20
|
+
"""Get the opposite pull direction of this direction.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
Pull_Direction: The opposite pull direction. If this is BtF, returns FtB. If this is FtB, returns BtF.
|
|
24
|
+
"""
|
|
25
|
+
if self is Pull_Direction.BtF:
|
|
26
|
+
return Pull_Direction.FtB
|
|
27
|
+
else:
|
|
28
|
+
return Pull_Direction.BtF
|
|
29
|
+
|
|
30
|
+
def __neg__(self) -> Pull_Direction:
|
|
31
|
+
"""Get the opposite pull direction using the negation operator.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Pull_Direction: The opposite pull direction, same as calling opposite().
|
|
35
|
+
"""
|
|
36
|
+
return self.opposite()
|
|
37
|
+
|
|
38
|
+
def __invert__(self) -> Pull_Direction:
|
|
39
|
+
"""Get the opposite pull direction using the bitwise inversion operator.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
Pull_Direction: The opposite pull direction, same as calling opposite().
|
|
43
|
+
"""
|
|
44
|
+
return self.opposite()
|
|
45
|
+
|
|
46
|
+
def __str__(self) -> str:
|
|
47
|
+
"""Get the string representation of the pull direction.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
str: The value of the pull direction ("Knit" for BtF, "Purl" for FtB).
|
|
51
|
+
"""
|
|
52
|
+
return str(self.value)
|
|
53
|
+
|
|
54
|
+
def __repr__(self) -> str:
|
|
55
|
+
"""Get the representation string of the pull direction for debugging.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
str: The name of the pull direction ("BtF" or "FtB").
|
|
59
|
+
"""
|
|
60
|
+
return self.name
|
|
61
|
+
|
|
62
|
+
def __hash__(self) -> int:
|
|
63
|
+
"""Get the hash value of the pull direction for use in sets and dictionaries.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
int: Hash value based on the pull direction name.
|
|
67
|
+
"""
|
|
68
|
+
return hash(self.name)
|