38
38
from typing_extensions import Self
39
39
40
40
from manim .typing import (
41
- ManimFloat ,
42
41
Point3D ,
43
42
Point3D_Array ,
44
43
Point3DLike ,
@@ -122,39 +121,45 @@ def get_vertices(self) -> Point3D_Array:
122
121
"""
123
122
return self .get_start_anchors ()
124
123
125
- def get_vertex_groups (self ) -> npt . NDArray [ ManimFloat ]:
124
+ def get_vertex_groups (self ) -> list [ Point3D_Array ]:
126
125
"""Gets the vertex groups of the :class:`Polygram`.
127
126
128
127
Returns
129
128
-------
130
- :class:`numpy.ndarray`
131
- The vertex groups of the :class:`Polygram`.
129
+ list[Point3D_Array]
130
+ The list of vertex groups of the :class:`Polygram`.
132
131
133
132
Examples
134
133
--------
135
134
::
136
135
137
- >>> poly = Polygram([ORIGIN, RIGHT, UP], [LEFT, LEFT + UP, 2 * LEFT])
138
- >>> poly.get_vertex_groups()
139
- array([[[ 0., 0., 0.],
140
- [ 1., 0., 0.],
141
- [ 0., 1., 0.]],
142
- <BLANKLINE>
143
- [[-1., 0., 0.],
144
- [-1., 1., 0.],
145
- [-2., 0., 0.]]])
136
+ >>> poly = Polygram([ORIGIN, RIGHT, UP, LEFT + UP], [LEFT, LEFT + UP, 2 * LEFT])
137
+ >>> groups = poly.get_vertex_groups()
138
+ >>> len(groups)
139
+ 2
140
+ >>> groups[0]
141
+ array([[ 0., 0., 0.],
142
+ [ 1., 0., 0.],
143
+ [ 0., 1., 0.],
144
+ [-1., 1., 0.]])
145
+ >>> groups[1]
146
+ array([[-1., 0., 0.],
147
+ [-1., 1., 0.],
148
+ [-2., 0., 0.]])
146
149
"""
147
150
vertex_groups = []
148
151
152
+ # TODO: If any of the original vertex groups contained the starting vertex N
153
+ # times, then .get_vertex_groups() splits it into N vertex groups.
149
154
group = []
150
155
for start , end in zip (self .get_start_anchors (), self .get_end_anchors ()):
151
156
group .append (start )
152
157
153
158
if self .consider_points_equals (end , group [0 ]):
154
- vertex_groups .append (group )
159
+ vertex_groups .append (np . array ( group ) )
155
160
group = []
156
161
157
- return np . array ( vertex_groups )
162
+ return vertex_groups
158
163
159
164
def round_corners (
160
165
self ,
@@ -223,18 +228,18 @@ def construct(self):
223
228
224
229
new_points : list [Point3D ] = []
225
230
226
- for vertices in self .get_vertex_groups ():
231
+ for vertex_group in self .get_vertex_groups ():
227
232
arcs = []
228
233
229
234
# Repeat the radius list as necessary in order to provide a radius
230
235
# for each vertex.
231
236
if isinstance (radius , (int , float )):
232
- radius_list = [radius ] * len (vertices )
237
+ radius_list = [radius ] * len (vertex_group )
233
238
else :
234
- radius_list = radius * ceil (len (vertices ) / len (radius ))
239
+ radius_list = radius * ceil (len (vertex_group ) / len (radius ))
235
240
236
- for currentRadius , (v1 , v2 , v3 ) in zip (
237
- radius_list , adjacent_n_tuples (vertices , 3 )
241
+ for current_radius , (v1 , v2 , v3 ) in zip (
242
+ radius_list , adjacent_n_tuples (vertex_group , 3 )
238
243
):
239
244
vect1 = v2 - v1
240
245
vect2 = v3 - v2
@@ -243,10 +248,10 @@ def construct(self):
243
248
244
249
angle = angle_between_vectors (vect1 , vect2 )
245
250
# Negative radius gives concave curves
246
- angle *= np .sign (currentRadius )
251
+ angle *= np .sign (current_radius )
247
252
248
253
# Distance between vertex and start of the arc
249
- cut_off_length = currentRadius * np .tan (angle / 2 )
254
+ cut_off_length = current_radius * np .tan (angle / 2 )
250
255
251
256
# Determines counterclockwise vs. clockwise
252
257
sign = np .sign (np .cross (vect1 , vect2 )[2 ])
@@ -261,17 +266,17 @@ def construct(self):
261
266
262
267
if evenly_distribute_anchors :
263
268
# Determine the average length of each curve
264
- nonZeroLengthArcs = [arc for arc in arcs if len (arc .points ) > 4 ]
265
- if len (nonZeroLengthArcs ) :
266
- totalArcLength = sum (
267
- [arc .get_arc_length () for arc in nonZeroLengthArcs ]
269
+ nonzero_length_arcs = [arc for arc in arcs if len (arc .points ) > 4 ]
270
+ if len (nonzero_length_arcs ) > 0 :
271
+ total_arc_length = sum (
272
+ [arc .get_arc_length () for arc in nonzero_length_arcs ]
268
273
)
269
- totalCurveCount = (
270
- sum ([len (arc .points ) for arc in nonZeroLengthArcs ]) / 4
274
+ num_curves = (
275
+ sum ([len (arc .points ) for arc in nonzero_length_arcs ]) / 4
271
276
)
272
- averageLengthPerCurve = totalArcLength / totalCurveCount
277
+ average_arc_length = total_arc_length / num_curves
273
278
else :
274
- averageLengthPerCurve = 1
279
+ average_arc_length = 1.0
275
280
276
281
# To ensure that we loop through starting with last
277
282
arcs = [arcs [- 1 ], * arcs [:- 1 ]]
@@ -284,9 +289,7 @@ def construct(self):
284
289
285
290
# Make sure anchors are evenly distributed, if necessary
286
291
if evenly_distribute_anchors :
287
- line .insert_n_curves (
288
- ceil (line .get_length () / averageLengthPerCurve )
289
- )
292
+ line .insert_n_curves (ceil (line .get_length () / average_arc_length ))
290
293
291
294
new_points .extend (line .points )
292
295
0 commit comments