knit-graphs 0.0.6__py3-none-any.whl → 0.0.8__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.Course.rst +7 -0
- docs/source/api/knit_graphs.Knit_Graph.rst +7 -0
- docs/source/api/knit_graphs.Knit_Graph_Visualizer.rst +7 -0
- docs/source/api/knit_graphs.Loop.rst +7 -0
- docs/source/api/knit_graphs.Pull_Direction.rst +7 -0
- docs/source/api/knit_graphs.Yarn.rst +7 -0
- docs/source/api/knit_graphs.artin_wale_braids.Crossing_Direction.rst +7 -0
- docs/source/api/knit_graphs.artin_wale_braids.Loop_Braid_Graph.rst +7 -0
- docs/source/api/knit_graphs.artin_wale_braids.Wale.rst +7 -0
- docs/source/api/knit_graphs.artin_wale_braids.Wale_Braid.rst +7 -0
- docs/source/api/knit_graphs.artin_wale_braids.Wale_Braid_Word.rst +7 -0
- docs/source/api/knit_graphs.artin_wale_braids.Wale_Group.rst +7 -0
- docs/source/api/knit_graphs.artin_wale_braids.rst +23 -0
- docs/source/api/knit_graphs.basic_knit_graph_generators.rst +7 -0
- docs/source/api/knit_graphs.rst +32 -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 +675 -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/basic_knit_graph_generators.py +251 -0
- knit_graphs-0.0.8.dist-info/LICENSE +21 -0
- {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.8.dist-info}/METADATA +33 -24
- knit_graphs-0.0.8.dist-info/RECORD +42 -0
- {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.8.dist-info}/WHEEL +1 -1
- knit_graphs/__about__.py +0 -4
- knit_graphs/knit_graph_generators/__init__.py +0 -0
- knit_graphs/knit_graph_generators/basic_knit_graph_generators.py +0 -248
- 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/Course.py
CHANGED
|
@@ -1,104 +1,156 @@
|
|
|
1
|
-
"""Course representation of a section of knitting with no parent loops.
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"""
|
|
69
|
-
|
|
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
|
-
|
|
1
|
+
"""Course representation of a section of knitting with no parent loops.
|
|
2
|
+
|
|
3
|
+
This module contains the Course class which represents a horizontal row of loops in a knitting pattern.
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import Iterator, cast
|
|
8
|
+
|
|
9
|
+
from knit_graphs._base_classes import _Base_Knit_Graph
|
|
10
|
+
from knit_graphs.Loop import Loop
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Course:
|
|
14
|
+
"""Course object for organizing loops into knitting rows.
|
|
15
|
+
|
|
16
|
+
A Course represents a horizontal row of loops in a knitting pattern.
|
|
17
|
+
It maintains an ordered list of loops and provides methods for analyzing the structure and relationships between courses in the knitted fabric.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, _knit_graph: _Base_Knit_Graph) -> None:
|
|
21
|
+
"""Initialize an empty course associated with a knit graph.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
_knit_graph (Knit_Graph): The knit graph that this course belongs to.
|
|
25
|
+
"""
|
|
26
|
+
self.loops_in_order: list[Loop] = []
|
|
27
|
+
self._loop_set: set[Loop] = set()
|
|
28
|
+
|
|
29
|
+
def add_loop(self, loop: Loop, index: int | None = None) -> None:
|
|
30
|
+
"""Add a loop to the course at the specified index or at the end.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
loop (Loop): The loop to add to this course.
|
|
34
|
+
index (int | None, optional): The index position to insert the loop at. If None, appends to the end.
|
|
35
|
+
"""
|
|
36
|
+
for parent_loop in loop.parent_loops:
|
|
37
|
+
assert parent_loop not in self, f"{loop} has parent {parent_loop}, cannot be added to same course"
|
|
38
|
+
self._loop_set.add(loop)
|
|
39
|
+
if index is None:
|
|
40
|
+
self.loops_in_order.append(loop)
|
|
41
|
+
else:
|
|
42
|
+
self.loops_in_order.insert(index, loop)
|
|
43
|
+
|
|
44
|
+
def has_increase(self) -> bool:
|
|
45
|
+
"""Check if this course contains any yarn overs that start new wales.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
bool: True if the course has at least one yarn over (loop with no parent loops) to start new wales.
|
|
49
|
+
"""
|
|
50
|
+
return any(not loop.has_parent_loops() for loop in self)
|
|
51
|
+
|
|
52
|
+
def has_decrease(self) -> bool:
|
|
53
|
+
"""Check if this course contains any decrease stitches that merge wales.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
bool: True if the course has at least one decrease stitch (loop with multiple parent loops) merging two or more wales.
|
|
57
|
+
"""
|
|
58
|
+
return any(len(loop.parent_loops) > 1 for loop in self)
|
|
59
|
+
|
|
60
|
+
def __getitem__(self, index: int | slice) -> Loop | list[Loop]:
|
|
61
|
+
"""Get loop(s) at the specified index or slice.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
index (int | slice): The index or slice to retrieve from the course.
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
Loop | list[Loop]: The loop at the specified index, or list of loops for a slice.
|
|
68
|
+
"""
|
|
69
|
+
return self.loops_in_order[index]
|
|
70
|
+
|
|
71
|
+
def in_round_with(self, next_course: Course) -> bool:
|
|
72
|
+
"""Check if the next course connects to this course in a circular pattern.
|
|
73
|
+
|
|
74
|
+
This method determines if the courses are connected in the round (circular knitting) by checking if the next course starts at the beginning of this course.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
next_course (Course): The course that should follow this course in circular knitting.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
bool: True if the next course starts at the beginning of this course, indicating circular knitting.
|
|
81
|
+
"""
|
|
82
|
+
next_start: Loop = cast(Loop, next_course[0])
|
|
83
|
+
i = 1
|
|
84
|
+
while not next_start.has_parent_loops():
|
|
85
|
+
next_start = cast(Loop, next_course[i])
|
|
86
|
+
i += 1
|
|
87
|
+
return self[0] in next_start.parent_loops
|
|
88
|
+
|
|
89
|
+
def in_row_with(self, next_course: Course) -> bool:
|
|
90
|
+
"""Check if the next course connects to this course in a flat/row pattern.
|
|
91
|
+
|
|
92
|
+
This method determines if the courses are connected in flat knitting (back and forth) by checking if the next course starts at the end of this course.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
next_course (Course): The course that should follow this course in flat knitting.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
bool: True if the next course starts at the end of this course, indicating flat/row knitting.
|
|
99
|
+
"""
|
|
100
|
+
next_start: Loop = cast(Loop, next_course[0])
|
|
101
|
+
i = 1
|
|
102
|
+
while not next_start.has_parent_loops():
|
|
103
|
+
next_start = cast(Loop, next_course[i])
|
|
104
|
+
i += 1
|
|
105
|
+
return self[-1] in next_start.parent_loops
|
|
106
|
+
|
|
107
|
+
def __contains__(self, loop: Loop) -> bool:
|
|
108
|
+
"""Check if a loop is contained in this course.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
loop (Loop): The loop to check for membership in this course.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
bool: True if the loop is in this course, False otherwise.
|
|
115
|
+
"""
|
|
116
|
+
return loop in self._loop_set
|
|
117
|
+
|
|
118
|
+
def __iter__(self) -> Iterator[Loop]:
|
|
119
|
+
"""Iterate over loops in this course in order.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
Iterator[Loop]: An iterator over the loops in this course in their natural order.
|
|
123
|
+
"""
|
|
124
|
+
return iter(self.loops_in_order)
|
|
125
|
+
|
|
126
|
+
def __reversed__(self) -> Iterator[Loop]:
|
|
127
|
+
"""Iterate over loops in this course in reverse order.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
Iterator[Loop]: An iterator over the loops in this course in reverse order.
|
|
131
|
+
"""
|
|
132
|
+
return reversed(self.loops_in_order)
|
|
133
|
+
|
|
134
|
+
def __len__(self) -> int:
|
|
135
|
+
"""Get the number of loops in this course.
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
int: The total number of loops in this course.
|
|
139
|
+
"""
|
|
140
|
+
return len(self.loops_in_order)
|
|
141
|
+
|
|
142
|
+
def __str__(self) -> str:
|
|
143
|
+
"""Get string representation of this course.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
str: String representation showing the ordered list of loops.
|
|
147
|
+
"""
|
|
148
|
+
return str(self.loops_in_order)
|
|
149
|
+
|
|
150
|
+
def __repr__(self) -> str:
|
|
151
|
+
"""Get string representation of this course for debugging.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
str: String representation showing the ordered list of loops.
|
|
155
|
+
"""
|
|
156
|
+
return str(self)
|