You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it's important that typehints are chosen correctly.
5
+
it's important that type hints are chosen correctly.
6
6
With the large variety of types provided by Manim, choosing
7
7
which one to use can be difficult. This guide aims to
8
8
aid you in the process of choosing the right type for the scenario.
9
9
10
10
11
-
The first step is figuring out which category your typehint fits into.
11
+
The first step is figuring out which category your type hint fits into.
12
12
13
13
Coordinates
14
14
-----------
15
-
Coordinates encompasses two "main" categories: points, and vectors.
15
+
Coordinates encompass two main categories: points, and vectors.
16
16
17
17
18
18
Points
@@ -41,10 +41,10 @@ in space. For example:
41
41
# it's a point3D
42
42
status3D(coord)
43
43
44
-
It's important to realize that the status functions worked with both
44
+
It's important to realize that the status functions accepted both
45
45
tuples/lists of the correct length, and ``NDArray``'s of the correct shape.
46
-
If they only worked with ``NDArray``'s, we would use their "Internal" counterparts:
47
-
``InternalPoint2D``, ``InternalPoint3D``, ``InternalPoint2D_Array`` and ``InternalPoint3D_Array``.
46
+
If they only accepted ``NDArray``'s, we would use their ``Internal`` counterparts:
47
+
:class:`~.typing.InternalPoint2D`, :class:`~.typing.InternalPoint3D`, :class:`~.typing.InternalPoint2D_Array` and :class:`~.typing.InternalPoint3D_Array`.
48
48
49
49
In general, the type aliases prefixed with ``Internal`` should never be used on
50
50
user-facing classes and functions, but should be reserved for internal behavior.
@@ -61,41 +61,41 @@ consider this slightly contrived function:
61
61
return mob.shift(direction * scale_factor)
62
62
63
63
Here we see an important example of the difference. ``direction`` can not, and
64
-
should not, be typed as a ``Point3D`` because it does not work with something
65
-
like ``direction=(0, 1, 0)``. You could type it as ``InternalPoint3D`` and
66
-
the typechecker and linter would be happy; however, this makes the code harder
64
+
should not, be typed as a :class:`~.typing.Point3D` because the function does not accept tuples/lists,
65
+
like ``direction=(0, 1, 0)``. You could type it as :class:`~.typing.InternalPoint3D` and
66
+
the type checker and linter would be happy; however, this makes the code harder
67
67
to understand.
68
68
69
69
As a general rule, if a parameter is called ``direction`` or ``axis``,
70
-
it should be typehinted as some form of ``Vector``.
70
+
it should be type hinted as some form of :class:`~.VectorND`.
71
71
72
72
.. warning::
73
73
74
-
This is not always true. For example as of Manim 0.18.0, the direction
75
-
parameter of the Vector mobject should be ``Point2D | Point3D``
74
+
This is not always true. For example, as of Manim 0.18.0, the direction
75
+
parameter of the :class:`.Vector` Mobject should be ``Point2D | Point3D``,
76
76
as it can also accept ``tuple[float, float]`` and ``tuple[float, float, float]``.
77
77
78
78
Colors
79
79
------
80
-
The interface manim provides for working with colors is :class:`.ManimColor`.
80
+
The interface Manim provides for working with colors is :class:`.ManimColor`.
81
81
The main color types Manim supports are RGB, RGBA, and HSV. You will want
82
-
to typehint a function depending on which type it uses. If any color will work,
82
+
to add type hints to a function depending on which type it uses. If any color will work,
83
83
you will need something like:
84
84
85
85
.. code-block:: python
86
86
87
87
ifTYPE_CHECKING:
88
88
from manim.utils.color import ParsableManimColor
89
89
90
-
#typehint stuff with ParsableManimColor
90
+
#type hint stuff with ParsableManimColor
91
91
92
92
93
93
94
94
Béziers
95
95
-------
96
-
Manim internally represents a ``Mobject`` by a collection of points. These
97
-
points represent Bézier curves, which are a way of representing a curve using a
98
-
sequence of points.
96
+
Manim internally represents a :class:`.Mobject` by a collection of points. In the case of :class:`.VMobject`,
97
+
the most commonly used subclass of :class:`.Mobject`, these points represent Bézier curves,
98
+
which are a way of representing a curve using a sequence of points.
99
99
100
100
.. note::
101
101
@@ -105,30 +105,30 @@ sequence of points.
105
105
Manim supports two different renderers, which each have different representations of
0 commit comments