knit-graphs 0.0.7__py3-none-any.whl → 0.0.9__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.
Files changed (29) hide show
  1. docs/source/api/knit_graphs.Course.rst +7 -0
  2. docs/source/api/knit_graphs.Knit_Graph.rst +7 -0
  3. docs/source/api/knit_graphs.Knit_Graph_Visualizer.rst +7 -0
  4. docs/source/api/knit_graphs.Loop.rst +7 -0
  5. docs/source/api/knit_graphs.Pull_Direction.rst +7 -0
  6. docs/source/api/knit_graphs.Yarn.rst +7 -0
  7. docs/source/api/knit_graphs.artin_wale_braids.Crossing_Direction.rst +7 -0
  8. docs/source/api/knit_graphs.artin_wale_braids.Loop_Braid_Graph.rst +7 -0
  9. docs/source/api/knit_graphs.artin_wale_braids.Wale.rst +7 -0
  10. docs/source/api/knit_graphs.artin_wale_braids.Wale_Braid.rst +7 -0
  11. docs/source/api/knit_graphs.artin_wale_braids.Wale_Braid_Word.rst +7 -0
  12. docs/source/api/knit_graphs.artin_wale_braids.Wale_Group.rst +7 -0
  13. docs/source/api/knit_graphs.artin_wale_braids.rst +11 -46
  14. docs/source/api/knit_graphs.basic_knit_graph_generators.rst +7 -0
  15. docs/source/api/knit_graphs.rst +12 -54
  16. knit_graphs/Course.py +24 -5
  17. knit_graphs/Knit_Graph.py +37 -14
  18. knit_graphs/Knit_Graph_Visualizer.py +188 -193
  19. knit_graphs/Loop.py +62 -12
  20. knit_graphs/Yarn.py +12 -9
  21. knit_graphs/artin_wale_braids/Wale.py +3 -4
  22. knit_graphs/artin_wale_braids/Wale_Group.py +7 -5
  23. knit_graphs/basic_knit_graph_generators.py +24 -75
  24. {knit_graphs-0.0.7.dist-info → knit_graphs-0.0.9.dist-info}/METADATA +5 -5
  25. knit_graphs-0.0.9.dist-info/RECORD +41 -0
  26. knit_graphs/_base_classes.py +0 -173
  27. knit_graphs-0.0.7.dist-info/RECORD +0 -29
  28. {knit_graphs-0.0.7.dist-info → knit_graphs-0.0.9.dist-info}/LICENSE +0 -0
  29. {knit_graphs-0.0.7.dist-info → knit_graphs-0.0.9.dist-info}/WHEEL +0 -0
@@ -0,0 +1,7 @@
1
+ knit\_graphs.Course module
2
+ ==========================
3
+
4
+ .. automodule:: knit_graphs.Course
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.Knit\_Graph module
2
+ ===============================
3
+
4
+ .. automodule:: knit_graphs.Knit_Graph
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.Knit\_Graph\_Visualizer module
2
+ ===========================================
3
+
4
+ .. automodule:: knit_graphs.Knit_Graph_Visualizer
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.Loop module
2
+ ========================
3
+
4
+ .. automodule:: knit_graphs.Loop
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.Pull\_Direction module
2
+ ===================================
3
+
4
+ .. automodule:: knit_graphs.Pull_Direction
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.Yarn module
2
+ ========================
3
+
4
+ .. automodule:: knit_graphs.Yarn
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.artin\_wale\_braids.Crossing\_Direction module
2
+ ===========================================================
3
+
4
+ .. automodule:: knit_graphs.artin_wale_braids.Crossing_Direction
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.artin\_wale\_braids.Loop\_Braid\_Graph module
2
+ ==========================================================
3
+
4
+ .. automodule:: knit_graphs.artin_wale_braids.Loop_Braid_Graph
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.artin\_wale\_braids.Wale module
2
+ ============================================
3
+
4
+ .. automodule:: knit_graphs.artin_wale_braids.Wale
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.artin\_wale\_braids.Wale\_Braid module
2
+ ===================================================
3
+
4
+ .. automodule:: knit_graphs.artin_wale_braids.Wale_Braid
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.artin\_wale\_braids.Wale\_Braid\_Word module
2
+ =========================================================
3
+
4
+ .. automodule:: knit_graphs.artin_wale_braids.Wale_Braid_Word
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.artin\_wale\_braids.Wale\_Group module
2
+ ===================================================
3
+
4
+ .. automodule:: knit_graphs.artin_wale_braids.Wale_Group
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -1,58 +1,23 @@
1
1
  knit\_graphs.artin\_wale\_braids package
2
2
  ========================================
3
3
 
4
- .. automodule:: knit_graphs.artin_wale_braids
5
- :members:
6
- :undoc-members:
7
- :show-inheritance:
8
-
9
4
  Submodules
10
5
  ----------
11
6
 
12
- knit\_graphs.artin\_wale\_braids.Crossing\_Direction module
13
- -----------------------------------------------------------
7
+ .. toctree::
8
+ :maxdepth: 4
14
9
 
15
- .. automodule:: knit_graphs.artin_wale_braids.Crossing_Direction
16
- :members:
17
- :undoc-members:
18
- :show-inheritance:
10
+ knit_graphs.artin_wale_braids.Crossing_Direction
11
+ knit_graphs.artin_wale_braids.Loop_Braid_Graph
12
+ knit_graphs.artin_wale_braids.Wale
13
+ knit_graphs.artin_wale_braids.Wale_Braid
14
+ knit_graphs.artin_wale_braids.Wale_Braid_Word
15
+ knit_graphs.artin_wale_braids.Wale_Group
19
16
 
20
- knit\_graphs.artin\_wale\_braids.Loop\_Braid\_Graph module
21
- ----------------------------------------------------------
17
+ Module contents
18
+ ---------------
22
19
 
23
- .. automodule:: knit_graphs.artin_wale_braids.Loop_Braid_Graph
24
- :members:
25
- :undoc-members:
26
- :show-inheritance:
27
-
28
- knit\_graphs.artin\_wale\_braids.Wale module
29
- --------------------------------------------
30
-
31
- .. automodule:: knit_graphs.artin_wale_braids.Wale
32
- :members:
33
- :undoc-members:
34
- :show-inheritance:
35
-
36
- knit\_graphs.artin\_wale\_braids.Wale\_Braid module
37
- ---------------------------------------------------
38
-
39
- .. automodule:: knit_graphs.artin_wale_braids.Wale_Braid
40
- :members:
41
- :undoc-members:
42
- :show-inheritance:
43
-
44
- knit\_graphs.artin\_wale\_braids.Wale\_Braid\_Word module
45
- ---------------------------------------------------------
46
-
47
- .. automodule:: knit_graphs.artin_wale_braids.Wale_Braid_Word
48
- :members:
49
- :undoc-members:
50
- :show-inheritance:
51
-
52
- knit\_graphs.artin\_wale\_braids.Wale\_Group module
53
- ---------------------------------------------------
54
-
55
- .. automodule:: knit_graphs.artin_wale_braids.Wale_Group
20
+ .. automodule:: knit_graphs.artin_wale_braids
56
21
  :members:
57
22
  :undoc-members:
58
23
  :show-inheritance:
@@ -0,0 +1,7 @@
1
+ knit\_graphs.basic\_knit\_graph\_generators module
2
+ ==================================================
3
+
4
+ .. automodule:: knit_graphs.basic_knit_graph_generators
5
+ :members:
6
+ :undoc-members:
7
+ :show-inheritance:
@@ -1,11 +1,6 @@
1
1
  knit\_graphs package
2
2
  ====================
3
3
 
4
- .. automodule:: knit_graphs
5
- :members:
6
- :undoc-members:
7
- :show-inheritance:
8
-
9
4
  Subpackages
10
5
  -----------
11
6
 
@@ -17,58 +12,21 @@ Subpackages
17
12
  Submodules
18
13
  ----------
19
14
 
20
- knit\_graphs.Course module
21
- --------------------------
22
-
23
- .. automodule:: knit_graphs.Course
24
- :members:
25
- :undoc-members:
26
- :show-inheritance:
27
-
28
- knit\_graphs.Knit\_Graph module
29
- -------------------------------
30
-
31
- .. automodule:: knit_graphs.Knit_Graph
32
- :members:
33
- :undoc-members:
34
- :show-inheritance:
35
-
36
- knit\_graphs.Knit\_Graph\_Visualizer module
37
- -------------------------------------------
38
-
39
- .. automodule:: knit_graphs.Knit_Graph_Visualizer
40
- :members:
41
- :undoc-members:
42
- :show-inheritance:
43
-
44
- knit\_graphs.Loop module
45
- ------------------------
46
-
47
- .. automodule:: knit_graphs.Loop
48
- :members:
49
- :undoc-members:
50
- :show-inheritance:
51
-
52
- knit\_graphs.Pull\_Direction module
53
- -----------------------------------
54
-
55
- .. automodule:: knit_graphs.Pull_Direction
56
- :members:
57
- :undoc-members:
58
- :show-inheritance:
59
-
60
- knit\_graphs.Yarn module
61
- ------------------------
15
+ .. toctree::
16
+ :maxdepth: 4
62
17
 
63
- .. automodule:: knit_graphs.Yarn
64
- :members:
65
- :undoc-members:
66
- :show-inheritance:
18
+ knit_graphs.Course
19
+ knit_graphs.Knit_Graph
20
+ knit_graphs.Knit_Graph_Visualizer
21
+ knit_graphs.Loop
22
+ knit_graphs.Pull_Direction
23
+ knit_graphs.Yarn
24
+ knit_graphs.basic_knit_graph_generators
67
25
 
68
- knit\_graphs.basic\_knit\_graph\_generators module
69
- --------------------------------------------------
26
+ Module contents
27
+ ---------------
70
28
 
71
- .. automodule:: knit_graphs.basic_knit_graph_generators
29
+ .. automodule:: knit_graphs
72
30
  :members:
73
31
  :undoc-members:
74
32
  :show-inheritance:
knit_graphs/Course.py CHANGED
@@ -4,11 +4,13 @@ This module contains the Course class which represents a horizontal row of loops
4
4
  """
5
5
  from __future__ import annotations
6
6
 
7
- from typing import Iterator, cast
7
+ from typing import TYPE_CHECKING, Iterator, cast
8
8
 
9
- from knit_graphs._base_classes import _Base_Knit_Graph
10
9
  from knit_graphs.Loop import Loop
11
10
 
11
+ if TYPE_CHECKING:
12
+ from knit_graphs.Knit_Graph import Knit_Graph
13
+
12
14
 
13
15
  class Course:
14
16
  """Course object for organizing loops into knitting rows.
@@ -17,15 +19,32 @@ class Course:
17
19
  It maintains an ordered list of loops and provides methods for analyzing the structure and relationships between courses in the knitted fabric.
18
20
  """
19
21
 
20
- def __init__(self, _knit_graph: _Base_Knit_Graph) -> None:
22
+ def __init__(self, knit_graph: Knit_Graph) -> None:
21
23
  """Initialize an empty course associated with a knit graph.
22
24
 
23
25
  Args:
24
- _knit_graph (Knit_Graph): The knit graph that this course belongs to.
26
+ knit_graph (Knit_Graph): The knit graph that this course belongs to.
25
27
  """
26
- self.loops_in_order: list[Loop] = []
28
+ self._knit_graph: Knit_Graph = knit_graph
29
+ self._loops_in_order: list[Loop] = []
27
30
  self._loop_set: set[Loop] = set()
28
31
 
32
+ @property
33
+ def loops_in_order(self) -> list[Loop]:
34
+ """
35
+ Returns:
36
+ list[Loop]: The list of loops in this course.
37
+ """
38
+ return self._loops_in_order
39
+
40
+ @property
41
+ def knit_graph(self) -> Knit_Graph:
42
+ """
43
+ Returns:
44
+ Knit_Graph: The knit graph that this course belongs to.
45
+ """
46
+ return self._knit_graph
47
+
29
48
  def add_loop(self, loop: Loop, index: int | None = None) -> None:
30
49
  """Add a loop to the course at the specified index or at the end.
31
50
 
knit_graphs/Knit_Graph.py CHANGED
@@ -5,9 +5,10 @@ It manages the relationships between loops, yarns, and structural elements like
5
5
  """
6
6
  from __future__ import annotations
7
7
 
8
- from typing import Any, cast
8
+ from typing import Any, Iterator, cast
9
+
10
+ from networkx import DiGraph
9
11
 
10
- from knit_graphs._base_classes import _Base_Knit_Graph
11
12
  from knit_graphs.artin_wale_braids.Crossing_Direction import Crossing_Direction
12
13
  from knit_graphs.artin_wale_braids.Loop_Braid_Graph import Loop_Braid_Graph
13
14
  from knit_graphs.artin_wale_braids.Wale import Wale
@@ -17,8 +18,11 @@ from knit_graphs.Loop import Loop
17
18
  from knit_graphs.Pull_Direction import Pull_Direction
18
19
  from knit_graphs.Yarn import Yarn
19
20
 
21
+ # from knit_graphs.artin_wale_braids.Wale import Wale
22
+ # from knit_graphs.artin_wale_braids.Wale_Group import Wale_Group
23
+
20
24
 
21
- class Knit_Graph(_Base_Knit_Graph):
25
+ class Knit_Graph:
22
26
  """A representation of knitted structures as connections between loops on yarns.
23
27
 
24
28
  The Knit_Graph class is the main data structure for representing knitted fabrics.
@@ -28,7 +32,7 @@ class Knit_Graph(_Base_Knit_Graph):
28
32
 
29
33
  def __init__(self) -> None:
30
34
  """Initialize an empty knit graph with no loops or yarns."""
31
- super().__init__()
35
+ self.stitch_graph: DiGraph = DiGraph()
32
36
  self.braid_graph: Loop_Braid_Graph = Loop_Braid_Graph()
33
37
  self._last_loop: None | Loop = None
34
38
  self.yarns: set[Yarn] = set()
@@ -69,7 +73,7 @@ class Knit_Graph(_Base_Knit_Graph):
69
73
  """
70
74
  self.stitch_graph.add_node(loop)
71
75
  if loop.yarn not in self.yarns:
72
- self.add_yarn(cast(Yarn, loop.yarn))
76
+ self.add_yarn(loop.yarn)
73
77
  if self._last_loop is None or loop > self._last_loop:
74
78
  self._last_loop = loop
75
79
 
@@ -129,12 +133,14 @@ class Knit_Graph(_Base_Knit_Graph):
129
133
  list[Wale]: The set of wales that end at this loop. Only returns multiple wales if this loop is a child of a decrease stitch.
130
134
  """
131
135
  wales = []
132
- for top_stitch_parent in self.stitch_graph.predecessors(last_loop):
136
+ if len(last_loop.parent_loops) == 0:
137
+ return [Wale(last_loop)]
138
+ for top_stitch_parent in last_loop.parent_loops:
133
139
  wale = Wale(last_loop)
134
140
  wale.add_loop_to_beginning(top_stitch_parent, cast(Pull_Direction, self.get_pull_direction(top_stitch_parent, last_loop)))
135
141
  cur_loop = top_stitch_parent
136
142
  while len(cur_loop.parent_loops) == 1: # stop at split for decrease or start of wale
137
- cur_loop = [*self.stitch_graph.predecessors(cur_loop)][0]
143
+ cur_loop = cur_loop.parent_loops[0]
138
144
  wale.add_loop_to_beginning(cur_loop, cast(Pull_Direction, self.get_pull_direction(cur_loop, cast(Loop, wale.first_loop))))
139
145
  wales.append(wale)
140
146
  return wales
@@ -148,8 +154,8 @@ class Knit_Graph(_Base_Knit_Graph):
148
154
  """
149
155
  courses = []
150
156
  course = Course(self)
151
- for loop in sorted([*self.stitch_graph.nodes]):
152
- for parent in self.stitch_graph.predecessors(loop):
157
+ for loop in self.sorted_loops():
158
+ for parent in loop.parent_loops:
153
159
  if parent in course: # start a new course
154
160
  courses.append(course)
155
161
  course = Course(self)
@@ -165,21 +171,38 @@ class Knit_Graph(_Base_Knit_Graph):
165
171
  dict[Loop, Wale_Group]: 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.
166
172
  """
167
173
  wale_groups = {}
168
- for loop in self.stitch_graph.nodes:
174
+ for loop in self:
169
175
  if self.is_terminal_loop(loop):
170
176
  wale_groups.update({loop: Wale_Group(wale, self) for wale in self.get_wales_ending_with_loop(loop)})
171
177
  return wale_groups
172
178
 
173
- def __contains__(self, item: Loop) -> bool:
179
+ def __contains__(self, item: Loop | tuple[Loop, Loop]) -> bool:
174
180
  """Check if a loop is contained in the knit graph.
175
181
 
176
182
  Args:
177
- item (Loop): The loop being checked for in the graph.
183
+ item (Loop | tuple[Loop, Loop]): The loop being checked for in the graph or the parent-child stitch edge to check for in the knit graph.
184
+
185
+ Returns:
186
+ bool: True if the given loop or stitch edge is in the graph, False otherwise.
187
+ """
188
+ if isinstance(item, Loop):
189
+ return bool(self.stitch_graph.has_node(item))
190
+ else:
191
+ return bool(self.stitch_graph.has_edge(item[0], item[1]))
178
192
 
193
+ def __iter__(self) -> Iterator[Loop]:
194
+ """
195
+ Returns:
196
+ Iterator[Loop]: An iterator over all loops in the knit graph.
197
+ """
198
+ return cast(Iterator[Loop], iter(self.stitch_graph.nodes))
199
+
200
+ def sorted_loops(self) -> list[Loop]:
201
+ """
179
202
  Returns:
180
- bool: True if the loop is in the graph, False otherwise.
203
+ list[Loop]: The list of loops in the stitch graph sorted from the earliest formed loop to the latest formed loop.
181
204
  """
182
- return bool(self.stitch_graph.has_node(item))
205
+ return sorted(list(self.stitch_graph.nodes))
183
206
 
184
207
  def get_pull_direction(self, parent: Loop, child: Loop) -> Pull_Direction | None:
185
208
  """Get the pull direction of the stitch edge between parent and child loops.