manim 0.17.0__py3-none-any.whl → 0.19.1__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 (163) hide show
  1. manim/__init__.py +11 -6
  2. manim/__main__.py +62 -19
  3. manim/_config/__init__.py +10 -9
  4. manim/_config/cli_colors.py +26 -9
  5. manim/_config/default.cfg +1 -3
  6. manim/_config/logger_utils.py +23 -13
  7. manim/_config/utils.py +662 -468
  8. manim/animation/animation.py +164 -18
  9. manim/animation/changing.py +34 -23
  10. manim/animation/composition.py +265 -67
  11. manim/animation/creation.py +208 -26
  12. manim/animation/fading.py +16 -18
  13. manim/animation/growing.py +35 -15
  14. manim/animation/indication.py +150 -76
  15. manim/animation/movement.py +56 -22
  16. manim/animation/numbers.py +64 -6
  17. manim/animation/rotation.py +78 -7
  18. manim/animation/specialized.py +6 -7
  19. manim/animation/speedmodifier.py +13 -10
  20. manim/animation/transform.py +14 -11
  21. manim/animation/transform_matching_parts.py +3 -4
  22. manim/animation/updaters/mobject_update_utils.py +152 -30
  23. manim/animation/updaters/update.py +10 -7
  24. manim/camera/camera.py +182 -118
  25. manim/camera/mapping_camera.py +34 -3
  26. manim/camera/moving_camera.py +95 -74
  27. manim/camera/multi_camera.py +23 -15
  28. manim/camera/three_d_camera.py +70 -52
  29. manim/cli/__init__.py +17 -0
  30. manim/cli/cfg/group.py +76 -44
  31. manim/cli/checkhealth/checks.py +192 -0
  32. manim/cli/checkhealth/commands.py +90 -0
  33. manim/cli/default_group.py +158 -25
  34. manim/cli/init/commands.py +33 -25
  35. manim/cli/plugins/commands.py +16 -3
  36. manim/cli/render/commands.py +72 -60
  37. manim/cli/render/ease_of_access_options.py +4 -3
  38. manim/cli/render/global_options.py +59 -17
  39. manim/cli/render/output_options.py +6 -5
  40. manim/cli/render/render_options.py +98 -33
  41. manim/constants.py +109 -59
  42. manim/data_structures.py +31 -0
  43. manim/mobject/frame.py +8 -5
  44. manim/mobject/geometry/__init__.py +1 -0
  45. manim/mobject/geometry/arc.py +277 -135
  46. manim/mobject/geometry/boolean_ops.py +32 -31
  47. manim/mobject/geometry/labeled.py +376 -0
  48. manim/mobject/geometry/line.py +192 -87
  49. manim/mobject/geometry/polygram.py +224 -58
  50. manim/mobject/geometry/shape_matchers.py +61 -25
  51. manim/mobject/geometry/tips.py +122 -48
  52. manim/mobject/graph.py +1027 -419
  53. manim/mobject/graphing/coordinate_systems.py +533 -278
  54. manim/mobject/graphing/functions.py +53 -32
  55. manim/mobject/graphing/number_line.py +123 -65
  56. manim/mobject/graphing/probability.py +88 -62
  57. manim/mobject/graphing/scale.py +33 -19
  58. manim/mobject/logo.py +118 -28
  59. manim/mobject/matrix.py +87 -83
  60. manim/mobject/mobject.py +912 -442
  61. manim/mobject/opengl/dot_cloud.py +16 -5
  62. manim/mobject/opengl/opengl_compatibility.py +4 -2
  63. manim/mobject/opengl/opengl_geometry.py +254 -153
  64. manim/mobject/opengl/opengl_image_mobject.py +3 -1
  65. manim/mobject/opengl/opengl_mobject.py +779 -482
  66. manim/mobject/opengl/opengl_point_cloud_mobject.py +41 -14
  67. manim/mobject/opengl/opengl_surface.py +14 -92
  68. manim/mobject/opengl/opengl_three_dimensions.py +12 -8
  69. manim/mobject/opengl/opengl_vectorized_mobject.py +98 -100
  70. manim/mobject/svg/brace.py +173 -41
  71. manim/mobject/svg/svg_mobject.py +139 -53
  72. manim/mobject/table.py +61 -68
  73. manim/mobject/text/code_mobject.py +193 -539
  74. manim/mobject/text/numbers.py +81 -34
  75. manim/mobject/text/tex_mobject.py +130 -78
  76. manim/mobject/text/text_mobject.py +288 -164
  77. manim/mobject/three_d/polyhedra.py +111 -13
  78. manim/mobject/three_d/three_d_utils.py +17 -8
  79. manim/mobject/three_d/three_dimensions.py +239 -106
  80. manim/mobject/types/image_mobject.py +50 -30
  81. manim/mobject/types/point_cloud_mobject.py +120 -75
  82. manim/mobject/types/vectorized_mobject.py +841 -408
  83. manim/mobject/value_tracker.py +105 -38
  84. manim/mobject/vector_field.py +50 -31
  85. manim/opengl/__init__.py +3 -3
  86. manim/plugins/__init__.py +14 -1
  87. manim/plugins/plugins_flags.py +10 -14
  88. manim/renderer/cairo_renderer.py +65 -50
  89. manim/renderer/opengl_renderer.py +89 -69
  90. manim/renderer/opengl_renderer_window.py +39 -18
  91. manim/renderer/shader.py +123 -87
  92. manim/renderer/shader_wrapper.py +44 -28
  93. manim/renderer/vectorized_mobject_rendering.py +38 -10
  94. manim/scene/moving_camera_scene.py +32 -3
  95. manim/scene/scene.py +507 -242
  96. manim/scene/scene_file_writer.py +371 -220
  97. manim/scene/section.py +20 -16
  98. manim/scene/three_d_scene.py +14 -22
  99. manim/scene/vector_space_scene.py +223 -129
  100. manim/scene/zoomed_scene.py +46 -41
  101. manim/typing.py +990 -0
  102. manim/utils/bezier.py +1823 -371
  103. manim/utils/caching.py +12 -5
  104. manim/utils/color/AS2700.py +236 -0
  105. manim/utils/color/BS381.py +318 -0
  106. manim/utils/color/DVIPSNAMES.py +96 -0
  107. manim/utils/color/SVGNAMES.py +179 -0
  108. manim/utils/color/X11.py +533 -0
  109. manim/utils/color/XKCD.py +952 -0
  110. manim/utils/color/__init__.py +61 -0
  111. manim/utils/color/core.py +1667 -0
  112. manim/utils/color/manim_colors.py +218 -0
  113. manim/utils/commands.py +48 -20
  114. manim/utils/config_ops.py +39 -19
  115. manim/utils/debug.py +8 -7
  116. manim/utils/deprecation.py +86 -39
  117. manim/utils/docbuild/__init__.py +17 -0
  118. manim/utils/docbuild/autoaliasattr_directive.py +236 -0
  119. manim/utils/docbuild/autocolor_directive.py +99 -0
  120. manim/utils/docbuild/manim_directive.py +94 -41
  121. manim/utils/docbuild/module_parsing.py +245 -0
  122. manim/utils/exceptions.py +6 -0
  123. manim/utils/family.py +5 -3
  124. manim/utils/family_ops.py +17 -4
  125. manim/utils/file_ops.py +27 -17
  126. manim/utils/hashing.py +55 -45
  127. manim/utils/images.py +13 -7
  128. manim/utils/ipython_magic.py +13 -7
  129. manim/utils/iterables.py +163 -120
  130. manim/utils/module_ops.py +66 -24
  131. manim/utils/opengl.py +77 -24
  132. manim/utils/parameter_parsing.py +32 -0
  133. manim/utils/paths.py +30 -33
  134. manim/utils/polylabel.py +235 -0
  135. manim/utils/qhull.py +218 -0
  136. manim/utils/rate_functions.py +98 -32
  137. manim/utils/simple_functions.py +25 -33
  138. manim/utils/sounds.py +7 -1
  139. manim/utils/space_ops.py +188 -115
  140. manim/utils/testing/__init__.py +17 -0
  141. manim/utils/testing/_frames_testers.py +13 -8
  142. manim/utils/testing/_show_diff.py +5 -3
  143. manim/utils/testing/_test_class_makers.py +34 -18
  144. manim/utils/testing/frames_comparison.py +37 -19
  145. manim/utils/tex.py +130 -198
  146. manim/utils/tex_file_writing.py +77 -47
  147. manim/utils/tex_templates.py +2 -1
  148. manim/utils/unit.py +6 -5
  149. {manim-0.17.0.dist-info → manim-0.19.1.dist-info}/METADATA +64 -65
  150. manim-0.19.1.dist-info/RECORD +220 -0
  151. {manim-0.17.0.dist-info → manim-0.19.1.dist-info}/WHEEL +1 -1
  152. manim-0.19.1.dist-info/entry_points.txt +3 -0
  153. {manim-0.17.0.dist-info → manim-0.19.1.dist-info/licenses}/LICENSE.community +1 -1
  154. manim/cli/new/group.py +0 -189
  155. manim/communitycolors.py +0 -9
  156. manim/gui/__init__.py +0 -0
  157. manim/gui/gui.py +0 -82
  158. manim/plugins/import_plugins.py +0 -43
  159. manim/utils/color.py +0 -552
  160. manim-0.17.0.dist-info/RECORD +0 -206
  161. manim-0.17.0.dist-info/entry_points.txt +0 -4
  162. /manim/cli/{new → checkhealth}/__init__.py +0 -0
  163. {manim-0.17.0.dist-info → manim-0.19.1.dist-info/licenses}/LICENSE +0 -0
@@ -1,14 +1,27 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from typing import Any, cast
4
+
3
5
  import numpy as np
6
+ from typing_extensions import Self
4
7
 
5
8
  from manim.constants import *
6
9
  from manim.mobject.mobject import Mobject
7
10
  from manim.mobject.opengl.opengl_vectorized_mobject import (
8
11
  OpenGLDashedVMobject,
12
+ OpenGLMobject,
9
13
  OpenGLVGroup,
10
14
  OpenGLVMobject,
11
15
  )
16
+ from manim.typing import (
17
+ Point3D,
18
+ Point3D_Array,
19
+ Point3DLike,
20
+ QuadraticSpline,
21
+ Vector2DLike,
22
+ Vector3D,
23
+ Vector3DLike,
24
+ )
12
25
  from manim.utils.color import *
13
26
  from manim.utils.iterables import adjacent_n_tuples, adjacent_pairs
14
27
  from manim.utils.simple_functions import clip
@@ -23,11 +36,36 @@ from manim.utils.space_ops import (
23
36
  )
24
37
 
25
38
  DEFAULT_DOT_RADIUS = 0.08
26
- DEFAULT_SMALL_DOT_RADIUS = 0.04
27
39
  DEFAULT_DASH_LENGTH = 0.05
28
40
  DEFAULT_ARROW_TIP_LENGTH = 0.35
29
41
  DEFAULT_ARROW_TIP_WIDTH = 0.35
30
42
 
43
+ __all__ = [
44
+ "OpenGLTipableVMobject",
45
+ "OpenGLArc",
46
+ "OpenGLArcBetweenPoints",
47
+ "OpenGLCurvedArrow",
48
+ "OpenGLCurvedDoubleArrow",
49
+ "OpenGLCircle",
50
+ "OpenGLDot",
51
+ "OpenGLEllipse",
52
+ "OpenGLAnnularSector",
53
+ "OpenGLSector",
54
+ "OpenGLAnnulus",
55
+ "OpenGLLine",
56
+ "OpenGLDashedLine",
57
+ "OpenGLTangentLine",
58
+ "OpenGLElbow",
59
+ "OpenGLArrow",
60
+ "OpenGLVector",
61
+ "OpenGLDoubleArrow",
62
+ "OpenGLCubicBezier",
63
+ "OpenGLPolygon",
64
+ "OpenGLRegularPolygon",
65
+ "OpenGLTriangle",
66
+ "OpenGLArrowTip",
67
+ ]
68
+
31
69
 
32
70
  class OpenGLTipableVMobject(OpenGLVMobject):
33
71
  """
@@ -52,17 +90,17 @@ class OpenGLTipableVMobject(OpenGLVMobject):
52
90
 
53
91
  def __init__(
54
92
  self,
55
- tip_length=DEFAULT_ARROW_TIP_LENGTH,
56
- normal_vector=OUT,
57
- tip_config={},
58
- **kwargs,
93
+ tip_length: float = DEFAULT_ARROW_TIP_LENGTH,
94
+ normal_vector: Vector3DLike = OUT,
95
+ tip_config: dict[str, Any] = {},
96
+ **kwargs: Any,
59
97
  ):
60
98
  self.tip_length = tip_length
61
99
  self.normal_vector = normal_vector
62
100
  self.tip_config = tip_config
63
101
  super().__init__(**kwargs)
64
102
 
65
- def add_tip(self, at_start=False, **kwargs):
103
+ def add_tip(self, at_start: bool = False, **kwargs: Any) -> Self:
66
104
  """
67
105
  Adds a tip to the TipableVMobject instance, recognising
68
106
  that the endpoints might need to be switched if it's
@@ -74,7 +112,7 @@ class OpenGLTipableVMobject(OpenGLVMobject):
74
112
  self.add(tip)
75
113
  return self
76
114
 
77
- def create_tip(self, at_start=False, **kwargs):
115
+ def create_tip(self, at_start: bool = False, **kwargs: Any) -> OpenGLArrowTip:
78
116
  """
79
117
  Stylises the tip, positions it spacially, and returns
80
118
  the newly instantiated tip to the caller.
@@ -83,7 +121,7 @@ class OpenGLTipableVMobject(OpenGLVMobject):
83
121
  self.position_tip(tip, at_start)
84
122
  return tip
85
123
 
86
- def get_unpositioned_tip(self, **kwargs):
124
+ def get_unpositioned_tip(self, **kwargs: Any) -> OpenGLArrowTip:
87
125
  """
88
126
  Returns a tip that has been stylistically configured,
89
127
  but has not yet been given a position in space.
@@ -93,7 +131,9 @@ class OpenGLTipableVMobject(OpenGLVMobject):
93
131
  config.update(kwargs)
94
132
  return OpenGLArrowTip(**config)
95
133
 
96
- def position_tip(self, tip, at_start=False):
134
+ def position_tip(
135
+ self, tip: OpenGLArrowTip, at_start: bool = False
136
+ ) -> OpenGLArrowTip:
97
137
  # Last two control points, defining both
98
138
  # the end, and the tangency direction
99
139
  if at_start:
@@ -106,7 +146,7 @@ class OpenGLTipableVMobject(OpenGLVMobject):
106
146
  tip.shift(anchor - tip.get_tip_point())
107
147
  return tip
108
148
 
109
- def reset_endpoints_based_on_tip(self, tip, at_start):
149
+ def reset_endpoints_based_on_tip(self, tip: OpenGLArrowTip, at_start: bool) -> Self:
110
150
  if self.get_length() == 0:
111
151
  # Zero length, put_start_and_end_on wouldn't
112
152
  # work
@@ -121,7 +161,7 @@ class OpenGLTipableVMobject(OpenGLVMobject):
121
161
  self.put_start_and_end_on(start, end)
122
162
  return self
123
163
 
124
- def asign_tip_attr(self, tip, at_start):
164
+ def asign_tip_attr(self, tip: OpenGLArrowTip, at_start: bool) -> Self:
125
165
  if at_start:
126
166
  self.start_tip = tip
127
167
  else:
@@ -129,14 +169,14 @@ class OpenGLTipableVMobject(OpenGLVMobject):
129
169
  return self
130
170
 
131
171
  # Checking for tips
132
- def has_tip(self):
172
+ def has_tip(self) -> bool:
133
173
  return hasattr(self, "tip") and self.tip in self
134
174
 
135
- def has_start_tip(self):
175
+ def has_start_tip(self) -> bool:
136
176
  return hasattr(self, "start_tip") and self.start_tip in self
137
177
 
138
178
  # Getters
139
- def pop_tips(self):
179
+ def pop_tips(self) -> OpenGLVGroup:
140
180
  start, end = self.get_start_and_end()
141
181
  result = OpenGLVGroup()
142
182
  if self.has_tip():
@@ -148,7 +188,7 @@ class OpenGLTipableVMobject(OpenGLVMobject):
148
188
  self.put_start_and_end_on(start, end)
149
189
  return result
150
190
 
151
- def get_tips(self):
191
+ def get_tips(self) -> OpenGLVGroup:
152
192
  """
153
193
  Returns a VGroup (collection of VMobjects) containing
154
194
  the TipableVMObject instance's tips.
@@ -160,60 +200,63 @@ class OpenGLTipableVMobject(OpenGLVMobject):
160
200
  result.add(self.start_tip)
161
201
  return result
162
202
 
163
- def get_tip(self):
203
+ def get_tip(self) -> OpenGLArrowTip:
164
204
  """Returns the TipableVMobject instance's (first) tip,
165
- otherwise throws an exception."""
205
+ otherwise throws an exception.
206
+ """
166
207
  tips = self.get_tips()
167
208
  if len(tips) == 0:
168
209
  raise Exception("tip not found")
169
210
  else:
170
- return tips[0]
211
+ rv = cast(OpenGLArrowTip, tips[0])
212
+ return rv
171
213
 
172
- def get_default_tip_length(self):
214
+ def get_default_tip_length(self) -> float:
173
215
  return self.tip_length
174
216
 
175
- def get_first_handle(self):
217
+ def get_first_handle(self) -> Point3D:
176
218
  return self.points[1]
177
219
 
178
- def get_last_handle(self):
220
+ def get_last_handle(self) -> Point3D:
179
221
  return self.points[-2]
180
222
 
181
- def get_end(self):
223
+ def get_end(self) -> Point3D:
182
224
  if self.has_tip():
183
225
  return self.tip.get_start()
184
226
  else:
185
227
  return super().get_end()
186
228
 
187
- def get_start(self):
229
+ def get_start(self) -> Point3D:
188
230
  if self.has_start_tip():
189
231
  return self.start_tip.get_start()
190
232
  else:
191
233
  return super().get_start()
192
234
 
193
- def get_length(self):
235
+ def get_length(self) -> float:
194
236
  start, end = self.get_start_and_end()
195
- return np.linalg.norm(start - end)
237
+ rv: float = np.linalg.norm(start - end)
238
+ return rv
196
239
 
197
240
 
198
241
  class OpenGLArc(OpenGLTipableVMobject):
199
242
  def __init__(
200
243
  self,
201
- start_angle=0,
202
- angle=TAU / 4,
203
- radius=1.0,
204
- n_components=8,
205
- arc_center=ORIGIN,
206
- **kwargs,
244
+ start_angle: float = 0,
245
+ angle: float = TAU / 4,
246
+ radius: float = 1.0,
247
+ n_components: int = 8,
248
+ arc_center: Point3DLike = ORIGIN,
249
+ **kwargs: Any,
207
250
  ):
208
251
  self.start_angle = start_angle
209
252
  self.angle = angle
210
253
  self.radius = radius
211
254
  self.n_components = n_components
212
255
  self.arc_center = arc_center
213
- super().__init__(self, **kwargs)
256
+ super().__init__(**kwargs)
214
257
  self.orientation = -1
215
258
 
216
- def init_points(self):
259
+ def init_points(self) -> None:
217
260
  self.set_points(
218
261
  OpenGLArc.create_quadratic_bezier_points(
219
262
  angle=self.angle,
@@ -226,7 +269,9 @@ class OpenGLArc(OpenGLTipableVMobject):
226
269
  self.shift(self.arc_center)
227
270
 
228
271
  @staticmethod
229
- def create_quadratic_bezier_points(angle, start_angle=0, n_components=8):
272
+ def create_quadratic_bezier_points(
273
+ angle: float, start_angle: float = 0, n_components: int = 8
274
+ ) -> QuadraticSpline:
230
275
  samples = np.array(
231
276
  [
232
277
  [np.cos(a), np.sin(a), 0]
@@ -246,7 +291,7 @@ class OpenGLArc(OpenGLTipableVMobject):
246
291
  points[2::3] = samples[2::2]
247
292
  return points
248
293
 
249
- def get_arc_center(self):
294
+ def get_arc_center(self) -> Point3D:
250
295
  """
251
296
  Looks at the normals to the first two
252
297
  anchors, and finds their intersection points
@@ -261,21 +306,29 @@ class OpenGLArc(OpenGLTipableVMobject):
261
306
  n2 = rotate_vector(t2, TAU / 4)
262
307
  return find_intersection(a1, n1, a2, n2)
263
308
 
264
- def get_start_angle(self):
309
+ def get_start_angle(self) -> float:
265
310
  angle = angle_of_vector(self.get_start() - self.get_arc_center())
266
- return angle % TAU
311
+ rv: float = angle % TAU
312
+ return rv
267
313
 
268
- def get_stop_angle(self):
314
+ def get_stop_angle(self) -> float:
269
315
  angle = angle_of_vector(self.get_end() - self.get_arc_center())
270
- return angle % TAU
316
+ rv: float = angle % TAU
317
+ return rv
271
318
 
272
- def move_arc_center_to(self, point):
319
+ def move_arc_center_to(self, point: Point3DLike) -> Self:
273
320
  self.shift(point - self.get_arc_center())
274
321
  return self
275
322
 
276
323
 
277
324
  class OpenGLArcBetweenPoints(OpenGLArc):
278
- def __init__(self, start, end, angle=TAU / 4, **kwargs):
325
+ def __init__(
326
+ self,
327
+ start: Point3DLike,
328
+ end: Point3DLike,
329
+ angle: float = TAU / 4,
330
+ **kwargs: Any,
331
+ ):
279
332
  super().__init__(angle=angle, **kwargs)
280
333
  if angle == 0:
281
334
  self.set_points_as_corners([LEFT, RIGHT])
@@ -283,30 +336,37 @@ class OpenGLArcBetweenPoints(OpenGLArc):
283
336
 
284
337
 
285
338
  class OpenGLCurvedArrow(OpenGLArcBetweenPoints):
286
- def __init__(self, start_point, end_point, **kwargs):
339
+ def __init__(self, start_point: Point3DLike, end_point: Point3DLike, **kwargs: Any):
287
340
  super().__init__(start_point, end_point, **kwargs)
288
341
  self.add_tip()
289
342
 
290
343
 
291
344
  class OpenGLCurvedDoubleArrow(OpenGLCurvedArrow):
292
- def __init__(self, start_point, end_point, **kwargs):
345
+ def __init__(self, start_point: Point3DLike, end_point: Point3DLike, **kwargs: Any):
293
346
  super().__init__(start_point, end_point, **kwargs)
294
347
  self.add_tip(at_start=True)
295
348
 
296
349
 
297
350
  class OpenGLCircle(OpenGLArc):
298
- def __init__(self, color=RED, **kwargs):
351
+ def __init__(self, color: ParsableManimColor = RED, **kwargs: Any):
299
352
  super().__init__(0, TAU, color=color, **kwargs)
300
353
 
301
- def surround(self, mobject, dim_to_match=0, stretch=False, buff=MED_SMALL_BUFF):
354
+ def surround(
355
+ self,
356
+ mobject: OpenGLMobject,
357
+ dim_to_match: int = 0,
358
+ stretch: bool = False,
359
+ buff: float = MED_SMALL_BUFF,
360
+ ) -> Self:
302
361
  # Ignores dim_to_match and stretch; result will always be a circle
303
362
  # TODO: Perhaps create an ellipse class to handle singele-dimension stretching
304
363
 
305
364
  self.replace(mobject, dim_to_match, stretch)
306
365
  self.stretch((self.get_width() + 2 * buff) / self.get_width(), 0)
307
366
  self.stretch((self.get_height() + 2 * buff) / self.get_height(), 1)
367
+ return self
308
368
 
309
- def point_at_angle(self, angle):
369
+ def point_at_angle(self, angle: float) -> Point3D:
310
370
  start_angle = self.get_start_angle()
311
371
  return self.point_from_proportion((angle - start_angle) / TAU)
312
372
 
@@ -314,12 +374,12 @@ class OpenGLCircle(OpenGLArc):
314
374
  class OpenGLDot(OpenGLCircle):
315
375
  def __init__(
316
376
  self,
317
- point=ORIGIN,
318
- radius=DEFAULT_DOT_RADIUS,
319
- stroke_width=0,
320
- fill_opacity=1.0,
321
- color=WHITE,
322
- **kwargs,
377
+ point: Point3DLike = ORIGIN,
378
+ radius: float = DEFAULT_DOT_RADIUS,
379
+ stroke_width: float = 0,
380
+ fill_opacity: float = 1.0,
381
+ color: ParsableManimColor = WHITE,
382
+ **kwargs: Any,
323
383
  ):
324
384
  super().__init__(
325
385
  arc_center=point,
@@ -332,7 +392,7 @@ class OpenGLDot(OpenGLCircle):
332
392
 
333
393
 
334
394
  class OpenGLEllipse(OpenGLCircle):
335
- def __init__(self, width=2, height=1, **kwargs):
395
+ def __init__(self, width: float = 2, height: float = 1, **kwargs: Any):
336
396
  super().__init__(**kwargs)
337
397
  self.set_width(width, stretch=True)
338
398
  self.set_height(height, stretch=True)
@@ -341,14 +401,14 @@ class OpenGLEllipse(OpenGLCircle):
341
401
  class OpenGLAnnularSector(OpenGLArc):
342
402
  def __init__(
343
403
  self,
344
- inner_radius=1,
345
- outer_radius=2,
346
- angle=TAU / 4,
347
- start_angle=0,
348
- fill_opacity=1,
349
- stroke_width=0,
350
- color=WHITE,
351
- **kwargs,
404
+ inner_radius: float = 1,
405
+ outer_radius: float = 2,
406
+ angle: float = TAU / 4,
407
+ start_angle: float = 0,
408
+ fill_opacity: float = 1,
409
+ stroke_width: float = 0,
410
+ color: ParsableManimColor = WHITE,
411
+ **kwargs: Any,
352
412
  ):
353
413
  self.inner_radius = inner_radius
354
414
  self.outer_radius = outer_radius
@@ -361,7 +421,7 @@ class OpenGLAnnularSector(OpenGLArc):
361
421
  **kwargs,
362
422
  )
363
423
 
364
- def init_points(self):
424
+ def init_points(self) -> None:
365
425
  inner_arc, outer_arc = (
366
426
  OpenGLArc(
367
427
  start_angle=self.start_angle,
@@ -379,20 +439,20 @@ class OpenGLAnnularSector(OpenGLArc):
379
439
 
380
440
 
381
441
  class OpenGLSector(OpenGLAnnularSector):
382
- def __init__(self, outer_radius=1, inner_radius=0, **kwargs):
442
+ def __init__(self, outer_radius: float = 1, inner_radius: float = 0, **kwargs: Any):
383
443
  super().__init__(inner_radius=inner_radius, outer_radius=outer_radius, **kwargs)
384
444
 
385
445
 
386
446
  class OpenGLAnnulus(OpenGLCircle):
387
447
  def __init__(
388
448
  self,
389
- inner_radius=1,
390
- outer_radius=2,
391
- fill_opacity=1,
392
- stroke_width=0,
393
- color=WHITE,
394
- mark_paths_closed=False,
395
- **kwargs,
449
+ inner_radius: float = 1,
450
+ outer_radius: float = 2,
451
+ fill_opacity: float = 1,
452
+ stroke_width: float = 0,
453
+ color: ParsableManimColor = WHITE,
454
+ mark_paths_closed: bool = False,
455
+ **kwargs: Any,
396
456
  ):
397
457
  self.mark_paths_closed = mark_paths_closed # is this even used?
398
458
  self.inner_radius = inner_radius
@@ -401,7 +461,7 @@ class OpenGLAnnulus(OpenGLCircle):
401
461
  fill_opacity=fill_opacity, stroke_width=stroke_width, color=color, **kwargs
402
462
  )
403
463
 
404
- def init_points(self):
464
+ def init_points(self) -> None:
405
465
  self.radius = self.outer_radius
406
466
  outer_circle = OpenGLCircle(radius=self.outer_radius)
407
467
  inner_circle = OpenGLCircle(radius=self.inner_radius)
@@ -412,17 +472,26 @@ class OpenGLAnnulus(OpenGLCircle):
412
472
 
413
473
 
414
474
  class OpenGLLine(OpenGLTipableVMobject):
415
- def __init__(self, start=LEFT, end=RIGHT, buff=0, path_arc=0, **kwargs):
475
+ def __init__(
476
+ self,
477
+ start: Point3DLike = LEFT,
478
+ end: Point3DLike = RIGHT,
479
+ buff: float = 0,
480
+ path_arc: float = 0,
481
+ **kwargs: Any,
482
+ ):
416
483
  self.dim = 3
417
484
  self.buff = buff
418
485
  self.path_arc = path_arc
419
486
  self.set_start_and_end_attrs(start, end)
420
487
  super().__init__(**kwargs)
421
488
 
422
- def init_points(self):
489
+ def init_points(self) -> None:
423
490
  self.set_points_by_ends(self.start, self.end, self.buff, self.path_arc)
424
491
 
425
- def set_points_by_ends(self, start, end, buff=0, path_arc=0):
492
+ def set_points_by_ends(
493
+ self, start: Point3DLike, end: Point3DLike, buff: float = 0, path_arc: float = 0
494
+ ) -> None:
426
495
  if path_arc:
427
496
  self.set_points(OpenGLArc.create_quadratic_bezier_points(path_arc))
428
497
  self.put_start_and_end_on(start, end)
@@ -430,26 +499,25 @@ class OpenGLLine(OpenGLTipableVMobject):
430
499
  self.set_points_as_corners([start, end])
431
500
  self.account_for_buff(self.buff)
432
501
 
433
- def set_path_arc(self, new_value):
502
+ def set_path_arc(self, new_value: float) -> None:
434
503
  self.path_arc = new_value
435
504
  self.init_points()
436
505
 
437
- def account_for_buff(self, buff):
506
+ def account_for_buff(self, buff: float) -> Self:
438
507
  if buff == 0:
439
- return
508
+ return self
440
509
  #
441
- if self.path_arc == 0:
442
- length = self.get_length()
443
- else:
444
- length = self.get_arc_length()
510
+ length = self.get_length() if self.path_arc == 0 else self.get_arc_length()
445
511
  #
446
512
  if length < 2 * buff:
447
- return
513
+ return self
448
514
  buff_prop = buff / length
449
515
  self.pointwise_become_partial(self, buff_prop, 1 - buff_prop)
450
516
  return self
451
517
 
452
- def set_start_and_end_attrs(self, start, end):
518
+ def set_start_and_end_attrs(
519
+ self, start: Mobject | Point3DLike, end: Mobject | Point3DLike
520
+ ) -> None:
453
521
  # If either start or end are Mobjects, this
454
522
  # gives their centers
455
523
  rough_start = self.pointify(start)
@@ -461,7 +529,9 @@ class OpenGLLine(OpenGLTipableVMobject):
461
529
  self.start = self.pointify(start, vect) + self.buff * vect
462
530
  self.end = self.pointify(end, -vect) - self.buff * vect
463
531
 
464
- def pointify(self, mob_or_point, direction=None):
532
+ def pointify(
533
+ self, mob_or_point: Mobject | Point3DLike, direction: Vector3DLike = None
534
+ ) -> Point3D:
465
535
  """
466
536
  Take an argument passed into Line (or subclass) and turn
467
537
  it into a 3d point.
@@ -478,33 +548,32 @@ class OpenGLLine(OpenGLTipableVMobject):
478
548
  result[: len(point)] = point
479
549
  return result
480
550
 
481
- def put_start_and_end_on(self, start, end):
551
+ def put_start_and_end_on(self, start: Point3DLike, end: Point3DLike) -> Self:
482
552
  curr_start, curr_end = self.get_start_and_end()
483
553
  if (curr_start == curr_end).all():
484
554
  self.set_points_by_ends(start, end, self.path_arc)
485
555
  return super().put_start_and_end_on(start, end)
486
556
 
487
- def get_vector(self):
557
+ def get_vector(self) -> Vector3D:
488
558
  return self.get_end() - self.get_start()
489
559
 
490
- def get_unit_vector(self):
560
+ def get_unit_vector(self) -> Vector3D:
491
561
  return normalize(self.get_vector())
492
562
 
493
- def get_angle(self):
563
+ def get_angle(self) -> float:
494
564
  return angle_of_vector(self.get_vector())
495
565
 
496
- def get_projection(self, point):
497
- """
498
- Return projection of a point onto the line
499
- """
566
+ def get_projection(self, point: Point3DLike) -> Point3D:
567
+ """Return projection of a point onto the line"""
500
568
  unit_vect = self.get_unit_vector()
501
569
  start = self.get_start()
502
570
  return start + np.dot(point - start, unit_vect) * unit_vect
503
571
 
504
- def get_slope(self):
505
- return np.tan(self.get_angle())
572
+ def get_slope(self) -> float:
573
+ rv: float = np.tan(self.get_angle())
574
+ return rv
506
575
 
507
- def set_angle(self, angle, about_point=None):
576
+ def set_angle(self, angle: float, about_point: Point3DLike | None = None) -> Self:
508
577
  if about_point is None:
509
578
  about_point = self.get_start()
510
579
  self.rotate(
@@ -513,13 +582,17 @@ class OpenGLLine(OpenGLTipableVMobject):
513
582
  )
514
583
  return self
515
584
 
516
- def set_length(self, length):
585
+ def set_length(self, length: float) -> None:
517
586
  self.scale(length / self.get_length())
518
587
 
519
588
 
520
589
  class OpenGLDashedLine(OpenGLLine):
521
590
  def __init__(
522
- self, *args, dash_length=DEFAULT_DASH_LENGTH, dashed_ratio=0.5, **kwargs
591
+ self,
592
+ *args: Any,
593
+ dash_length: float = DEFAULT_DASH_LENGTH,
594
+ dashed_ratio: float = 0.5,
595
+ **kwargs: Any,
523
596
  ):
524
597
  self.dashed_ratio = dashed_ratio
525
598
  self.dash_length = dash_length
@@ -534,33 +607,40 @@ class OpenGLDashedLine(OpenGLLine):
534
607
  self.clear_points()
535
608
  self.add(*dashes)
536
609
 
537
- def calculate_num_dashes(self, dashed_ratio):
610
+ def calculate_num_dashes(self, dashed_ratio: float) -> int:
538
611
  return max(
539
612
  2,
540
613
  int(np.ceil((self.get_length() / self.dash_length) * dashed_ratio)),
541
614
  )
542
615
 
543
- def get_start(self):
616
+ def get_start(self) -> Point3D:
544
617
  if len(self.submobjects) > 0:
545
618
  return self.submobjects[0].get_start()
546
619
  else:
547
620
  return super().get_start()
548
621
 
549
- def get_end(self):
622
+ def get_end(self) -> Point3D:
550
623
  if len(self.submobjects) > 0:
551
624
  return self.submobjects[-1].get_end()
552
625
  else:
553
626
  return super().get_end()
554
627
 
555
- def get_first_handle(self):
628
+ def get_first_handle(self) -> Point3D:
556
629
  return self.submobjects[0].points[1]
557
630
 
558
- def get_last_handle(self):
631
+ def get_last_handle(self) -> Point3D:
559
632
  return self.submobjects[-1].points[-2]
560
633
 
561
634
 
562
635
  class OpenGLTangentLine(OpenGLLine):
563
- def __init__(self, vmob, alpha, length=1, d_alpha=1e-6, **kwargs):
636
+ def __init__(
637
+ self,
638
+ vmob: OpenGLVMobject,
639
+ alpha: float,
640
+ length: float = 1,
641
+ d_alpha: float = 1e-6,
642
+ **kwargs: Any,
643
+ ):
564
644
  self.length = length
565
645
  self.d_alpha = d_alpha
566
646
  da = self.d_alpha
@@ -571,7 +651,7 @@ class OpenGLTangentLine(OpenGLLine):
571
651
 
572
652
 
573
653
  class OpenGLElbow(OpenGLVMobject):
574
- def __init__(self, width=0.2, angle=0, **kwargs):
654
+ def __init__(self, width: float = 0.2, angle: float = 0, **kwargs: Any):
575
655
  self.angle = angle
576
656
  super().__init__(self, **kwargs)
577
657
  self.set_points_as_corners([UP, UP + RIGHT, RIGHT])
@@ -582,19 +662,19 @@ class OpenGLElbow(OpenGLVMobject):
582
662
  class OpenGLArrow(OpenGLLine):
583
663
  def __init__(
584
664
  self,
585
- start=LEFT,
586
- end=RIGHT,
587
- path_arc=0,
588
- fill_color=GREY_A,
589
- fill_opacity=1,
590
- stroke_width=0,
591
- buff=MED_SMALL_BUFF,
592
- thickness=0.05,
593
- tip_width_ratio=5,
594
- tip_angle=PI / 3,
595
- max_tip_length_to_length_ratio=0.5,
596
- max_width_to_length_ratio=0.1,
597
- **kwargs,
665
+ start: Point3DLike = LEFT,
666
+ end: Point3DLike = RIGHT,
667
+ path_arc: float = 0,
668
+ fill_color: ParsableManimColor = GREY_A,
669
+ fill_opacity: float = 1,
670
+ stroke_width: float = 0,
671
+ buff: float = MED_SMALL_BUFF,
672
+ thickness: float = 0.05,
673
+ tip_width_ratio: float = 5,
674
+ tip_angle: float = PI / 3,
675
+ max_tip_length_to_length_ratio: float = 0.5,
676
+ max_width_to_length_ratio: float = 0.1,
677
+ **kwargs: Any,
598
678
  ):
599
679
  self.thickness = thickness
600
680
  self.tip_width_ratio = tip_width_ratio
@@ -612,9 +692,11 @@ class OpenGLArrow(OpenGLLine):
612
692
  **kwargs,
613
693
  )
614
694
 
615
- def set_points_by_ends(self, start, end, buff=0, path_arc=0):
695
+ def set_points_by_ends(
696
+ self, start: Point3DLike, end: Point3DLike, buff: float = 0, path_arc: float = 0
697
+ ) -> None:
616
698
  # Find the right tip length and thickness
617
- vect = end - start
699
+ vect = np.asarray(end) - np.asarray(start)
618
700
  length = max(np.linalg.norm(vect), 1e-8)
619
701
  thickness = self.thickness
620
702
  w_ratio = self.max_width_to_length_ratio / (thickness / length)
@@ -675,7 +757,7 @@ class OpenGLArrow(OpenGLLine):
675
757
  self.shift(start - self.get_start())
676
758
  self.refresh_triangulation()
677
759
 
678
- def reset_points_around_ends(self):
760
+ def reset_points_around_ends(self) -> Self:
679
761
  self.set_points_by_ends(
680
762
  self.get_start(),
681
763
  self.get_end(),
@@ -683,36 +765,41 @@ class OpenGLArrow(OpenGLLine):
683
765
  )
684
766
  return self
685
767
 
686
- def get_start(self):
768
+ def get_start(self) -> Point3D:
687
769
  nppc = self.n_points_per_curve
688
770
  points = self.points
689
771
  return (points[0] + points[-nppc]) / 2
690
772
 
691
- def get_end(self):
773
+ def get_end(self) -> Point3D:
692
774
  return self.points[self.tip_index]
693
775
 
694
- def put_start_and_end_on(self, start, end):
776
+ def put_start_and_end_on(self, start: Point3DLike, end: Point3DLike) -> Self:
695
777
  self.set_points_by_ends(start, end, buff=0, path_arc=self.path_arc)
696
778
  return self
697
779
 
698
- def scale(self, *args, **kwargs):
780
+ def scale(self, *args: Any, **kwargs: Any) -> Self:
699
781
  super().scale(*args, **kwargs)
700
782
  self.reset_points_around_ends()
701
783
  return self
702
784
 
703
- def set_thickness(self, thickness):
785
+ def set_thickness(self, thickness: float) -> Self:
704
786
  self.thickness = thickness
705
787
  self.reset_points_around_ends()
706
788
  return self
707
789
 
708
- def set_path_arc(self, path_arc):
790
+ def set_path_arc(self, path_arc: float) -> None:
709
791
  self.path_arc = path_arc
710
792
  self.reset_points_around_ends()
711
- return self
793
+ # return self
712
794
 
713
795
 
714
796
  class OpenGLVector(OpenGLArrow):
715
- def __init__(self, direction=RIGHT, buff=0, **kwargs):
797
+ def __init__(
798
+ self,
799
+ direction: Vector2DLike | Vector3DLike = RIGHT,
800
+ buff: float = 0,
801
+ **kwargs: Any,
802
+ ):
716
803
  self.buff = buff
717
804
  if len(direction) == 2:
718
805
  direction = np.hstack([direction, 0])
@@ -720,30 +807,37 @@ class OpenGLVector(OpenGLArrow):
720
807
 
721
808
 
722
809
  class OpenGLDoubleArrow(OpenGLArrow):
723
- def __init__(self, *args, **kwargs):
810
+ def __init__(self, *args: Any, **kwargs: Any):
724
811
  super().__init__(*args, **kwargs)
725
812
  self.add_tip(at_start=True)
726
813
 
727
814
 
728
815
  class OpenGLCubicBezier(OpenGLVMobject):
729
- def __init__(self, a0, h0, h1, a1, **kwargs):
816
+ def __init__(
817
+ self,
818
+ a0: Point3DLike,
819
+ h0: Point3DLike,
820
+ h1: Point3DLike,
821
+ a1: Point3DLike,
822
+ **kwargs: Any,
823
+ ):
730
824
  super().__init__(**kwargs)
731
825
  self.add_cubic_bezier_curve(a0, h0, h1, a1)
732
826
 
733
827
 
734
828
  class OpenGLPolygon(OpenGLVMobject):
735
- def __init__(self, *vertices, **kwargs):
736
- self.vertices = vertices
829
+ def __init__(self, *vertices: Point3DLike, **kwargs: Any):
830
+ self.vertices: Point3D_Array = np.array(vertices)
737
831
  super().__init__(**kwargs)
738
832
 
739
- def init_points(self):
833
+ def init_points(self) -> None:
740
834
  verts = self.vertices
741
835
  self.set_points_as_corners([*verts, verts[0]])
742
836
 
743
- def get_vertices(self):
837
+ def get_vertices(self) -> Point3D_Array:
744
838
  return self.get_start_anchors()
745
839
 
746
- def round_corners(self, radius=0.5):
840
+ def round_corners(self, radius: float = 0.5) -> Self:
747
841
  vertices = self.get_vertices()
748
842
  arcs = []
749
843
  for v1, v2, v3 in adjacent_n_tuples(vertices, 3):
@@ -780,7 +874,7 @@ class OpenGLPolygon(OpenGLVMobject):
780
874
 
781
875
 
782
876
  class OpenGLRegularPolygon(OpenGLPolygon):
783
- def __init__(self, n=6, start_angle=None, **kwargs):
877
+ def __init__(self, n: int = 6, start_angle: float | None = None, **kwargs: Any):
784
878
  self.start_angle = start_angle
785
879
  if self.start_angle is None:
786
880
  if n % 2 == 0:
@@ -793,20 +887,20 @@ class OpenGLRegularPolygon(OpenGLPolygon):
793
887
 
794
888
 
795
889
  class OpenGLTriangle(OpenGLRegularPolygon):
796
- def __init__(self, **kwargs):
890
+ def __init__(self, **kwargs: Any):
797
891
  super().__init__(n=3, **kwargs)
798
892
 
799
893
 
800
894
  class OpenGLArrowTip(OpenGLTriangle):
801
895
  def __init__(
802
896
  self,
803
- fill_opacity=1,
804
- fill_color=WHITE,
805
- stroke_width=0,
806
- width=DEFAULT_ARROW_TIP_WIDTH,
807
- length=DEFAULT_ARROW_TIP_LENGTH,
808
- angle=0,
809
- **kwargs,
897
+ fill_opacity: float = 1,
898
+ fill_color: ParsableManimColor = WHITE,
899
+ stroke_width: float = 0,
900
+ width: float = DEFAULT_ARROW_TIP_WIDTH,
901
+ length: float = DEFAULT_ARROW_TIP_LENGTH,
902
+ angle: float = 0,
903
+ **kwargs: Any,
810
904
  ):
811
905
  super().__init__(
812
906
  start_angle=0,
@@ -818,24 +912,31 @@ class OpenGLArrowTip(OpenGLTriangle):
818
912
  self.set_width(width, stretch=True)
819
913
  self.set_height(length, stretch=True)
820
914
 
821
- def get_base(self):
915
+ def get_base(self) -> Point3D:
822
916
  return self.point_from_proportion(0.5)
823
917
 
824
- def get_tip_point(self):
918
+ def get_tip_point(self) -> Point3D:
825
919
  return self.points[0]
826
920
 
827
- def get_vector(self):
921
+ def get_vector(self) -> Vector3D:
828
922
  return self.get_tip_point() - self.get_base()
829
923
 
830
- def get_angle(self):
924
+ def get_angle(self) -> float:
831
925
  return angle_of_vector(self.get_vector())
832
926
 
833
- def get_length(self):
834
- return np.linalg.norm(self.get_vector())
927
+ def get_length(self) -> float:
928
+ rv: float = np.linalg.norm(self.get_vector())
929
+ return rv
835
930
 
836
931
 
837
932
  class OpenGLRectangle(OpenGLPolygon):
838
- def __init__(self, color=WHITE, width=4.0, height=2.0, **kwargs):
933
+ def __init__(
934
+ self,
935
+ color: ParsableManimColor = WHITE,
936
+ width: float = 4.0,
937
+ height: float = 2.0,
938
+ **kwargs: Any,
939
+ ):
839
940
  super().__init__(UR, UL, DL, DR, color=color, **kwargs)
840
941
 
841
942
  self.set_width(width, stretch=True)
@@ -843,14 +944,14 @@ class OpenGLRectangle(OpenGLPolygon):
843
944
 
844
945
 
845
946
  class OpenGLSquare(OpenGLRectangle):
846
- def __init__(self, side_length=2.0, **kwargs):
947
+ def __init__(self, side_length: float = 2.0, **kwargs: Any):
847
948
  self.side_length = side_length
848
949
 
849
950
  super().__init__(height=side_length, width=side_length, **kwargs)
850
951
 
851
952
 
852
953
  class OpenGLRoundedRectangle(OpenGLRectangle):
853
- def __init__(self, corner_radius=0.5, **kwargs):
954
+ def __init__(self, corner_radius: float = 0.5, **kwargs: Any):
854
955
  self.corner_radius = corner_radius
855
956
  super().__init__(**kwargs)
856
957
  self.round_corners(self.corner_radius)