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.
Files changed (33) 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.artin_wale_braids.rst +58 -0
  6. docs/source/api/knit_graphs.rst +74 -0
  7. docs/source/conf.py +335 -0
  8. docs/source/index.rst +71 -0
  9. docs/source/installation.rst +67 -0
  10. knit_graphs/Course.py +156 -104
  11. knit_graphs/Knit_Graph.py +249 -186
  12. knit_graphs/Knit_Graph_Visualizer.py +680 -0
  13. knit_graphs/Loop.py +141 -155
  14. knit_graphs/Pull_Direction.py +68 -23
  15. knit_graphs/Yarn.py +424 -267
  16. knit_graphs/__init__.py +3 -3
  17. knit_graphs/_base_classes.py +173 -0
  18. knit_graphs/artin_wale_braids/Crossing_Direction.py +74 -15
  19. knit_graphs/artin_wale_braids/Loop_Braid_Graph.py +95 -62
  20. knit_graphs/artin_wale_braids/Wale.py +169 -93
  21. knit_graphs/artin_wale_braids/Wale_Braid.py +50 -30
  22. knit_graphs/artin_wale_braids/Wale_Braid_Word.py +99 -54
  23. knit_graphs/artin_wale_braids/Wale_Group.py +136 -88
  24. knit_graphs/{knit_graph_generators/basic_knit_graph_generators.py → basic_knit_graph_generators.py} +302 -248
  25. knit_graphs-0.0.7.dist-info/LICENSE +21 -0
  26. {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.7.dist-info}/METADATA +33 -24
  27. knit_graphs-0.0.7.dist-info/RECORD +29 -0
  28. {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.7.dist-info}/WHEEL +1 -1
  29. knit_graphs/__about__.py +0 -4
  30. knit_graphs/knit_graph_generators/__init__.py +0 -0
  31. knit_graphs/knit_graph_visualizer/Stitch_Visualizer.py +0 -427
  32. knit_graphs/knit_graph_visualizer/__init__.py +0 -0
  33. 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
- class Loop:
5
- """
6
- A class to represent a single loop structure for modeling a single loop in a knitting pattern.
7
-
8
- Attributes:
9
- -----------
10
- _loop_id : int
11
- a unique identifier for the loop
12
- yarn : Yarn
13
- the Yarn variable that creates and holds this loop
14
- parent_loops : list
15
- the list of parent loops
16
- front_floats : dict
17
- a dictionary of loops in front of the float
18
- back_floats : dict
19
- a dictionary of loops behind the float
20
-
21
- Methods:
22
- -----------
23
- add_loop_in_front_of_float(u, v)
24
- Set this loop to be in front of the float between u and v
25
- add_loop_behind_float(u, v)
26
- Set this loop to be behind the float between u and v
27
- is_in_front_of_float(u, v)
28
- Check if the float between u and v is in front of this loop
29
- is_behind_float(u, v)
30
- Check if the float between u and v is behind this loop
31
- prior_loop_on_yarn()
32
- Return the prior loop on yarn or None if first loop on yarn
33
- next_loop_on_yarn()
34
- Return the next loop on yarn or None if last loop on yarn
35
- has_parent_loops()
36
- Check if loop has stitch-edge parents
37
- add_parent_loop(parent, stack_position)
38
- Add the parent Loop onto the stack of parent_loops
39
- """
40
-
41
- def __init__(self, loop_id: int, yarn):
42
- """
43
- Constructs the Loop object.
44
-
45
- Parameters:
46
- -----------
47
- loop_id : int
48
- a unique identifier for the loop, must be non-negative
49
- yarn : Yarn
50
- the Yarn variable that creates and holds this loop
51
- """
52
- assert loop_id >= 0, f"{loop_id}: Loop_id must be non-negative"
53
- self._loop_id: int = loop_id
54
- self.yarn = yarn
55
- self.parent_loops: list[Loop] = []
56
- self.front_floats: dict[Loop, set[Loop]] = {}
57
- self.back_floats: dict[Loop, set[Loop]] = {}
58
-
59
- def add_loop_in_front_of_float(self, u, v):
60
- """
61
- Set this loop to be in front of the float between u and v
62
- :param u: First loop in float
63
- :param v: Second loop in float
64
- """
65
- if u not in self.back_floats:
66
- self.back_floats[u] = set()
67
- if v not in self.back_floats:
68
- self.back_floats[v] = set()
69
- self.back_floats[u].add(v)
70
- self.back_floats[v].add(u)
71
-
72
- def add_loop_behind_float(self, u, v):
73
- """
74
- Set this loop to be behind the float between u and v
75
- :param u: First loop in float
76
- :param v: Second loop in float
77
- """
78
- if u not in self.front_floats:
79
- self.front_floats[u] = set()
80
- if v not in self.front_floats:
81
- self.front_floats[v] = set()
82
- self.front_floats[u].add(v)
83
- self.front_floats[v].add(u)
84
-
85
- def is_in_front_of_float(self, u, v) -> bool:
86
- """
87
- :param u: First loop in float.
88
- :param v: Second loop in float.
89
- :return: True if the float between u and v is in front of this loop.
90
- """
91
- return u in self.back_floats and v in self.back_floats and v in self.back_floats[u]
92
-
93
- def is_behind_float(self, u, v) -> bool:
94
- """
95
- :param u: First loop in float.
96
- :param v: Second loop in float.
97
- :return: True if the float between u and v is behind this loop.
98
- """
99
- return u in self.front_floats and v in self.front_floats and v in self.front_floats[u]
100
-
101
- def prior_loop_on_yarn(self):
102
- """
103
- :return: Prior loop on yarn or None if first loop on yarn
104
- """
105
- return self.yarn.prior_loop(self)
106
-
107
- def next_loop_on_yarn(self):
108
- """
109
- :return: Next loop on yarn or Non if last loop on yarn
110
- """
111
- return self.yarn.next_loop(self)
112
-
113
- def has_parent_loops(self) -> bool:
114
- """
115
- :return: True if loop has stitch-edge parents
116
- """
117
- return len(self.parent_loops) > 0
118
-
119
- def add_parent_loop(self, parent, stack_position: int | None = None):
120
- """
121
- Adds the parent Loop onto the stack of parent_loops
122
- :param parent: the Loop to be added onto the stack
123
- :param stack_position: The position to insert the parent into, by default add on top of the stack
124
- """
125
- if stack_position is not None:
126
- self.parent_loops.insert(stack_position, parent)
127
- else:
128
- self.parent_loops.append(parent)
129
-
130
- @property
131
- def loop_id(self) -> int:
132
- """
133
- :return: the id of the loop
134
- """
135
- return self._loop_id
136
-
137
- def __hash__(self):
138
- return self.loop_id
139
-
140
- def __eq__(self, other):
141
- return isinstance(other, Loop) and self.loop_id == other.loop_id and self.yarn == other.yarn
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}"
@@ -1,23 +1,68 @@
1
- """Enumerator used to define the two pull-direction of a loop through other loops"""
2
- from enum import Enum
3
-
4
-
5
- class Pull_Direction(Enum):
6
- """An enumerator of the two pull-directions of a loop."""
7
- BtF = "Knit"
8
- FtB = "Purl"
9
-
10
- def opposite(self):
11
- """
12
- :return: returns the opposite pull direction of self
13
- """
14
- if self is Pull_Direction.BtF:
15
- return Pull_Direction.FtB
16
- else:
17
- return Pull_Direction.BtF
18
-
19
- def __str__(self):
20
- return self.value
21
-
22
- def __repr__(self):
23
- return self.value
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)