jerboapy 0.2rc332__cp313-cp313-win_amd64.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.
jerboapy_ext/utils.py ADDED
@@ -0,0 +1,214 @@
1
+ from jerboapy import *
2
+ import math
3
+ from .Point3 import Point3
4
+ from .Color4 import Color4
5
+
6
+
7
+ def make_polygon(gmap, vertices):
8
+ """Create a polygon in the GMap from a list of vertices.
9
+ Args:
10
+ gmap (GMap): The GMap to which the polygon will be added.
11
+ vertices (list of Point3): A list of Point3 objects representing the vertices of the polygon.
12
+
13
+ Returns:
14
+ list of Dart: The list of darts created for the polygon.
15
+ """
16
+ num_vertices = len(vertices)
17
+ if num_vertices < 3:
18
+ raise ValueError("A polygon must have at least 3 vertices.")
19
+
20
+ darts = gmap.make_darts(num_vertices * 2)
21
+ color = Color4.randomColor()
22
+
23
+ # Compute the normal vector using the first three vertices
24
+ ab = vertices[1] - vertices[0]
25
+ ac = vertices[2] - vertices[0]
26
+ normal = ab.cross(ac)
27
+ normal.normalize()
28
+
29
+ for i in range(num_vertices):
30
+ darts[i * 2].ebd123["pos"] = vertices[i]
31
+ darts[i * 2].ebd01["normal"] = normal
32
+ darts[i * 2].ebd01["color"] = color
33
+ darts[i * 2].ebd["orient"] = True
34
+
35
+ darts[i * 2 + 1].ebd123["pos"] = vertices[i]
36
+ darts[i * 2 + 1].ebd01["normal"] = normal
37
+ darts[i * 2 + 1].ebd01["color"] = color
38
+ darts[i * 2 + 1].ebd["orient"] = False
39
+
40
+ # Link the darts to form the edges of the polygon
41
+ gmap.linkAlpha(1, darts[i * 2], darts[i * 2 + 1])
42
+ gmap.linkAlpha(0, darts[i * 2 + 1], darts[(i * 2 + 2) % (num_vertices * 2)])
43
+ return darts
44
+
45
+ def make_regular_polygon(gmap, num_sides = 12, center=Point3(0,0,0), radius=1.0):
46
+ """Create a regular polygon in the GMap.
47
+ Args:
48
+ gmap (GMap): The GMap to which the polygon will be added.
49
+ num_sides (int): The number of sides of the polygon.
50
+ center (Point3): The center point of the polygon.
51
+ radius (float): The radius of the polygon.
52
+ Returns:
53
+ list of Dart: The list of darts created for the polygon.
54
+ """
55
+ # Example: Create a regular dodecagon (12-sided polygon)
56
+ angle_step = (2.0 * Point3.PI) / float(num_sides)
57
+
58
+ # Generate vertices for the dodecagon
59
+ dodecagon_vertices = [
60
+ center + radius * Point3(math.cos(i * angle_step), math.sin(i * angle_step), 0)
61
+ for i in range(num_sides)
62
+ ]
63
+
64
+ # Create the dodecagon using make_regular_polygon
65
+ make_polygon(gmap, dodecagon_vertices)
66
+
67
+
68
+
69
+
70
+ def collect(orbittab, gmap, dart, ebdname, defvalue):
71
+ # collect the darts of the orbit
72
+ orbit = Orbit(orbittab)(gmap, dart)
73
+ # collect the ebd of the darts
74
+ ebd = []
75
+ for i in range(len(orbit)):
76
+ ebd.append(gmap[orbit[i]].ebd.get(ebdname, defvalue))
77
+ return ebd
78
+
79
+ def collect0(orbittab, gmap, dart, ebdname, defvalue):
80
+ # collect the darts of the orbit
81
+ orbit = Orbit(orbittab)(gmap, dart)
82
+ # collect the ebd of the darts
83
+ ebd = []
84
+ for i in range(len(orbit)):
85
+ ebd.append(gmap[orbit[i]].ebd0.get(ebdname, defvalue))
86
+ return ebd
87
+
88
+ def collect1(orbittab, gmap, dart, ebdname, defvalue):
89
+ # collect the darts of the orbit
90
+ orbit = Orbit(orbittab)(gmap, dart)
91
+ # collect the ebd of the darts
92
+ ebd = []
93
+ for i in range(len(orbit)):
94
+ ebd.append(gmap[orbit[i]].ebd1.get(ebdname, defvalue))
95
+ return ebd
96
+
97
+ def collect2(orbittab, gmap, dart, ebdname, defvalue):
98
+ # collect the darts of the orbit
99
+ orbit = Orbit(orbittab)(gmap, dart)
100
+ # collect the ebd of the darts
101
+ ebd = []
102
+ for i in range(len(orbit)):
103
+ ebd.append(gmap[orbit[i]].ebd2.get(ebdname, defvalue))
104
+ return ebd
105
+
106
+ def collect3(orbittab, gmap, dart, ebdname, defvalue):
107
+ # collect the darts of the orbit
108
+ orbit = Orbit(orbittab)(gmap, dart)
109
+ # collect the ebd of the darts
110
+ ebd = []
111
+ for i in range(len(orbit)):
112
+ ebd.append(gmap[orbit[i]].ebd3.get(ebdname, defvalue))
113
+ return ebd
114
+
115
+
116
+ def collect01(orbittab, gmap, dart, ebdname, defvalue):
117
+ # collect the darts of the orbit
118
+ orbit = Orbit(orbittab)(gmap, dart)
119
+ # collect the ebd of the darts
120
+ ebd = []
121
+ for i in range(len(orbit)):
122
+ ebd.append(gmap[orbit[i]].ebd01.get(ebdname, defvalue))
123
+ return ebd
124
+
125
+ def collect02(orbittab, gmap, dart, ebdname, defvalue):
126
+ # collect the darts of the orbit
127
+ orbit = Orbit(orbittab)(gmap, dart)
128
+ # collect the ebd of the darts
129
+ ebd = []
130
+ for i in range(len(orbit)):
131
+ ebd.append(gmap[orbit[i]].ebd02.get(ebdname, defvalue))
132
+ return ebd
133
+
134
+ def collect03(orbittab, gmap, dart, ebdname, defvalue):
135
+ # collect the darts of the orbit
136
+ orbit = Orbit(orbittab)(gmap, dart)
137
+ # collect the ebd of the darts
138
+ ebd = []
139
+ for i in range(len(orbit)):
140
+ ebd.append(gmap[orbit[i]].ebd03.get(ebdname, defvalue))
141
+ return ebd
142
+
143
+ def collect12(orbittab, gmap, dart, ebdname, defvalue):
144
+ # collect the darts of the orbit
145
+ orbit = Orbit(orbittab)(gmap, dart)
146
+ # collect the ebd of the darts
147
+ ebd = []
148
+ for i in range(len(orbit)):
149
+ ebd.append(gmap[orbit[i]].ebd12.get(ebdname, defvalue))
150
+ return ebd
151
+
152
+ def collect13(orbittab, gmap, dart, ebdname, defvalue):
153
+ # collect the darts of the orbit
154
+ orbit = Orbit(orbittab)(gmap, dart)
155
+ # collect the ebd of the darts
156
+ ebd = []
157
+ for i in range(len(orbit)):
158
+ ebd.append(gmap[orbit[i]].ebd13.get(ebdname, defvalue))
159
+ return ebd
160
+
161
+ def collect23(orbittab, gmap, dart, ebdname, defvalue):
162
+ # collect the darts of the orbit
163
+ orbit = Orbit(orbittab)(gmap, dart)
164
+ # collect the ebd of the darts
165
+ ebd = []
166
+ for i in range(len(orbit)):
167
+ ebd.append(gmap[orbit[i]].ebd23.get(ebdname, defvalue))
168
+ return ebd
169
+
170
+ def collect012(orbittab, gmap, dart, ebdname, defvalue):
171
+ # collect the darts of the orbit
172
+ orbit = Orbit(orbittab)(gmap, dart)
173
+ # collect the ebd of the darts
174
+ ebd = []
175
+ for i in range(len(orbit)):
176
+ ebd.append(gmap[orbit[i]].ebd012.get(ebdname, defvalue))
177
+ return ebd
178
+
179
+ def collect013(orbittab, gmap, dart, ebdname, defvalue):
180
+ # collect the darts of the orbit
181
+ orbit = Orbit(orbittab)(gmap, dart)
182
+ # collect the ebd of the darts
183
+ ebd = []
184
+ for i in range(len(orbit)):
185
+ ebd.append(gmap[orbit[i]].ebd013.get(ebdname, defvalue))
186
+ return ebd
187
+
188
+ def collect023(orbittab, gmap, dart, ebdname, defvalue):
189
+ # collect the darts of the orbit
190
+ orbit = Orbit(orbittab)(gmap, dart)
191
+ # collect the ebd of the darts
192
+ ebd = []
193
+ for i in range(len(orbit)):
194
+ ebd.append(gmap[orbit[i]].ebd023.get(ebdname, defvalue))
195
+ return ebd
196
+
197
+ def collect123(orbittab, gmap, dart, ebdname, defvalue):
198
+ # collect the darts of the orbit
199
+ orbit = Orbit(orbittab)(gmap, dart)
200
+ # collect the ebd of the darts
201
+ ebd = []
202
+ for i in range(len(orbit)):
203
+ ebd.append(gmap[orbit[i]].ebd123.get(ebdname, defvalue))
204
+ return ebd
205
+
206
+ def collect0123(orbittab, gmap, dart, ebdname, defvalue):
207
+ # collect the darts of the orbit
208
+ orbit = Orbit(orbittab)(gmap, dart)
209
+ # collect the ebd of the darts
210
+ ebd = []
211
+ for i in range(len(orbit)):
212
+ ebd.append(gmap[orbit[i]].ebd0123.get(ebdname, defvalue))
213
+ return ebd
214
+