Skip to content

Commit ccdd84c

Browse files
remove weird implementation
1 parent 1c68e52 commit ccdd84c

File tree

2 files changed

+19
-45
lines changed

2 files changed

+19
-45
lines changed

manim/mobject/geometry/shape_matchers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def set_style(self, fill_opacity: float, **kwargs: Any) -> Self: # type: ignore
132132
def get_fill_color(self) -> ManimColor:
133133
# The type of the color property is set to Any using the property decorator
134134
# vectorized_mobject.py#L571
135-
temp_color: ManimColor = self.color
135+
temp_color: ManimColor = self.color # type: ignore[has-type]
136136
return temp_color
137137

138138

manim/mobject/graphing/coordinate_systems.py

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing import TYPE_CHECKING, Any, Callable, TypeVar, overload
1818

1919
import numpy as np
20-
from typing_extensions import NotRequired, Self, TypedDict
20+
from typing_extensions import Self
2121

2222
from manim import config
2323
from manim.constants import *
@@ -62,19 +62,6 @@
6262
LineType = TypeVar("LineType", bound=Line)
6363

6464

65-
class _MatmulConfig(TypedDict):
66-
"""A dictionary for configuring the __matmul__/__rmatmul__ operation.
67-
68-
Parameters
69-
----------
70-
method: The method to call
71-
unpack: whether to unpack the parameter given to __matmul__/__rmatmul__
72-
"""
73-
74-
method: str
75-
unpack: NotRequired[bool]
76-
77-
7865
class CoordinateSystem:
7966
r"""Abstract base class for Axes and NumberPlane.
8067
@@ -160,7 +147,7 @@ def __init__(
160147
self.y_length = y_length
161148
self.num_sampled_graph_points_per_tick = 10
162149

163-
def coords_to_point(self, *coords: ManimFloat):
150+
def coords_to_point(self, *coords: float):
164151
raise NotImplementedError()
165152

166153
def point_to_coords(self, point: Point3D):
@@ -1849,36 +1836,20 @@ def construct(self):
18491836

18501837
return T_label_group
18511838

1852-
_matmul_config: _MatmulConfig = {
1853-
"method": "coords_to_point",
1854-
"unpack": True,
1855-
}
1856-
_rmatmul_config: _MatmulConfig = {"method": "point_to_coords", "unpack": False}
1857-
1858-
def __matmul__(self, coord):
1839+
def __matmul__(self, coord: Iterable[float] | Mobject):
18591840
if isinstance(coord, Mobject):
18601841
coord = coord.get_center()
1861-
method = getattr(self, self._matmul_config["method"])
1862-
assert callable(method)
1863-
return (
1864-
method(*coord) if self._matmul_config.get("unpack", True) else method(coord)
1865-
)
1842+
return self.coords_to_point(*coord)
18661843

1867-
def __rmatmul__(self, point):
1844+
def __rmatmul__(self, point: Point3D):
18681845
"""Perform a point-to-coords action for a coordinate scene.
18691846
18701847
.. warning::
18711848
18721849
This will not work with NumPy arrays or other objects that
18731850
implement ``__matmul__``.
18741851
"""
1875-
method = getattr(self, self._rmatmul_config["method"])
1876-
assert callable(method)
1877-
return (
1878-
method(*point)
1879-
if self._rmatmul_config.get("unpack", False)
1880-
else method(point)
1881-
)
1852+
return self.point_to_coords(point)
18821853

18831854

18841855
class Axes(VGroup, CoordinateSystem, metaclass=ConvertToOpenGL):
@@ -3020,11 +2991,6 @@ def construct(self):
30202991
self.add(polarplane_pi)
30212992
"""
30222993

3023-
_matmul_config = {
3024-
"method": "polar_to_point",
3025-
}
3026-
_rmatmul_config = {"method": "point_to_polar"}
3027-
30282994
def __init__(
30292995
self,
30302996
radius_max: float = config["frame_y_radius"],
@@ -3368,6 +3334,12 @@ def get_radian_label(self, number, font_size: float = 24, **kwargs: Any) -> Math
33683334

33693335
return MathTex(string, font_size=font_size, **kwargs)
33703336

3337+
def __matmul__(self, coord: Point2D):
3338+
return self.polar_to_point(*coord)
3339+
3340+
def __rmatmul__(self, point: Point2D):
3341+
return self.point_to_polar(point)
3342+
33713343

33723344
class ComplexPlane(NumberPlane):
33733345
"""A :class:`~.NumberPlane` specialized for use with complex numbers.
@@ -3395,10 +3367,6 @@ def construct(self):
33953367
33963368
"""
33973369

3398-
_matmul_config = {"method": "number_to_point", "unpack": False}
3399-
3400-
_rmatmul_config = {"method": "point_to_number"}
3401-
34023370
def __init__(self, **kwargs: Any) -> None:
34033371
super().__init__(
34043372
**kwargs,
@@ -3444,6 +3412,12 @@ def p2n(self, point: Point3D) -> complex:
34443412
"""Abbreviation for :meth:`point_to_number`."""
34453413
return self.point_to_number(point)
34463414

3415+
def __matmul__(self, coord: float | complex):
3416+
return self.number_to_point(coord)
3417+
3418+
def __rmatmul__(self, point: Point3D):
3419+
return self.point_to_number(point)
3420+
34473421
def _get_default_coordinate_values(self) -> list[float | complex]:
34483422
"""Generate a list containing the numerical values of the plane's labels.
34493423

0 commit comments

Comments
 (0)