Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Typing #3086

Merged
merged 101 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
bd4d123
first draft of color class + starting library conversion
MrDiver Nov 13, 2022
01e28fd
Merge branch 'main' into color_fix
MrDiver Nov 13, 2022
a0e85af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 13, 2022
8af3f81
Merge branch 'main' into color_fix
MrDiver Nov 19, 2022
332d327
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2022
da0806a
changed everything to Manim color todo: figure out circular dependenc…
MrDiver Nov 19, 2022
73ffb51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2022
157c504
first working draft of new color version
MrDiver Dec 10, 2022
a7e4a3e
Merge branch 'main' into color_fix
MrDiver Dec 10, 2022
d21583d
resolving conflicts
MrDiver Dec 11, 2022
074345e
resolving conflicts
MrDiver Dec 11, 2022
128b8ab
resolving conflicts
MrDiver Dec 11, 2022
31bcdac
resolving conflicts
MrDiver Dec 11, 2022
27c0ddb
resolving conflicts
MrDiver Dec 11, 2022
195512a
changed default internal value of ManimColor to np.ndarray[float]
MrDiver Dec 16, 2022
9823616
starting to fix tests
MrDiver Dec 16, 2022
e638643
fixed more tests and changed precision of manim color
MrDiver Dec 17, 2022
7867aa3
removed premature color conversion
MrDiver Dec 17, 2022
a12507a
fixed some more tests
MrDiver Dec 17, 2022
15c4998
final test changes
MrDiver Dec 17, 2022
76d7cda
fix doctests
MrDiver Dec 17, 2022
a27aff4
fix for 3.8
MrDiver Dec 17, 2022
1580c82
fixing ManimColor string representation
MrDiver Dec 17, 2022
b2cc282
removing some unneccesary conversions
MrDiver Dec 17, 2022
2baeff5
moved community constants to manim_colors.py and added more color sta…
MrDiver Dec 22, 2022
86c5d07
Merge branch 'main' into color_fix
MrDiver Dec 22, 2022
b44a3e9
Merge branch 'color_fix' of github.com:MrDiver/manim into 52-fix-typing
MrDiver Dec 24, 2022
cd7a385
Added typing.py and typed bezier.py, core.py, constants.py fully
MrDiver Dec 25, 2022
47e16b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 25, 2022
3193597
fixed codeql complaints
MrDiver Dec 25, 2022
bd3bf0c
add type ignore for np.allclose
MrDiver Dec 25, 2022
8c1b871
fixed import in three_dimensions
MrDiver Dec 25, 2022
2433c1d
added ignore for F401 back again in flake
MrDiver Dec 25, 2022
d32b267
added typings to coordinate_systems.py
alembcke Jan 7, 2023
0356591
Few improvements to `graphing/coordinate_systems.py`
Viicos Jan 20, 2023
b08e4a6
added some typings to mobject/geometry/line.py
alembcke Jan 20, 2023
ee865ff
updated typings for mobject/geometry/line.py
alembcke Jan 21, 2023
9eb6ed3
Add missing imports to `line.py`
Viicos Jan 21, 2023
561ef52
added typings to three_dimensions.py
alembcke Feb 6, 2023
bf2bcbf
Use `FunctionOverride` for animation overrides
Viicos Feb 18, 2023
1f56200
Remove `TYPE_CHECKING` check
Viicos Feb 18, 2023
802ab71
Revert "Remove `TYPE_CHECKING` check"
Viicos Feb 18, 2023
b11ffe2
Use `Self` in `coordinate_systems.py`
Viicos Feb 18, 2023
a41900c
Typehinted mobject.py and updated manim.typing.py
JasonGrace2282 Aug 6, 2023
c0f121c
Typed VMobject
JasonGrace2282 Aug 10, 2023
88f9b2d
Type-hinted manim.mobject.geometry
JasonGrace2282 Aug 10, 2023
17ce647
math.cos->np.cos, etc & fixed incorrect typehints
JasonGrace2282 Aug 10, 2023
747167b
Merge branch 'main' of github.com:ManimCommunity/manim into 52-fix-ty…
MrDiver Aug 11, 2023
2a71462
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2023
8a149ca
fix missing annotations import
MrDiver Aug 11, 2023
28d9b24
Merge branch '52-fix-typing' of github.com:MrDiver/manim into 52-fix-…
MrDiver Aug 11, 2023
6987498
TypeAlias fix in typing.py
MrDiver Aug 11, 2023
9026015
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 11, 2023
51922d1
Add ignore errors again to mypy because commits are not possible like…
MrDiver Aug 11, 2023
e8ab923
Merge main
Viicos Sep 22, 2023
106774d
Fix last typing issues
Viicos Sep 22, 2023
ca3154c
Update docs
Viicos Sep 22, 2023
920d15c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2023
c6183e8
Only type check manim
Viicos Sep 22, 2023
ad7043f
Try fixing pre-commit
Viicos Sep 22, 2023
1da1b99
fix merge
Viicos Sep 22, 2023
8522b59
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2023
6f95fd3
Fix compat
Viicos Sep 22, 2023
c2d7d42
Fix compat again
Viicos Sep 22, 2023
3a3d501
Fix imports compat
Viicos Sep 22, 2023
2189d01
Use union syntax
Viicos Sep 22, 2023
e62ade2
Use union syntax
Viicos Sep 22, 2023
4497734
Fix reduce_across_dimension
Viicos Sep 22, 2023
aadb22c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2023
0852403
Various test and merge fixes
Viicos Sep 22, 2023
b9fbf54
Doc fixes
Viicos Sep 22, 2023
0f108c0
Last doc fix
Viicos Sep 22, 2023
5160a1f
Revert usage of np over math
Viicos Sep 23, 2023
388b6d1
Bump numpy version
Viicos Sep 23, 2023
287c3ad
Remove obsolete duplicate example
Viicos Sep 23, 2023
0c0f875
Fixed Incorrect Typehint in manim.constants
JasonGrace2282 Sep 23, 2023
b87b594
Fix docstring typo
Viicos Sep 24, 2023
1c139af
More fixes
Viicos Sep 25, 2023
ffaa031
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 25, 2023
56501d7
docs fixes
Viicos Sep 25, 2023
921f450
Add internal aliases
Viicos Sep 25, 2023
4e3fe30
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 25, 2023
5663791
fix compat
Viicos Sep 25, 2023
f92ebd6
Merge remote-tracking branch 'origin/main' into 52-fix-typing
behackl Oct 27, 2023
feca683
line lengths in .rst file, formatting, typos
behackl Oct 28, 2023
2bcd8ac
add docstring for space_ops:cross2d
behackl Oct 28, 2023
5514ac4
add some more arrow tip typings (in a non-circular import causing way)
behackl Oct 28, 2023
b259a04
yes, this can be deleted
behackl Oct 28, 2023
e390082
fix formatting of example
behackl Oct 28, 2023
737189c
added docstring to bezier::inverse_interpolation
behackl Oct 28, 2023
3c4051f
added docstring + test for bezier::match_interpolate
behackl Oct 28, 2023
c7659d3
some improvements in coordinate_systems
behackl Oct 28, 2023
351353a
Vector -> Vector3
behackl Oct 28, 2023
3616c50
replaced np.ndarray with more appropriate type hints
behackl Oct 28, 2023
672b0e3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2023
84c9cdc
Apply feedback
Viicos Oct 29, 2023
4fed4af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2023
ad228f1
revert to previous (new) version
behackl Nov 2, 2023
c2b48f8
fix doctest
behackl Nov 3, 2023
948214e
fix ReST errors
behackl Nov 3, 2023
33d9e4a
Merge remote-tracking branch 'origin/main' into 52-fix-typing
behackl Nov 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion manim/_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,6 @@ def format(self, val: str) -> None:
doc="Frame rate in frames per second.",
)

# TODO: This was parsed before maybe add ManimColor(val), but results in circular import
background_color = property(
lambda self: self._d["background_color"],
lambda self, val: self._d.__setitem__("background_color", ManimColor(val)),
Expand Down
6 changes: 2 additions & 4 deletions manim/mobject/geometry/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def construct(self):

import itertools
import warnings
from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING

import numpy as np
from typing_extensions import Self, TypeAlias
from typing_extensions import Self

from manim.constants import *
from manim.mobject.opengl.opengl_compatibility import ConvertToOpenGL
Expand All @@ -70,8 +70,6 @@ def construct(self):
from manim.typing import CubicBezierPoints, Point3D, QuadraticBezierPoints, Vector


Angle: TypeAlias = Union[float, np.float64]


class TipableVMobject(VMobject, metaclass=ConvertToOpenGL):
"""Meant for shared functionality between Arc and Line.
Expand Down
1 change: 0 additions & 1 deletion manim/mobject/graphing/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,6 @@ def get_T_label(
label_color: ParsableManimColor | None = None,
triangle_size: float = MED_SMALL_BUFF,
triangle_color: ParsableManimColor | None = WHITE,
# TODO: May have to be made a generic but it can be more than just a line.
line_func: type[Line] = Line,
line_color: ParsableManimColor = YELLOW,
) -> VGroup:
Expand Down
59 changes: 30 additions & 29 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
Point3D,
Point3D_Array,
Vector,
Vector3,
)

from ..animation.animation import Animation
Expand Down Expand Up @@ -1148,7 +1149,7 @@ def apply_to_family(self, func: Callable[[Mobject], None]) -> None:
for mob in self.family_members_with_points():
func(mob)

def shift(self, *vectors: Vector) -> Self:
def shift(self, *vectors: Vector3) -> Self:
"""Shift by the given vectors.

Parameters
Expand Down Expand Up @@ -1220,14 +1221,14 @@ def construct(self):
)
return self

def rotate_about_origin(self, angle: float, axis: Vector = OUT, axes=[]) -> Self:
def rotate_about_origin(self, angle: float, axis: Vector3 = OUT, axes=[]) -> Self:
"""Rotates the :class:`~.Mobject` about the ORIGIN, which is at [0,0,0]."""
return self.rotate(angle, axis, about_point=ORIGIN)

def rotate(
self,
angle: float,
axis: Vector = OUT,
axis: Vector3 = OUT,
about_point: Point3D | None = None,
**kwargs,
) -> Self:
Expand All @@ -1238,7 +1239,7 @@ def rotate(
)
return self

def flip(self, axis: Vector = UP, **kwargs) -> Self:
def flip(self, axis: Vector3 = UP, **kwargs) -> Self:
"""Flips/Mirrors an mobject about its center.

Examples
Expand Down Expand Up @@ -1332,7 +1333,7 @@ def R3_func(point):
return self.apply_function(R3_func)

def wag(
self, direction: Vector = RIGHT, axis: Vector = DOWN, wag_factor: float = 1.0
self, direction: Vector3 = RIGHT, axis: Vector3 = DOWN, wag_factor: float = 1.0
) -> Self:
for mob in self.family_members_with_points():
alphas = np.dot(mob.points, np.transpose(axis))
Expand Down Expand Up @@ -1398,7 +1399,7 @@ def center(self) -> Self:
return self

def align_on_border(
self, direction: Vector, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER
self, direction: Vector3, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER
) -> Self:
"""Direction just needs to be a vector pointing towards side or
corner in the 2d plane.
Expand All @@ -1415,24 +1416,24 @@ def align_on_border(
return self

def to_corner(
self, corner: Vector = DL, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER
self, corner: Vector3 = DL, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER
) -> Self:
return self.align_on_border(corner, buff)

def to_edge(
self, edge: Vector = LEFT, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER
self, edge: Vector3 = LEFT, buff: float = DEFAULT_MOBJECT_TO_EDGE_BUFFER
) -> Self:
return self.align_on_border(edge, buff)

def next_to(
self,
mobject_or_point: Mobject | Point3D,
direction: Vector = RIGHT,
direction: Vector3 = RIGHT,
buff: float = DEFAULT_MOBJECT_TO_MOBJECT_BUFFER,
aligned_edge: Vector = ORIGIN,
aligned_edge: Vector3 = ORIGIN,
submobject_to_align: Mobject | None = None,
index_of_submobject_to_align: int | None = None,
coor_mask: Vector = np.array([1, 1, 1]),
coor_mask: Vector3 = np.array([1, 1, 1]),
) -> Self:
"""Move this :class:`~.Mobject` next to another's :class:`~.Mobject` or Point3D.

Expand Down Expand Up @@ -1624,22 +1625,22 @@ def stretch_to_fit_depth(self, depth: float, **kwargs) -> Self:

return self.rescale_to_fit(depth, 2, stretch=True, **kwargs)

def set_coord(self, value, dim: int, direction: Vector = ORIGIN) -> Self:
def set_coord(self, value, dim: int, direction: Vector3 = ORIGIN) -> Self:
curr = self.get_coord(dim, direction)
shift_vect = np.zeros(self.dim)
shift_vect[dim] = value - curr
self.shift(shift_vect)
return self

def set_x(self, x: float, direction: Vector = ORIGIN) -> Self:
def set_x(self, x: float, direction: Vector3 = ORIGIN) -> Self:
"""Set x value of the center of the :class:`~.Mobject` (``int`` or ``float``)"""
return self.set_coord(x, 0, direction)

def set_y(self, y: float, direction: Vector = ORIGIN) -> Self:
def set_y(self, y: float, direction: Vector3 = ORIGIN) -> Self:
"""Set y value of the center of the :class:`~.Mobject` (``int`` or ``float``)"""
return self.set_coord(y, 1, direction)

def set_z(self, z: float, direction: Vector = ORIGIN) -> Self:
def set_z(self, z: float, direction: Vector3 = ORIGIN) -> Self:
"""Set z value of the center of the :class:`~.Mobject` (``int`` or ``float``)"""
return self.set_coord(z, 2, direction)

Expand All @@ -1652,8 +1653,8 @@ def space_out_submobjects(self, factor: float = 1.5, **kwargs) -> Self:
def move_to(
self,
point_or_mobject: Point3D | Mobject,
aligned_edge: Vector = ORIGIN,
coor_mask: Vector = np.array([1, 1, 1]),
aligned_edge: Vector3 = ORIGIN,
coor_mask: Vector3 = np.array([1, 1, 1]),
) -> Self:
"""Move center of the :class:`~.Mobject` to certain Point3D."""
if isinstance(point_or_mobject, Mobject):
Expand Down Expand Up @@ -1958,7 +1959,7 @@ def get_extremum_along_dim(
else:
return np.max(values)

def get_critical_point(self, direction: Vector) -> Point3D:
def get_critical_point(self, direction: Vector3) -> Point3D:
"""Picture a box bounding the :class:`~.Mobject`. Such a box has
9 'critical points': 4 corners, 4 edge center, the
center. This returns one of them, along the given direction.
Expand Down Expand Up @@ -1987,11 +1988,11 @@ def get_critical_point(self, direction: Vector) -> Point3D:

# Pseudonyms for more general get_critical_point method

def get_edge_center(self, direction: Vector) -> Point3D:
def get_edge_center(self, direction: Vector3) -> Point3D:
"""Get edge Point3Ds for certain direction."""
return self.get_critical_point(direction)

def get_corner(self, direction: Vector) -> Point3D:
def get_corner(self, direction: Vector3) -> Point3D:
"""Get corner Point3Ds for certain direction."""
return self.get_critical_point(direction)

Expand All @@ -2002,7 +2003,7 @@ def get_center(self) -> Point3D:
def get_center_of_mass(self) -> Point3D:
return np.apply_along_axis(np.mean, 0, self.get_all_points())

def get_boundary_point(self, direction: Vector) -> Point3D:
def get_boundary_point(self, direction: Vector3) -> Point3D:
all_points = self.get_points_defining_boundary()
index = np.argmax(np.dot(all_points, np.array(direction).T))
return all_points[index]
Expand Down Expand Up @@ -2061,19 +2062,19 @@ def length_over_dim(self, dim: int) -> float:
dim,
) - self.reduce_across_dimension(min, dim)

def get_coord(self, dim: int, direction: Vector = ORIGIN):
def get_coord(self, dim: int, direction: Vector3 = ORIGIN):
"""Meant to generalize ``get_x``, ``get_y`` and ``get_z``"""
return self.get_extremum_along_dim(dim=dim, key=direction[dim])

def get_x(self, direction: Vector = ORIGIN) -> ManimFloat:
def get_x(self, direction: Vector3 = ORIGIN) -> ManimFloat:
"""Returns x Point3D of the center of the :class:`~.Mobject` as ``float``"""
return self.get_coord(0, direction)

def get_y(self, direction: Vector = ORIGIN) -> ManimFloat:
def get_y(self, direction: Vector3 = ORIGIN) -> ManimFloat:
"""Returns y Point3D of the center of the :class:`~.Mobject` as ``float``"""
return self.get_coord(1, direction)

def get_z(self, direction: Vector = ORIGIN) -> ManimFloat:
def get_z(self, direction: Vector3 = ORIGIN) -> ManimFloat:
"""Returns z Point3D of the center of the :class:`~.Mobject` as ``float``"""
return self.get_coord(2, direction)

Expand Down Expand Up @@ -2144,7 +2145,7 @@ def match_depth(self, mobject: Mobject, **kwargs) -> Self:
return self.match_dim_size(mobject, 2, **kwargs)

def match_coord(
self, mobject: Mobject, dim: int, direction: Vector = ORIGIN
self, mobject: Mobject, dim: int, direction: Vector3 = ORIGIN
) -> Self:
"""Match the Point3Ds with the Point3Ds of another :class:`~.Mobject`."""
return self.set_coord(
Expand All @@ -2168,7 +2169,7 @@ def match_z(self, mobject: Mobject, direction=ORIGIN) -> Self:
def align_to(
self,
mobject_or_point: Mobject | Point3D,
direction: Vector = ORIGIN,
direction: Vector3 = ORIGIN,
) -> Self:
"""Aligns mobject to another :class:`~.Mobject` in a certain direction.

Expand Down Expand Up @@ -2223,7 +2224,7 @@ def family_members_with_points(self) -> list[Self]:

def arrange(
self,
direction: Vector = RIGHT,
direction: Vector3 = RIGHT,
buff: float = DEFAULT_MOBJECT_TO_MOBJECT_BUFFER,
center: bool = True,
**kwargs,
Expand Down Expand Up @@ -2256,7 +2257,7 @@ def arrange_in_grid(
rows: int | None = None,
cols: int | None = None,
buff: float | tuple[float, float] = MED_SMALL_BUFF,
cell_alignment: Vector = ORIGIN,
cell_alignment: Vector3 = ORIGIN,
row_alignments: str | None = None, # "ucd"
col_alignments: str | None = None, # "lcr"
row_heights: Iterable[float | None] | None = None,
Expand Down
7 changes: 2 additions & 5 deletions manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,17 +1284,14 @@ def insert_n_curves_to_point_list(self, n: int, points: np.ndarray) -> np.ndarra
for _ in range(-diff):
ipc[np.argmax(ipc)] -= 1

new_length = sum(x + 1 for x in ipc)
new_points = np.empty((new_length, nppc, 3))
i = 0
new_points = []
for group, n_inserts in zip(bezier_groups, ipc):
# What was once a single quadratic curve defined
# by "group" will now be broken into n_inserts + 1
# smaller quadratic curves
alphas = np.linspace(0, 1, n_inserts + 2)
for a1, a2 in zip(alphas, alphas[1:]):
new_points[i] = partial_quadratic_bezier_points(group, a1, a2)
i = i + 1
new_points += partial_quadratic_bezier_points(group, a1, a2)
behackl marked this conversation as resolved.
Show resolved Hide resolved
return np.vstack(new_points)

def interpolate(self, mobject1, mobject2, alpha, *args, **kwargs):
Expand Down
7 changes: 5 additions & 2 deletions manim/utils/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,11 @@ def integer_interpolate(
returned integer and the next one of the
list.

For example, if start=0, end=10, alpha=0.46, This
would return (4, 0.6).
Example
-------
.. code-block:: pycon
>>> integer_interpolate(start=0, end=10, alpha=0.46)
(4, 0.6)
"""
if alpha >= 1:
return (int(end - 1), 1.0)
Expand Down