topologicpy 0.4.8__py3-none-any.whl → 0.4.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 (79) hide show
  1. topologicpy/Aperture.py +46 -0
  2. topologicpy/Cell.py +1780 -0
  3. topologicpy/CellComplex.py +791 -0
  4. topologicpy/Cluster.py +591 -0
  5. topologicpy/Color.py +157 -0
  6. topologicpy/Context.py +56 -0
  7. topologicpy/DGL.py +2661 -0
  8. topologicpy/Dictionary.py +470 -0
  9. topologicpy/Edge.py +855 -0
  10. topologicpy/EnergyModel.py +1052 -0
  11. topologicpy/Face.py +1810 -0
  12. topologicpy/Graph.py +3526 -0
  13. topologicpy/Graph_Export.py +858 -0
  14. topologicpy/Grid.py +338 -0
  15. topologicpy/Helper.py +182 -0
  16. topologicpy/Honeybee.py +424 -0
  17. topologicpy/Matrix.py +255 -0
  18. topologicpy/Neo4jGraph.py +311 -0
  19. topologicpy/Plotly.py +1396 -0
  20. topologicpy/Polyskel.py +524 -0
  21. topologicpy/Process.py +1368 -0
  22. topologicpy/SQL.py +48 -0
  23. topologicpy/Shell.py +1418 -0
  24. topologicpy/Speckle.py +433 -0
  25. topologicpy/Topology.py +5854 -0
  26. topologicpy/UnitTest.py +29 -0
  27. topologicpy/Vector.py +555 -0
  28. topologicpy/Vertex.py +714 -0
  29. topologicpy/Wire.py +2346 -0
  30. topologicpy/__init__.py +20 -0
  31. topologicpy/bin/linux/topologic/__init__.py +2 -0
  32. topologicpy/bin/linux/topologic/topologic.cpython-310-x86_64-linux-gnu.so +0 -0
  33. topologicpy/bin/linux/topologic/topologic.cpython-311-x86_64-linux-gnu.so +0 -0
  34. topologicpy/bin/linux/topologic/topologic.cpython-38-x86_64-linux-gnu.so +0 -0
  35. topologicpy/bin/linux/topologic/topologic.cpython-39-x86_64-linux-gnu.so +0 -0
  36. topologicpy/bin/linux/topologic.libs/libTKBO-6bdf205d.so.7.7.0 +0 -0
  37. topologicpy/bin/linux/topologic.libs/libTKBRep-2960a069.so.7.7.0 +0 -0
  38. topologicpy/bin/linux/topologic.libs/libTKBool-c44b74bd.so.7.7.0 +0 -0
  39. topologicpy/bin/linux/topologic.libs/libTKFillet-9a670ba0.so.7.7.0 +0 -0
  40. topologicpy/bin/linux/topologic.libs/libTKG2d-8f31849e.so.7.7.0 +0 -0
  41. topologicpy/bin/linux/topologic.libs/libTKG3d-4c6bce57.so.7.7.0 +0 -0
  42. topologicpy/bin/linux/topologic.libs/libTKGeomAlgo-26066fd9.so.7.7.0 +0 -0
  43. topologicpy/bin/linux/topologic.libs/libTKGeomBase-2116cabe.so.7.7.0 +0 -0
  44. topologicpy/bin/linux/topologic.libs/libTKMath-72572fa8.so.7.7.0 +0 -0
  45. topologicpy/bin/linux/topologic.libs/libTKMesh-2a060427.so.7.7.0 +0 -0
  46. topologicpy/bin/linux/topologic.libs/libTKOffset-6cab68ff.so.7.7.0 +0 -0
  47. topologicpy/bin/linux/topologic.libs/libTKPrim-eb1262b3.so.7.7.0 +0 -0
  48. topologicpy/bin/linux/topologic.libs/libTKShHealing-e67e5cc7.so.7.7.0 +0 -0
  49. topologicpy/bin/linux/topologic.libs/libTKTopAlgo-e4c96c33.so.7.7.0 +0 -0
  50. topologicpy/bin/linux/topologic.libs/libTKernel-fb7fe3b7.so.7.7.0 +0 -0
  51. topologicpy/bin/linux/topologic.libs/libgcc_s-32c1665e.so.1 +0 -0
  52. topologicpy/bin/linux/topologic.libs/libstdc++-672d7b41.so.6.0.30 +0 -0
  53. topologicpy/bin/windows/topologic/TKBO-f6b191de.dll +0 -0
  54. topologicpy/bin/windows/topologic/TKBRep-e56a600e.dll +0 -0
  55. topologicpy/bin/windows/topologic/TKBool-7b8d47ae.dll +0 -0
  56. topologicpy/bin/windows/topologic/TKFillet-0ddbf0a8.dll +0 -0
  57. topologicpy/bin/windows/topologic/TKG2d-2e2dee3d.dll +0 -0
  58. topologicpy/bin/windows/topologic/TKG3d-6674513d.dll +0 -0
  59. topologicpy/bin/windows/topologic/TKGeomAlgo-d240e370.dll +0 -0
  60. topologicpy/bin/windows/topologic/TKGeomBase-df87aba5.dll +0 -0
  61. topologicpy/bin/windows/topologic/TKMath-45bd625a.dll +0 -0
  62. topologicpy/bin/windows/topologic/TKMesh-d6e826b1.dll +0 -0
  63. topologicpy/bin/windows/topologic/TKOffset-79b9cc94.dll +0 -0
  64. topologicpy/bin/windows/topologic/TKPrim-aa430a86.dll +0 -0
  65. topologicpy/bin/windows/topologic/TKShHealing-bb48be89.dll +0 -0
  66. topologicpy/bin/windows/topologic/TKTopAlgo-7d0d1e22.dll +0 -0
  67. topologicpy/bin/windows/topologic/TKernel-08c8cfbb.dll +0 -0
  68. topologicpy/bin/windows/topologic/__init__.py +2 -0
  69. topologicpy/bin/windows/topologic/topologic.cp310-win_amd64.pyd +0 -0
  70. topologicpy/bin/windows/topologic/topologic.cp311-win_amd64.pyd +0 -0
  71. topologicpy/bin/windows/topologic/topologic.cp38-win_amd64.pyd +0 -0
  72. topologicpy/bin/windows/topologic/topologic.cp39-win_amd64.pyd +0 -0
  73. {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/METADATA +1 -1
  74. topologicpy-0.4.9.dist-info/RECORD +77 -0
  75. topologicpy-0.4.9.dist-info/top_level.txt +1 -0
  76. topologicpy-0.4.8.dist-info/RECORD +0 -5
  77. topologicpy-0.4.8.dist-info/top_level.txt +0 -1
  78. {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/LICENSE +0 -0
  79. {topologicpy-0.4.8.dist-info → topologicpy-0.4.9.dist-info}/WHEEL +0 -0
topologicpy/Grid.py ADDED
@@ -0,0 +1,338 @@
1
+ import topologicpy
2
+ import topologic
3
+
4
+
5
+ class Grid(topologic.Cluster):
6
+ @staticmethod
7
+ def EdgesByDistances(face=None, uOrigin=None, vOrigin=None, uRange=[-0.5,-0.25,0, 0.25,0.5], vRange=[-0.5,-0.25,0, 0.25,0.5], clip=False, tolerance=0.0001):
8
+ """
9
+ Creates a grid (cluster of edges).
10
+
11
+ Parameters
12
+ ----------
13
+ face : topologic.Face , optional
14
+ The input face. If set to None, the grid will be created on the XY plane. The default is None.
15
+ uOrigin : topologic.Vertex , optional
16
+ The origin of the *u* grid lines. If set to None: if the face is set, the uOrigin will be set to vertex at the face's 0,0 paratmer. If the face is set to None, the uOrigin will be set to the origin. The default is None.
17
+ vOrigin : topologic.Vertex , optional
18
+ The origin of the *v* grid lines. If set to None: if the face is set, the vOrigin will be set to vertex at the face's 0,0 paratmer. If the face is set to None, the vOrigin will be set to the origin. The default is None.
19
+ uRange : list , optional
20
+ A list of distances for the *u* grid lines from the uOrigin. The default is [-0.5,-0.25,0, 0.25,0.5].
21
+ vRange : list , optional
22
+ A list of distances for the *v* grid lines from the vOrigin. The default is [-0.5,-0.25,0, 0.25,0.5].
23
+ clip : bool , optional
24
+ If True the grid will be clipped by the shape of the input face. The default is False.
25
+ tolerance : float , optional
26
+ The desired tolerance. The default is 0.0001.
27
+
28
+ Returns
29
+ -------
30
+ topologic.Cluster
31
+ The created grid. Edges in the grid have an identifying dictionary with two keys: "dir" and "offset". The "dir" key can have one of two values: "u" or "v", the "offset" key contains the offset distance of that grid edge from the specified origin.
32
+
33
+ """
34
+ from topologicpy.Vertex import Vertex
35
+ from topologicpy.Edge import Edge
36
+ from topologicpy.Face import Face
37
+ from topologicpy.Cluster import Cluster
38
+ from topologicpy.Topology import Topology
39
+ from topologicpy.Dictionary import Dictionary
40
+ from topologicpy.Vector import Vector
41
+ if len(uRange) < 1 or len(vRange) < 1:
42
+ return None
43
+ if not uOrigin:
44
+ if not isinstance(face, topologic.Face):
45
+ uOrigin = Vertex.ByCoordinates(0,0,0)
46
+ else:
47
+ uOrigin = Face.VertexByParameters(face, 0, 0)
48
+ if not vOrigin:
49
+ if not isinstance(face, topologic.Face):
50
+ vOrigin = Vertex.ByCoordinates(0,0,0)
51
+ else:
52
+ vOrigin = Face.VertexByParameters(face, 0, 0)
53
+
54
+ if isinstance(face, topologic.Face):
55
+ v1 = Face.VertexByParameters(face, 0, 0)
56
+ v2 = Face.VertexByParameters(face, 1, 0)
57
+ v3 = Face.VertexByParameters(face, 0, 0)
58
+ v4 = Face.VertexByParameters(face, 0, 1)
59
+ else:
60
+ v1 = Vertex.ByCoordinates(0,0,0)
61
+ v2 = Vertex.ByCoordinates(max(uRange),0,0)
62
+ v3 = Vertex.ByCoordinates(0,0,0)
63
+ v4 = Vertex.ByCoordinates(0,max(vRange),0)
64
+
65
+ uVector = [v2.X()-v1.X(), v2.Y()-v1.Y(),v2.Z()-v1.Z()]
66
+ vVector = [v4.X()-v3.X(), v4.Y()-v3.Y(),v4.Z()-v3.Z()]
67
+ gridEdges = []
68
+ if len(uRange) > 0:
69
+ uRange.sort()
70
+ uuVector = Vector.Normalize(uVector)
71
+ for u in uRange:
72
+ tempVec = Vector.Multiply(uuVector, u, tolerance)
73
+ v1 = Vertex.ByCoordinates(uOrigin.X()+tempVec[0], uOrigin.Y()+tempVec[1], uOrigin.Z()+tempVec[2])
74
+ v2 = Vertex.ByCoordinates(v1.X()+vVector[0], v1.Y()+vVector[1], v1.Z()+vVector[2])
75
+ e = Edge.ByVertices([v1, v2])
76
+ if clip and isinstance(face, topologic.Face):
77
+ e = e.Intersect(face, False)
78
+ if e:
79
+ if isinstance(e, topologic.Edge):
80
+ d = Dictionary.ByKeysValues(["dir", "offset"],["u",u])
81
+ e.SetDictionary(d)
82
+ gridEdges.append(e)
83
+ elif e.Type() > topologic.Edge.Type():
84
+ tempEdges = []
85
+ _ = e.Edges(None, tempEdges)
86
+ for tempEdge in tempEdges:
87
+ d = Dictionary.ByKeysValues(["dir", "offset"],["u",u])
88
+ tempEdge.SetDictionary(d)
89
+ gridEdges.append(tempEdge)
90
+ if len(vRange) > 0:
91
+ vRange.sort()
92
+ uvVector = Vector.Normalize(vVector)
93
+ for v in vRange:
94
+ tempVec = Vector.Multiply(uvVector, v, tolerance)
95
+ v1 = Vertex.ByCoordinates(vOrigin.X()+tempVec[0], vOrigin.Y()+tempVec[1], vOrigin.Z()+tempVec[2])
96
+ v2 = Vertex.ByCoordinates(v1.X()+uVector[0], v1.Y()+uVector[1], v1.Z()+uVector[2])
97
+ e = Edge.ByVertices([v1, v2])
98
+ if clip and isinstance(face, topologic.Face):
99
+ e = e.Intersect(face, False)
100
+ if e:
101
+ if isinstance(e, topologic.Edge):
102
+ d = Dictionary.ByKeysValues(["dir", "offset"],["v",v])
103
+ e.SetDictionary(d)
104
+ gridEdges.append(e)
105
+ elif e.Type() > topologic.Edge.Type():
106
+ tempEdges = []
107
+ _ = e.Edges(None, tempEdges)
108
+ for tempEdge in tempEdges:
109
+ d = Dictionary.ByKeysValues(["dir", "offset"],["v",v])
110
+ tempEdge.SetDictionary(d)
111
+ gridEdges.append(tempEdge)
112
+ grid = None
113
+ if len(gridEdges) > 0:
114
+ grid = Cluster.ByTopologies(gridEdges)
115
+ return grid
116
+
117
+ @staticmethod
118
+ def EdgesByParameters(face, uRange=[0,0.25,0.5,0.75,1.0], vRange=[0,0.25,0.5,0.75,1.0], clip=False):
119
+ """
120
+ Creates a grid (cluster of edges).
121
+
122
+ Parameters
123
+ ----------
124
+ face : topologic.Face
125
+ The input face.
126
+ uRange : list , optional
127
+ A list of *u* parameters for the *u* grid lines. The default is [0,0.25,0.5, 0.75, 1.0].
128
+ vRange : list , optional
129
+ A list of *v* parameters for the *v* grid lines. The default is [0,0.25,0.5, 0.75, 1.0].
130
+ clip : bool , optional
131
+ If True the grid will be clipped by the shape of the input face. The default is False.
132
+
133
+ Returns
134
+ -------
135
+ topologic.Cluster
136
+ The created grid. Edges in the grid have an identifying dictionary with two keys: "dir" and "offset". The "dir" key can have one of two values: "u" or "v", the "offset" key contains the offset parameter of that grid edge.
137
+
138
+ """
139
+ from topologicpy.Vertex import Vertex
140
+ from topologicpy.Edge import Edge
141
+ from topologicpy.Face import Face
142
+ from topologicpy.Cluster import Cluster
143
+ from topologicpy.Dictionary import Dictionary
144
+
145
+ if not isinstance(face, topologic.Face):
146
+ return None
147
+ if len(uRange) < 1 and len(vRange) < 1:
148
+ return None
149
+ if len(uRange) > 0:
150
+ if (min(uRange) < 0) or (max(uRange) > 1):
151
+ return None
152
+ if len(vRange) > 0:
153
+ if (min(vRange) < 0) or (max(vRange) > 1):
154
+ return None
155
+
156
+ uRange.sort()
157
+ vRange.sort()
158
+ gridEdges = []
159
+ for u in uRange:
160
+ v1 = Face.VertexByParameters(face, u, 0)
161
+ v2 = Face.VertexByParameters(face, u, 1)
162
+ e = Edge.ByVertices([v1, v2])
163
+ if clip and isinstance(face, topologic.Face):
164
+ e = e.Intersect(face, False)
165
+ if e:
166
+ if isinstance(e, topologic.Edge):
167
+ d = Dictionary.ByKeysValues(["dir", "offset"],["u",u])
168
+ e.SetDictionary(d)
169
+ gridEdges.append(e)
170
+ elif e.Type() > topologic.Edge.Type():
171
+ tempEdges = []
172
+ _ = e.Edges(None, tempEdges)
173
+ for tempEdge in tempEdges:
174
+ d = Dictionary.ByKeysValues(["dir", "offset"],["u",u])
175
+ tempEdge.SetDictionary(d)
176
+ gridEdges.append(tempEdge)
177
+ for v in vRange:
178
+ v1 = Face.VertexByParameters(face, 0, v)
179
+ v2 = Face.VertexByParameters(face, 1, v)
180
+ e = Edge.ByVertices([v1, v2])
181
+ if clip and isinstance(face, topologic.Face):
182
+ e = e.Intersect(face, False)
183
+ if e:
184
+ if isinstance(e, topologic.Edge):
185
+ d = Dictionary.ByKeysValues(["dir", "offset"],["v",v])
186
+ e.SetDictionary(d)
187
+ gridEdges.append(e)
188
+ elif e.Type() > topologic.Edge.Type():
189
+ tempEdges = []
190
+ _ = e.Edges(None, tempEdges)
191
+ for tempEdge in tempEdges:
192
+ d = Dictionary.ByKeysValues(["dir", "offset"],["v",v])
193
+ tempEdge.SetDictionary(d)
194
+ gridEdges.append(tempEdge)
195
+ grid = None
196
+ if len(gridEdges) > 0:
197
+ grid = Cluster.ByTopologies(gridEdges)
198
+ return grid
199
+
200
+
201
+ @staticmethod
202
+ def VerticesByDistances(face=None, origin=None, uRange=[-0.5,-0.25,0, 0.25,0.5], vRange=[-0.5,-0.25,0,0.25,0.5], clip=False, tolerance=0.0001):
203
+ """
204
+ Creates a grid (cluster of vertices).
205
+
206
+ Parameters
207
+ ----------
208
+ face : topologic.Face , optional
209
+ The input face. If set to None, the grid will be created on the XY plane. The default is None.
210
+ origin : topologic.Vertex , optional
211
+ The origin of the grid vertices. If set to None: if the face is set, the origin will be set to vertex at the face's 0,0 paratmer. If the face is set to None, the origin will be set to (0,0,0). The default is None.
212
+ uRange : list , optional
213
+ A list of distances for the *u* grid lines from the uOrigin. The default is [-0.5,-0.25,0, 0.25,0.5].
214
+ vRange : list , optional
215
+ A list of distances for the *v* grid lines from the vOrigin. The default is [-0.5,-0.25,0, 0.25,0.5].
216
+ clip : bool , optional
217
+ If True the grid will be clipped by the shape of the input face. The default is False.
218
+ tolerance : float , optional
219
+ The desired tolerance. The default is 0.0001.
220
+
221
+ Returns
222
+ -------
223
+ topologic.Cluster
224
+ The created grid. Vertices in the grid have an identifying dictionary with two keys: "u" and "v". The "dir" key can have one of two values: "u" or "v" that contain the *u* and *v* offset distances of that grid vertex from the specified origin.
225
+
226
+ """
227
+ from topologicpy.Vertex import Vertex
228
+ from topologicpy.Edge import Edge
229
+ from topologicpy.Face import Face
230
+ from topologicpy.Cluster import Cluster
231
+ from topologicpy.Topology import Topology
232
+ from topologicpy.Dictionary import Dictionary
233
+ from topologicpy.Vector import Vector
234
+ if len(uRange) < 1 or len(vRange) < 1:
235
+ return None
236
+ if not origin:
237
+ if not isinstance(face, topologic.Face):
238
+ origin = Vertex.ByCoordinates(0,0,0)
239
+ else:
240
+ origin = Face.VertexByParameters(face, 0, 0)
241
+
242
+ if isinstance(face, topologic.Face):
243
+ v1 = Face.VertexByParameters(face, 0, 0)
244
+ v2 = Face.VertexByParameters(face, 1, 0)
245
+ v3 = Face.VertexByParameters(face, 0, 0)
246
+ v4 = Face.VertexByParameters(face, 0, 1)
247
+ else:
248
+ v1 = Vertex.ByCoordinates(0,0,0)
249
+ v2 = Vertex.ByCoordinates(max(uRange),0,0)
250
+ v3 = Vertex.ByCoordinates(0,0,0)
251
+ v4 = Vertex.ByCoordinates(0,max(vRange),0)
252
+
253
+ uVector = [v2.X()-v1.X(), v2.Y()-v1.Y(),v2.Z()-v1.Z()]
254
+ vVector = [v4.X()-v3.X(), v4.Y()-v3.Y(),v4.Z()-v3.Z()]
255
+ gridVertices = []
256
+ if len(uRange) > 0:
257
+ uRange.sort()
258
+ uuVector = Vector.Normalize(uVector)
259
+ uvVector = Vector.Normalize(vVector)
260
+ for u in uRange:
261
+ for v in vRange:
262
+ uTempVec = Vector.Multiply(uuVector, u, tolerance)
263
+ vTempVec = Vector.Multiply(uvVector, v, tolerance)
264
+ gridVertex = Vertex.ByCoordinates(origin.X()+uTempVec[0], origin.Y()+vTempVec[1], origin.Z()+uTempVec[2])
265
+ if clip and isinstance(face, topologic.Face):
266
+ gridVertex = gridVertex.Intersect(face, False)
267
+ if isinstance(gridVertex, topologic.Vertex):
268
+ d = Dictionary.ByKeysValues(["u","v"],[u,v])
269
+ if d:
270
+ gridVertex.SetDictionary(d)
271
+ gridVertices.append(gridVertex)
272
+ grid = None
273
+ if len(gridVertices) > 0:
274
+ grid = Cluster.ByTopologies(gridVertices)
275
+ return grid
276
+
277
+ @staticmethod
278
+ def VerticesByParameters(face=None, uRange=[0.0,0.25,0.5,0.75,1.0], vRange=[0.0,0.25,0.5,0.75,1.0], clip=False, tolerance=0.0001):
279
+ """
280
+ Creates a grid (cluster of vertices).
281
+
282
+ Parameters
283
+ ----------
284
+ face : topologic.Face , optional
285
+ The input face. If set to None, the grid will be created on the XY plane. The default is None.
286
+ origin : topologic.Vertex , optional
287
+ The origin of the grid vertices. If set to None: if the face is set, the origin will be set to vertex at the face's 0,0 paratmer. If the face is set to None, the origin will be set to (0,0,0). The default is None.
288
+ uRange : list , optional
289
+ A list of *u* parameters for the *u* grid lines from the uOrigin. The default is [0.0,0.25,0.5,0.75,1.0].
290
+ vRange : list , optional
291
+ A list of *v* parameters for the *v* grid lines from the vOrigin. The default is [0.0,0.25,0.5,0.75,1.0].
292
+ clip : bool , optional
293
+ If True the grid will be clipped by the shape of the input face. The default is False.
294
+ tolerance : float , optional
295
+ The desired tolerance. The default is 0.0001.
296
+
297
+ Returns
298
+ -------
299
+ topologic.Cluster
300
+ The created grid. Vertices in the grid have an identifying dictionary with two keys: "u" and "v". The "dir" key can have one of two values: "u" or "v" that contain the *u* and *v* offset distances of that grid vertex from the specified origin.
301
+
302
+ """
303
+ from topologicpy.Vertex import Vertex
304
+ from topologicpy.Edge import Edge
305
+ from topologicpy.Face import Face
306
+ from topologicpy.Cluster import Cluster
307
+ from topologicpy.Topology import Topology
308
+ from topologicpy.Dictionary import Dictionary
309
+ from topologicpy.Vector import Vector
310
+
311
+ if not isinstance(face, topologic.Face):
312
+ return None
313
+ if len(uRange) < 1 or len(vRange) < 1:
314
+ return None
315
+ if (min(uRange) < 0) or (max(uRange) > 1):
316
+ return None
317
+ if (min(vRange) < 0) or (max(vRange) > 1):
318
+ return None
319
+
320
+ uRange.sort()
321
+ vRange.sort()
322
+ gridVertices = []
323
+ if len(uRange) > 0:
324
+ uRange.sort()
325
+ for u in uRange:
326
+ for v in vRange:
327
+ gridVertex = Vertex.ByParameter(face, u, v)
328
+ if clip and isinstance(face, topologic.Face):
329
+ gridVertex = gridVertex.Intersect(face, False)
330
+ if isinstance(gridVertex, topologic.Vertex):
331
+ d = Dictionary.ByKeysValues(["u","v"],[u,v])
332
+ if d:
333
+ gridVertex.SetDictionary(d)
334
+ gridVertices.append(gridVertex)
335
+ grid = None
336
+ if len(gridVertices) > 0:
337
+ grid = Cluster.ByTopologies(gridVertices)
338
+ return grid
topologicpy/Helper.py ADDED
@@ -0,0 +1,182 @@
1
+ import topologicpy
2
+ import numpy as np
3
+ import numpy.linalg as la
4
+ import math
5
+
6
+ class Helper:
7
+ @staticmethod
8
+ def Flatten(l):
9
+ """
10
+ Flattens the input nested list.
11
+
12
+ Parameters
13
+ ----------
14
+ l : list
15
+ The input nested list.
16
+
17
+ Returns
18
+ -------
19
+ list
20
+ The flattened list.
21
+
22
+ """
23
+
24
+ if not isinstance(l, list):
25
+ return [l]
26
+ flat_list = []
27
+ for item in l:
28
+ flat_list = flat_list + Helper.Flatten(item)
29
+ return flat_list
30
+
31
+ @staticmethod
32
+ def Iterate(l):
33
+ """
34
+ Iterates the input nested list so that each sublist has the same number of members. To fill extra members, the shorter lists are iterated from their first member.
35
+ For example Iterate([[1,2,3],['m','n','o','p'],['a','b','c','d','e']]) yields [[1, 2, 3, 1, 2], ['m', 'n', 'o', 'p', 'm'], ['a', 'b', 'c', 'd', 'e']]
36
+
37
+ Parameters
38
+ ----------
39
+ l : list
40
+ The input nested list.
41
+
42
+ Returns
43
+ -------
44
+ list
45
+ The iterated list.
46
+
47
+ """
48
+ # From https://stackoverflow.com/questions/34432056/repeat-elements-of-list-between-each-other-until-we-reach-a-certain-length
49
+ def onestep(cur,y,base):
50
+ # one step of the iteration
51
+ if cur is not None:
52
+ y.append(cur)
53
+ base.append(cur)
54
+ else:
55
+ y.append(base[0]) # append is simplest, for now
56
+ base = base[1:]+[base[0]] # rotate
57
+ return base
58
+
59
+ maxLength = len(l[0])
60
+ iterated_list = []
61
+ for aSubList in l:
62
+ newLength = len(aSubList)
63
+ if newLength > maxLength:
64
+ maxLength = newLength
65
+ for anItem in l:
66
+ for i in range(len(anItem), maxLength):
67
+ anItem.append(None)
68
+ y=[]
69
+ base=[]
70
+ for cur in anItem:
71
+ base = onestep(cur,y,base)
72
+ iterated_list.append(y)
73
+ return iterated_list
74
+
75
+ @staticmethod
76
+ def Repeat(l):
77
+ """
78
+ Repeats the input nested list so that each sublist has the same number of members. To fill extra members, the last item in the shorter lists are repeated and appended.
79
+ For example Iterate([[1,2,3],['m','n','o','p'],['a','b','c','d','e']]) yields [[1, 2, 3, 3, 3], ['m', 'n', 'o', 'p', 'p'], ['a', 'b', 'c', 'd', 'e']]
80
+
81
+ Parameters
82
+ ----------
83
+ l : list
84
+ The input nested list.
85
+
86
+ Returns
87
+ -------
88
+ list
89
+ The repeated list.
90
+
91
+ """
92
+ if not isinstance(l, list):
93
+ return None
94
+ repeated_list = [x for x in l if isinstance(x, list)]
95
+ if len(repeated_list) < 1:
96
+ return None
97
+ maxLength = len(repeated_list[0])
98
+ for aSubList in repeated_list:
99
+ newLength = len(aSubList)
100
+ if newLength > maxLength:
101
+ maxLength = newLength
102
+ for anItem in repeated_list:
103
+ if (len(anItem) > 0):
104
+ itemToAppend = anItem[-1]
105
+ else:
106
+ itemToAppend = None
107
+ for i in range(len(anItem), maxLength):
108
+ anItem.append(itemToAppend)
109
+ return repeated_list
110
+
111
+ @staticmethod
112
+ def Transpose(l):
113
+ """
114
+ Transposes (swaps rows and columns) the input list.
115
+
116
+ Parameters
117
+ ----------
118
+ l : list
119
+ The input list.
120
+
121
+ Returns
122
+ -------
123
+ list
124
+ The transposed list.
125
+
126
+ """
127
+ if not isinstance(l, list):
128
+ return None
129
+ length = len(l[0])
130
+ transposed_list = []
131
+ for i in range(length):
132
+ tempRow = []
133
+ for j in range(len(l)):
134
+ tempRow.append(l[j][i])
135
+ transposed_list.append(tempRow)
136
+ return transposed_list
137
+
138
+ @staticmethod
139
+ def Trim(l):
140
+ """
141
+ Trims the input nested list so that each sublist has the same number of members. All lists are trimmed to match the length of the shortest list.
142
+ For example Trim([[1,2,3],['m','n','o','p'],['a','b','c','d','e']]) yields [[1, 2, 3], ['m', 'n', 'o'], ['a', 'b', 'c']]
143
+
144
+ Parameters
145
+ ----------
146
+ l : list
147
+ The input nested list.
148
+
149
+ Returns
150
+ -------
151
+ list
152
+ The repeated list.
153
+
154
+ """
155
+ minLength = len(l[0])
156
+ returnList = []
157
+ for aSubList in l:
158
+ newLength = len(aSubList)
159
+ if newLength < minLength:
160
+ minLength = newLength
161
+ for anItem in l:
162
+ anItem = anItem[:minLength]
163
+ returnList.append(anItem)
164
+ return returnList
165
+
166
+ @staticmethod
167
+ def Version():
168
+ """
169
+ Returns the current version of the software.
170
+
171
+ Parameters
172
+ ----------
173
+ None
174
+
175
+
176
+ Returns
177
+ -------
178
+ str
179
+ The current version of the software.
180
+
181
+ """
182
+ return topologicpy.__version__