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.
Files changed (47) hide show
  1. knit_graphs-0.0.6.dist-info/licenses/LICENSE → LICENSE +21 -21
  2. README.md +75 -0
  3. docs/Makefile +20 -0
  4. docs/make.bat +35 -0
  5. docs/source/api/knit_graphs.Course.rst +7 -0
  6. docs/source/api/knit_graphs.Knit_Graph.rst +7 -0
  7. docs/source/api/knit_graphs.Knit_Graph_Visualizer.rst +7 -0
  8. docs/source/api/knit_graphs.Loop.rst +7 -0
  9. docs/source/api/knit_graphs.Pull_Direction.rst +7 -0
  10. docs/source/api/knit_graphs.Yarn.rst +7 -0
  11. docs/source/api/knit_graphs.artin_wale_braids.Crossing_Direction.rst +7 -0
  12. docs/source/api/knit_graphs.artin_wale_braids.Loop_Braid_Graph.rst +7 -0
  13. docs/source/api/knit_graphs.artin_wale_braids.Wale.rst +7 -0
  14. docs/source/api/knit_graphs.artin_wale_braids.Wale_Braid.rst +7 -0
  15. docs/source/api/knit_graphs.artin_wale_braids.Wale_Braid_Word.rst +7 -0
  16. docs/source/api/knit_graphs.artin_wale_braids.Wale_Group.rst +7 -0
  17. docs/source/api/knit_graphs.artin_wale_braids.rst +23 -0
  18. docs/source/api/knit_graphs.basic_knit_graph_generators.rst +7 -0
  19. docs/source/api/knit_graphs.rst +32 -0
  20. docs/source/conf.py +335 -0
  21. docs/source/index.rst +71 -0
  22. docs/source/installation.rst +67 -0
  23. knit_graphs/Course.py +156 -104
  24. knit_graphs/Knit_Graph.py +249 -186
  25. knit_graphs/Knit_Graph_Visualizer.py +675 -0
  26. knit_graphs/Loop.py +141 -155
  27. knit_graphs/Pull_Direction.py +68 -23
  28. knit_graphs/Yarn.py +424 -267
  29. knit_graphs/__init__.py +3 -3
  30. knit_graphs/_base_classes.py +173 -0
  31. knit_graphs/artin_wale_braids/Crossing_Direction.py +74 -15
  32. knit_graphs/artin_wale_braids/Loop_Braid_Graph.py +95 -62
  33. knit_graphs/artin_wale_braids/Wale.py +169 -93
  34. knit_graphs/artin_wale_braids/Wale_Braid.py +50 -30
  35. knit_graphs/artin_wale_braids/Wale_Braid_Word.py +99 -54
  36. knit_graphs/artin_wale_braids/Wale_Group.py +136 -88
  37. knit_graphs/basic_knit_graph_generators.py +251 -0
  38. knit_graphs-0.0.8.dist-info/LICENSE +21 -0
  39. {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.8.dist-info}/METADATA +33 -24
  40. knit_graphs-0.0.8.dist-info/RECORD +42 -0
  41. {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.8.dist-info}/WHEEL +1 -1
  42. knit_graphs/__about__.py +0 -4
  43. knit_graphs/knit_graph_generators/__init__.py +0 -0
  44. knit_graphs/knit_graph_generators/basic_knit_graph_generators.py +0 -248
  45. knit_graphs/knit_graph_visualizer/Stitch_Visualizer.py +0 -427
  46. knit_graphs/knit_graph_visualizer/__init__.py +0 -0
  47. 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
- import networkx
3
-
4
- from knit_graphs.Loop import Loop
5
- from knit_graphs.artin_wale_braids.Wale import Wale
6
-
7
-
8
- class Wale_Group:
9
- """
10
- A graphs structure maintaining the relationship between connected wales through decreases
11
- """
12
-
13
- def __init__(self, terminal_wale: Wale, knit_graph):
14
- self.wale_graph: networkx.DiGraph = networkx.DiGraph()
15
- self.stitch_graph: networkx.DiGraph = networkx.DiGraph()
16
- self.terminal_wale: Wale | None = terminal_wale
17
- self.top_loops: dict[Loop, Wale] = {}
18
- self.bottom_loops: dict[Loop, Wale] = {}
19
- self.build_group_from_top_wale(terminal_wale, knit_graph)
20
-
21
- def add_wale(self, wale: Wale):
22
- """
23
- :param wale: Adds wale to group and connects by di-graph by position of shared loops.
24
- """
25
- self.wale_graph.add_node(wale)
26
- for u, v in wale.stitches.edges:
27
- self.stitch_graph.add_edge(u, v, pull_direction=wale.stitches.get_edge_data(u, v, "pull_direction"))
28
- for top_loop, other_wale in self.top_loops.items():
29
- if top_loop == wale.first_loop:
30
- self.wale_graph.add_edge(other_wale, wale)
31
- for bot_loop, other_wale in self.bottom_loops.items():
32
- if bot_loop == wale.last_loop:
33
- self.wale_graph.add_edge(wale, other_wale)
34
- self.top_loops[wale.last_loop] = wale
35
- self.bottom_loops[wale.first_loop] = wale
36
-
37
- def add_parent_wales(self, wale: Wale, knit_graph) -> list[Wale]:
38
- """
39
- Add parent wales that created the given wale to a wale group.
40
- :param wale: Wale to find parents from.
41
- :param knit_graph: Knit graph used to derive stitch relationships.
42
- :return: List of wales that were added.
43
- """
44
- added_wales = []
45
- for parent_loop in wale.first_loop.parent_loops:
46
- parent_wales = knit_graph.get_wales_ending_with_loop(parent_loop)
47
- for parent_wale in parent_wales:
48
- self.add_wale(parent_wale)
49
- added_wales.extend(parent_wales)
50
- return added_wales
51
-
52
- def build_group_from_top_wale(self, top_wale: Wale, knit_graph):
53
- """
54
- Builds out a wale group by finding parent wales from top wale provided
55
- :param top_wale: top of a wale tree.
56
- :param knit_graph: Knit graph used to derive stitch relationships.
57
- """
58
- self.add_wale(top_wale)
59
- added_wales = self.add_parent_wales(top_wale, knit_graph)
60
- while len(added_wales) > 0:
61
- next_wale = added_wales.pop()
62
- more_wales = self.add_parent_wales(next_wale, knit_graph)
63
- added_wales.extend(more_wales)
64
-
65
- def get_loops_over_courses(self) -> list[list[Loop]]:
66
- """
67
- :return: List of lists of loops that are in the same course by wales
68
- """
69
- top_loop = self.terminal_wale.last_loop
70
- courses = []
71
- cur_course = [top_loop]
72
- while len(cur_course) > 0:
73
- courses.append(cur_course)
74
- next_course = []
75
- for loop in cur_course:
76
- next_course.extend(self.stitch_graph.predecessors(loop))
77
- cur_course = next_course
78
- return courses
79
-
80
- def __len__(self):
81
- """
82
- :return: height of the wale group from base loop to the tallest terminal
83
- """
84
- max_len = 0
85
- for bot_loop, wale in self.bottom_loops.items():
86
- path_len = sum(len(successor) for successor in networkx.dfs_preorder_nodes(self.wale_graph, wale))
87
- max_len = max(max_len, path_len)
88
- return max_len
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
@@ -0,0 +1,251 @@
1
+ """Module of functions that generate basic knit graph swatches.
2
+
3
+ This module provides utility functions for creating common knitting patterns and structures as knit graphs.
4
+ These functions serve as building blocks for testing and demonstration purposes.
5
+ """
6
+ from knit_graphs.artin_wale_braids.Crossing_Direction import Crossing_Direction
7
+ from knit_graphs.Knit_Graph import Knit_Graph
8
+ from knit_graphs.Loop import Loop
9
+ from knit_graphs.Pull_Direction import Pull_Direction
10
+ from knit_graphs.Yarn import Yarn
11
+
12
+
13
+ def co_loops(width: int) -> tuple[Knit_Graph, Yarn]:
14
+ """Create a cast-on row of loops forming the foundation for knitting patterns.
15
+
16
+ Args:
17
+ width (int): The number of loops to create in the cast-on row.
18
+
19
+ Returns:
20
+ tuple[Knit_Graph, Yarn]: A tuple containing the knit graph with one course of the specified width and the yarn used to create it.
21
+ """
22
+ knit_graph = Knit_Graph()
23
+ yarn = Yarn(knit_graph=knit_graph)
24
+ for _ in range(0, width):
25
+ _loop = yarn.make_loop_on_end()
26
+ return knit_graph, yarn
27
+
28
+
29
+ def jersey_swatch(width: int, height: int) -> Knit_Graph:
30
+ """Generate a rectangular knit swatch with all knit stitches in a flat sheet structure.
31
+
32
+ This creates a basic stockinette/jersey pattern where all stitches are worked as knit stitches from back to front.
33
+
34
+ Args:
35
+ width (int): The number of stitches per course (horizontal row).
36
+ height (int): The number of courses (vertical rows) in the swatch.
37
+
38
+ Returns:
39
+ Knit_Graph: A knit graph representing a flat rectangular swatch with all knit stitches.
40
+ """
41
+ knit_graph, yarn = co_loops(width)
42
+ last_course = list(knit_graph.get_courses()[0])
43
+ for _ in range(0, height):
44
+ next_course = []
45
+ for parent_loop in reversed(last_course):
46
+ child_loop = yarn.make_loop_on_end()
47
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF)
48
+ next_course.append(child_loop)
49
+ last_course = next_course
50
+ return knit_graph
51
+
52
+
53
+ def jersey_tube(tube_width: int, height: int) -> Knit_Graph:
54
+ """Generate a tubular knit structure with all knit stitches worked in the round.
55
+
56
+ This creates a seamless tube by knitting in the round, where the front and back sections are connected by floats to maintain the circular structure.
57
+
58
+ Args:
59
+ tube_width (int): The number of stitches per course on the front side of the tube.
60
+ height (int): The number of courses (vertical rows) in the tube.
61
+
62
+ Returns:
63
+ Knit_Graph: A knit graph representing a seamless tube with all knit stitches.
64
+ """
65
+ knit_graph, yarn = co_loops(tube_width * 2)
66
+ last_course = [*knit_graph.get_courses()[0]]
67
+
68
+ def _set_tube_floats() -> None:
69
+ """Internal helper function to set up float connections between front and back of tube."""
70
+ front_loops = last_course[0:tube_width]
71
+ back_loops = last_course[tube_width:]
72
+ for first_front, second_front, back in zip(front_loops[0:-1], front_loops[1:], reversed(back_loops)):
73
+ yarn.add_loop_behind_float(back, first_front, second_front)
74
+ for (first_back, second_back, front) in zip(back_loops[0:-1], back_loops[1:], reversed(front_loops)):
75
+ yarn.add_loop_in_front_of_float(front, first_back, second_back)
76
+
77
+ _set_tube_floats()
78
+ for _ in range(0, height):
79
+ next_course = [yarn.make_loop_on_end() for _p in last_course]
80
+ for parent_loop, child_loop in zip(last_course, next_course):
81
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF)
82
+ last_course = next_course
83
+ _set_tube_floats()
84
+ return knit_graph
85
+
86
+
87
+ def kp_rib_swatch(width: int, height: int) -> Knit_Graph:
88
+ """Generate a knit-purl ribbing swatch with alternating wales of knit and purl stitches.
89
+
90
+ This creates a 1x1 ribbing pattern where knit and purl wales alternate, maintaining their stitch type throughout the height of the swatch for a stretchy, textured fabric.
91
+
92
+ Args:
93
+ width (int): The number of stitches per course (horizontal row).
94
+ height (int): The number of courses (vertical rows) in the swatch.
95
+
96
+ Returns:
97
+ Knit_Graph: A knit graph representing a ribbed swatch with alternating knit and purl wales.
98
+ """
99
+ knit_graph, yarn = co_loops(width)
100
+ last_course = knit_graph.get_courses()[0]
101
+ next_course = []
102
+ next_pull = Pull_Direction.BtF
103
+ for parent_loop in reversed(last_course):
104
+ child_loop = yarn.make_loop_on_end()
105
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=next_pull)
106
+ next_pull = next_pull.opposite()
107
+ next_course.append(child_loop)
108
+ last_course = next_course
109
+ for _ in range(1, height):
110
+ next_course = []
111
+ for parent_loop in reversed(last_course):
112
+ grand_parent = parent_loop.parent_loops[0]
113
+ parent_pull = knit_graph.get_pull_direction(grand_parent, parent_loop)
114
+ assert isinstance(parent_pull, Pull_Direction)
115
+ child_loop = yarn.make_loop_on_end()
116
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=parent_pull)
117
+ next_course.append(child_loop)
118
+ last_course = next_course
119
+ return knit_graph
120
+
121
+
122
+ def seed_swatch(width: int, height: int) -> Knit_Graph:
123
+ """Generate a seed stitch swatch with a checkerboard pattern of knit and purl stitches.
124
+
125
+ This creates a textured fabric where each stitch alternates between knit and purl both horizontally and vertically, creating a bumpy, non-curling fabric texture.
126
+
127
+ Args:
128
+ width (int): The number of stitches per course (horizontal row).
129
+ height (int): The number of courses (vertical rows) in the swatch.
130
+
131
+ Returns:
132
+ Knit_Graph: A knit graph representing a seed stitch swatch with checkerboard knit-purl pattern.
133
+ """
134
+ knit_graph, yarn = co_loops(width)
135
+ last_course = knit_graph.get_courses()[0]
136
+ next_course = []
137
+ next_pull = Pull_Direction.BtF
138
+ for parent_loop in reversed(last_course):
139
+ child_loop = yarn.make_loop_on_end()
140
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=next_pull)
141
+ next_pull = next_pull.opposite()
142
+ next_course.append(child_loop)
143
+ last_course = next_course
144
+ for _ in range(1, height):
145
+ next_course = []
146
+ for parent_loop in reversed(last_course):
147
+ grand_parent = parent_loop.parent_loops[0]
148
+ parent_pull = knit_graph.get_pull_direction(grand_parent, parent_loop)
149
+ assert isinstance(parent_pull, Pull_Direction)
150
+ child_loop = yarn.make_loop_on_end()
151
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=parent_pull.opposite())
152
+ next_course.append(child_loop)
153
+ last_course = next_course
154
+ return knit_graph
155
+
156
+
157
+ def lace_mesh(width: int, height: int) -> Knit_Graph:
158
+ """Generate a mesh pattern with alternating left and right leaning decrease paired to yarn-overs.
159
+ These pairings create a basic lace pattern with eyelets formed around the increases.
160
+
161
+ Args:
162
+ width (int): The number of stitches per course (horizontal row).
163
+ height (int): The number of courses (vertical rows) in the swatch.
164
+
165
+ Returns:
166
+ Knit_Graph: A knit graph representing a mesh swatch.
167
+ """
168
+ knit_graph, yarn = co_loops(width)
169
+ last_course = knit_graph.get_courses()[0]
170
+ next_course = []
171
+ for parent_loop in reversed(last_course):
172
+ child_loop = yarn.make_loop_on_end()
173
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF)
174
+ next_course.append(child_loop)
175
+ last_course = next_course
176
+ for _ in range(1, height):
177
+ # Make the lace course
178
+ next_course = []
179
+ yo_parent = None
180
+ prior_child = None
181
+ for i, parent_loop in enumerate(reversed(last_course)):
182
+ child_loop = yarn.make_loop_on_end()
183
+ if i % 3 == 0: # Just knit every third stitch
184
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF, stack_position=0)
185
+ elif i % 6 == 1: # Second of every 6 stitches (0 indexed) is yarn over before a decrease.
186
+ yo_parent = parent_loop
187
+ elif i % 6 == 2: # Third of every 6 stitches is bottom of decrease with prior yarn-over's parent
188
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF, stack_position=0)
189
+ assert isinstance(yo_parent, Loop)
190
+ knit_graph.connect_loops(yo_parent, child_loop, pull_direction=Pull_Direction.BtF, stack_position=1)
191
+ elif i % 6 == 4: # Fifth of every six stitches is bottom of decrease with next yarn-over's parent
192
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF, stack_position=0)
193
+ prior_child = child_loop
194
+ elif i % 6 == 5: # The last of six stitches is the top of the prior decrease and new yarn-over
195
+ assert isinstance(prior_child, Loop)
196
+ knit_graph.connect_loops(parent_loop, prior_child, pull_direction=Pull_Direction.BtF, stack_position=1)
197
+ next_course.append(child_loop)
198
+ last_course = next_course
199
+ # Make a basic jersey course
200
+ next_course = []
201
+ for parent_loop in reversed(last_course):
202
+ child_loop = yarn.make_loop_on_end()
203
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF)
204
+ next_course.append(child_loop)
205
+ last_course = next_course
206
+ return knit_graph
207
+
208
+
209
+ def twist_cable(width: int, height: int) -> Knit_Graph:
210
+ """Generate a twisted cable pattern with alternating crossing directions and purl separators.
211
+
212
+ This creates a cable pattern with 1x1 twists that alternate direction every two rows, separated by purl wales to make the cable structure more prominent.
213
+
214
+ Args:
215
+ width (int): The number of stitches per course (horizontal row).
216
+ height (int): The number of courses (vertical rows) in the swatch.
217
+
218
+ Returns:
219
+ Knit_Graph: A knit graph representing a twisted cable pattern with alternating crossing directions.
220
+ """
221
+ # p k\k p ->: 3-4
222
+ # p k k p <-: 2-3
223
+ # p k/k p ->: 1-2
224
+ # p k k p <-: 0-1
225
+ # 0 1 2 3
226
+ knit_graph, yarn = co_loops(width)
227
+ last_course = knit_graph.get_courses()[0]
228
+ next_course = []
229
+ pull_directions = [Pull_Direction.FtB, Pull_Direction.BtF, Pull_Direction.BtF, Pull_Direction.FtB]
230
+ for i, parent_loop in enumerate(reversed(last_course)):
231
+ child_loop = yarn.make_loop_on_end()
232
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=pull_directions[i % 4])
233
+ next_course.append(child_loop)
234
+ last_course = next_course
235
+ crossing = Crossing_Direction.Over_Right
236
+ for r in range(1, height):
237
+ next_course = [yarn.make_loop_on_end() for _ in last_course]
238
+ for i, parent_loop in enumerate(reversed(last_course)):
239
+ if r % 2 == 0 or i % 4 == 0 or i % 4 == 3: # not cable row (even) or in purl wale
240
+ child_loop = next_course[i]
241
+ elif i % 4 == 1:
242
+ child_loop = next_course[i + 1]
243
+ else:
244
+ child_loop = next_course[i - 1]
245
+ knit_graph.connect_loops(parent_loop, child_loop, pull_direction=pull_directions[i % 4])
246
+ if r % 2 == 1: # cable row
247
+ for left_loop, right_loop in zip(next_course[1::4], next_course[2::4]):
248
+ knit_graph.add_crossing(left_loop, right_loop, crossing)
249
+ crossing = ~crossing
250
+ last_course = next_course
251
+ return knit_graph
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Megan Hofmann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,23 +1,29 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.1
2
2
  Name: knit-graphs
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: A graph representation of knitted structures where each loop is a node and edges represent yarn and stitch relationships.
5
- Project-URL: Documentation, https://github.com/mhofmann-Khoury/knit_graph#readme
6
- Project-URL: Issues, https://github.com/mhofmann-Khoury/knit_graph/issues
7
- Project-URL: Source, https://github.com/mhofmann-Khoury/knit_graph
8
- Author-email: Megan Hofmann <m.hofmann@northeastern.edu>
9
- License-File: LICENSE
10
- Keywords: ACT Lab,Northeastern,fabrication,knit,machine knit,textile
11
- Classifier: Development Status :: 2 - Pre-Alpha
5
+ Home-page: https://mhofmann-Khoury.github.io/knit-graphs/
6
+ License: MIT
7
+ Keywords: ACT Lab,Northeastern University,knit,machine knit,fabrication,textile
8
+ Author: Megan Hofmann
9
+ Author-email: m.hofmann@northeastern.edu
10
+ Maintainer: Megan Hofmann
11
+ Maintainer-email: m.hofmann@northeastern.edu
12
+ Requires-Python: >=3.11,<3.14
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
12
16
  Classifier: Natural Language :: English
13
- Classifier: Programming Language :: Python
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
14
19
  Classifier: Programming Language :: Python :: 3.11
15
20
  Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: Implementation :: PyPy
21
+ Classifier: Programming Language :: Python :: 3.13
17
22
  Classifier: Topic :: Scientific/Engineering
18
- Requires-Python: >=3.11
19
- Requires-Dist: networkx~=3.2.1
20
- Requires-Dist: plotly~=5.22.0
23
+ Requires-Dist: networkx (>=3.5)
24
+ Requires-Dist: plotly (>=6.3.0,<7.0.0)
25
+ Project-URL: Documentation, https://mhofmann-Khoury.github.io/knit-graphs/
26
+ Project-URL: Repository, https://github.com/mhofmann-Khoury/knit-graphs
21
27
  Description-Content-Type: text/markdown
22
28
 
23
29
  # knit_graphs
@@ -27,9 +33,9 @@ Description-Content-Type: text/markdown
27
33
 
28
34
  -----
29
35
  ## Description
30
- The knit-graphs packaged provides a data structure for representing knitted structures formed of loops of yarn (nodes) connected by various edge structures. Loops are connected by: floats (yarn-edges) in a yarn graph structure, stitch edges (loops pulled through loops), and crossed over each other in a wale-braid structure.
36
+ The knit-graphs packaged provides a data structure for representing knitted structures formed of loops of yarn (nodes) connected by various edge structures. Loops are connected by: floats (yarn-edges) in a yarn graph structure, stitch edges (loops pulled through loops), and crossed over each other in a wale-braid structure.
31
37
 
32
- Knit graphs provide a powerful tool for representing knitted structures for digital fabrication systems such as knitting machine programming languages and design tools.
38
+ Knit graphs provide a powerful tool for representing knitted structures for digital fabrication systems such as knitting machine programming languages and design tools.
33
39
 
34
40
  Additional details about this knit-graph construction are available in the ACM publication:
35
41
  ["KnitPicking Texture: Programming and Modifying Complex Knitted Textures for Machine and Hand Knitting"](https://doi.org/10.1145/3332165.3347886)
@@ -54,25 +60,27 @@ pip install knit-graphs
54
60
  ## Usage
55
61
 
56
62
  ### Knit Graph Generators
57
- The [knit-graph-generators subpackage](https://github.com/mhofmann-Khoury/knit_graph/tree/main/src/knit_graphs/knit_graph_generators) provides a library of basic knit graphs to generate such as casting on loops of a knitted structure, creating Jersey (aka Stockinette) tubes and swatches, and other basic textures.
63
+ The [knit-graph-generators subpackage](https://github.com/mhofmann-Khoury/knit_graph/tree/main/src/knit_graphs/knit_graph_generators) provides a library of basic knit graphs to generate such as casting on loops of a knitted structure, creating Jersey (aka Stockinette) tubes and swatches, and other basic textures.
58
64
  For example, to generate a swatch of knit-purl ribbing use the following:
65
+
59
66
  ```python
60
- from knit_graphs.knit_graph_generators.basic_knit_graph_generators import kp_rib_swatch
67
+ from knit_graphs.basic_knit_graph_generators import kp_rib_swatch
68
+
61
69
  width = 10
62
70
  height = 10
63
71
  kp_rib_swatch = kp_rib_swatch(width, height)
64
72
  ```
65
73
  Additional examples of knitgraph generator usage can be found in the [Knit_Graph test module](https://github.com/mhofmann-Khoury/knit_graph/blob/main/tests/test_Knit_Graph.py).
66
74
 
67
- Knitgraphs can be created without generators. We encourage users to review the generators as simple examples on creating a knit graph programmatically.
75
+ Knitgraphs can be created without generators. We encourage users to review the generators as simple examples on creating a knit graph programmatically.
68
76
 
69
77
  ### Visualizing Knit Graphs
70
- We provide simple support for visualizing knit graphs. This is primarily used to debugging simple knit graph programs.
78
+ We provide simple support for visualizing knit graphs. This is primarily used to debugging simple knit graph programs.
71
79
 
72
80
  For example, we can visualize a swatch of seed stitch (checkered knit and purl stitches) with the following code.
73
81
 
74
82
  ```python
75
- from knit_graphs.knit_graph_generators.basic_knit_graph_generators import seed_swatch
83
+ from knit_graphs.basic_knit_graph_generators import seed_swatch
76
84
  from knit_graphs.knit_graph_visualizer.Stitch_Visualizer import visualize_stitches
77
85
 
78
86
  width = 4
@@ -80,16 +88,17 @@ height = 4
80
88
  swatch = seed_swatch(width, height)
81
89
  visualize_stitches(swatch)
82
90
  ```
83
- The visualizer shows knit stitches (loops pulled from the back of the fabric to the front) as blue edges and purl stitches (loops pulled from the front to back) (aka back-knits) as red edges. Loop nodes are circles labeled with their time-ordered index and colored to match their yarn (defaults to dark green). The yarn edges (aka floats) connecting them are made of thin edges the same color as the loop nodes.
91
+ The visualizer shows knit stitches (loops pulled from the back of the fabric to the front) as blue edges and purl stitches (loops pulled from the front to back) (aka back-knits) as red edges. Loop nodes are circles labeled with their time-ordered index and colored to match their yarn (defaults to dark green). The yarn edges (aka floats) connecting them are made of thin edges the same color as the loop nodes.
84
92
 
85
93
  Additional examples of using the visualizer are available in the [Stitch Visualizer Tests Module](https://github.com/mhofmann-Khoury/knit_graph/blob/main/tests/test_Stitch_Visualizer.py)
86
94
 
87
95
  ## Credits
88
- The design of this data scructure was completed by the authors of
96
+ The design of this data scructure was completed by the authors of
89
97
  ["KnitPicking Texture: Programming and Modifying Complex Knitted Textures for Machine and Hand Knitting"](https://doi.org/10.1145/3332165.3347886).
90
98
 
91
99
  The inclusion of the Artin-Braide wale crossing construction was inspired by ["An Artin Braid Group Representation of Knitting Machine State with Applications to Validation and Optimization of Fabrication Plans"](https://doi.org/10.1109/ICRA48506.2021.9562113) by Jenny Lin and James McCann.
92
100
 
93
101
  ## License
94
102
 
95
- `knit-graphs` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
103
+ `knit-graphs` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
104
+