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
|
@@ -1,88 +1,136 @@
|
|
|
1
|
-
"""Module containing the Wale_Group class and its methods.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
from
|
|
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
|
-
self.
|
|
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
|
-
|
|
1
|
+
"""Module containing the Wale_Group class and its methods.
|
|
2
|
+
|
|
3
|
+
This module provides the Wale_Group class which represents a collection of interconnected wales that are joined through decrease operations, forming a tree-like structure of vertical stitch columns.
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import cast
|
|
8
|
+
|
|
9
|
+
from networkx import DiGraph, dfs_preorder_nodes
|
|
10
|
+
|
|
11
|
+
from knit_graphs._base_classes import _Base_Knit_Graph
|
|
12
|
+
from knit_graphs.artin_wale_braids.Wale import Wale
|
|
13
|
+
from knit_graphs.Loop import Loop
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Wale_Group:
|
|
17
|
+
"""A graph structure maintaining relationships between connected wales through decrease operations.
|
|
18
|
+
|
|
19
|
+
This class represents a collection of wales that are connected through decrease stitches, where multiple wales merge into fewer wales as the knitting progresses upward.
|
|
20
|
+
It maintains both the wale-to-wale relationships and the individual stitch connections within the group.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
wale_graph (DiGraph): A directed graph representing the relationships between wales in this group.
|
|
24
|
+
stitch_graph (DiGraph): A directed graph of all individual stitch connections within this wale group.
|
|
25
|
+
terminal_wale (Wale | None): The topmost wale in this group, typically where multiple wales converge.
|
|
26
|
+
top_loops (dict[Loop, Wale]): Mapping from the last (top) loop of each wale to the wale itself.
|
|
27
|
+
bottom_loops (dict[Loop, Wale]): Mapping from the first (bottom) loop of each wale to the wale itself.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(self, terminal_wale: Wale, knit_graph: _Base_Knit_Graph):
|
|
31
|
+
"""Initialize a wale group starting from a terminal wale and building downward.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
terminal_wale (Wale): The topmost wale in the group, used as the starting point for building the complete group structure.
|
|
35
|
+
knit_graph (Knit_Graph): The parent knit graph that contains this wale group.
|
|
36
|
+
"""
|
|
37
|
+
self.wale_graph: DiGraph = DiGraph()
|
|
38
|
+
self.stitch_graph: DiGraph = DiGraph()
|
|
39
|
+
self._knit_graph: _Base_Knit_Graph = knit_graph
|
|
40
|
+
self.terminal_wale: Wale | None = terminal_wale
|
|
41
|
+
self.top_loops: dict[Loop, Wale] = {}
|
|
42
|
+
self.bottom_loops: dict[Loop, Wale] = {}
|
|
43
|
+
self.build_group_from_top_wale(terminal_wale)
|
|
44
|
+
|
|
45
|
+
def add_wale(self, wale: Wale) -> None:
|
|
46
|
+
"""Add a wale to the group and connect it to existing wales through shared loops.
|
|
47
|
+
|
|
48
|
+
This method adds the wale to the group's graphs and establishes connections with other wales based on shared loops at their endpoints.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
wale (Wale): The wale to add to this group. Empty wales are ignored and not added.
|
|
52
|
+
"""
|
|
53
|
+
if len(wale) == 0:
|
|
54
|
+
return # This wale is empty and therefore there is nothing to add to the wale group
|
|
55
|
+
self.wale_graph.add_node(wale)
|
|
56
|
+
for u, v in wale.stitches.edges:
|
|
57
|
+
self.stitch_graph.add_edge(u, v, pull_direction=wale.get_stitch_pull_direction(u, v))
|
|
58
|
+
for top_loop, other_wale in self.top_loops.items():
|
|
59
|
+
if top_loop == wale.first_loop:
|
|
60
|
+
self.wale_graph.add_edge(other_wale, wale)
|
|
61
|
+
for bot_loop, other_wale in self.bottom_loops.items():
|
|
62
|
+
if bot_loop == wale.last_loop:
|
|
63
|
+
self.wale_graph.add_edge(wale, other_wale)
|
|
64
|
+
assert isinstance(wale.last_loop, Loop)
|
|
65
|
+
self.top_loops[wale.last_loop] = wale
|
|
66
|
+
assert isinstance(wale.first_loop, Loop)
|
|
67
|
+
self.bottom_loops[wale.first_loop] = wale
|
|
68
|
+
|
|
69
|
+
def add_parent_wales(self, wale: Wale) -> list[Wale]:
|
|
70
|
+
"""Find and add all parent wales that created the given wale through decrease operations.
|
|
71
|
+
|
|
72
|
+
This method identifies wales that end at the loops that are parents of this wale's first loop, representing the wales that were decreased together to form the given wale.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
wale (Wale): The wale to find and add parent wales for.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
list[Wale]: The list of parent wales that were found and added to the group.
|
|
79
|
+
"""
|
|
80
|
+
added_wales = []
|
|
81
|
+
for parent_loop in cast(Loop, wale.first_loop).parent_loops:
|
|
82
|
+
parent_wales = cast(list[Wale], self._knit_graph.get_wales_ending_with_loop(parent_loop))
|
|
83
|
+
for parent_wale in parent_wales:
|
|
84
|
+
self.add_wale(parent_wale)
|
|
85
|
+
added_wales.extend(parent_wales)
|
|
86
|
+
return added_wales
|
|
87
|
+
|
|
88
|
+
def build_group_from_top_wale(self, top_wale: Wale) -> None:
|
|
89
|
+
"""Build the complete wale group by recursively finding all parent wales from the terminal wale.
|
|
90
|
+
|
|
91
|
+
This method starts with the terminal wale and recursively adds all parent wales, building the complete tree structure of wales that contribute to the terminal wale through decrease operations.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
top_wale (Wale): The terminal wale at the top of the group structure.
|
|
95
|
+
"""
|
|
96
|
+
self.add_wale(top_wale)
|
|
97
|
+
added_wales = self.add_parent_wales(top_wale)
|
|
98
|
+
while len(added_wales) > 0:
|
|
99
|
+
next_wale = added_wales.pop()
|
|
100
|
+
more_wales = self.add_parent_wales(next_wale)
|
|
101
|
+
added_wales.extend(more_wales)
|
|
102
|
+
|
|
103
|
+
def get_loops_over_courses(self) -> list[list[Loop]]:
|
|
104
|
+
"""Get loops organized by their course (horizontal row) within this wale group.
|
|
105
|
+
|
|
106
|
+
This method traces through the stitch connections starting from the terminal wale's top loop and groups loops by their vertical position (course) in the knitted structure.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
list[list[Loop]]: A list where each inner list contains all loops that belong to the same course, ordered from top to bottom courses. Returns empty list if there is no terminal wale.
|
|
110
|
+
"""
|
|
111
|
+
if self.terminal_wale is None:
|
|
112
|
+
return []
|
|
113
|
+
top_loop: Loop = cast(Loop, self.terminal_wale.last_loop)
|
|
114
|
+
courses: list[list[Loop]] = []
|
|
115
|
+
cur_course: list[Loop] = [top_loop]
|
|
116
|
+
while len(cur_course) > 0:
|
|
117
|
+
courses.append(cur_course)
|
|
118
|
+
next_course = []
|
|
119
|
+
for loop in cur_course:
|
|
120
|
+
next_course.extend(self.stitch_graph.predecessors(loop))
|
|
121
|
+
cur_course = next_course
|
|
122
|
+
return courses
|
|
123
|
+
|
|
124
|
+
def __len__(self) -> int:
|
|
125
|
+
"""Get the height of the wale group measured as the maximum number of loops from base to terminal.
|
|
126
|
+
|
|
127
|
+
This method calculates the total length by summing all loops in all wales that can be reached from each bottom wale, returning the maximum total length found.
|
|
128
|
+
|
|
129
|
+
Returns:
|
|
130
|
+
int: The height of the wale group from the base loops to the tallest terminal, measured in total number of loops.
|
|
131
|
+
"""
|
|
132
|
+
max_len = 0
|
|
133
|
+
for bot_loop, wale in self.bottom_loops.items():
|
|
134
|
+
path_len = sum(len(successor) for successor in dfs_preorder_nodes(self.wale_graph, wale))
|
|
135
|
+
max_len = max(max_len, path_len)
|
|
136
|
+
return max_len
|