|
17 | 17 | from typing import TYPE_CHECKING, Any, Callable, TypeVar, overload |
18 | 18 |
|
19 | 19 | import numpy as np |
20 | | -from typing_extensions import NotRequired, Self, TypedDict |
| 20 | +from typing_extensions import Self |
21 | 21 |
|
22 | 22 | from manim import config |
23 | 23 | from manim.constants import * |
|
62 | 62 | LineType = TypeVar("LineType", bound=Line) |
63 | 63 |
|
64 | 64 |
|
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 | | - |
78 | 65 | class CoordinateSystem: |
79 | 66 | r"""Abstract base class for Axes and NumberPlane. |
80 | 67 |
|
@@ -160,7 +147,7 @@ def __init__( |
160 | 147 | self.y_length = y_length |
161 | 148 | self.num_sampled_graph_points_per_tick = 10 |
162 | 149 |
|
163 | | - def coords_to_point(self, *coords: ManimFloat): |
| 150 | + def coords_to_point(self, *coords: float): |
164 | 151 | raise NotImplementedError() |
165 | 152 |
|
166 | 153 | def point_to_coords(self, point: Point3D): |
@@ -1849,36 +1836,20 @@ def construct(self): |
1849 | 1836 |
|
1850 | 1837 | return T_label_group |
1851 | 1838 |
|
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): |
1859 | 1840 | if isinstance(coord, Mobject): |
1860 | 1841 | 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) |
1866 | 1843 |
|
1867 | | - def __rmatmul__(self, point): |
| 1844 | + def __rmatmul__(self, point: Point3D): |
1868 | 1845 | """Perform a point-to-coords action for a coordinate scene. |
1869 | 1846 |
|
1870 | 1847 | .. warning:: |
1871 | 1848 |
|
1872 | 1849 | This will not work with NumPy arrays or other objects that |
1873 | 1850 | implement ``__matmul__``. |
1874 | 1851 | """ |
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) |
1882 | 1853 |
|
1883 | 1854 |
|
1884 | 1855 | class Axes(VGroup, CoordinateSystem, metaclass=ConvertToOpenGL): |
@@ -3020,11 +2991,6 @@ def construct(self): |
3020 | 2991 | self.add(polarplane_pi) |
3021 | 2992 | """ |
3022 | 2993 |
|
3023 | | - _matmul_config = { |
3024 | | - "method": "polar_to_point", |
3025 | | - } |
3026 | | - _rmatmul_config = {"method": "point_to_polar"} |
3027 | | - |
3028 | 2994 | def __init__( |
3029 | 2995 | self, |
3030 | 2996 | radius_max: float = config["frame_y_radius"], |
@@ -3368,6 +3334,12 @@ def get_radian_label(self, number, font_size: float = 24, **kwargs: Any) -> Math |
3368 | 3334 |
|
3369 | 3335 | return MathTex(string, font_size=font_size, **kwargs) |
3370 | 3336 |
|
| 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 | + |
3371 | 3343 |
|
3372 | 3344 | class ComplexPlane(NumberPlane): |
3373 | 3345 | """A :class:`~.NumberPlane` specialized for use with complex numbers. |
@@ -3395,10 +3367,6 @@ def construct(self): |
3395 | 3367 |
|
3396 | 3368 | """ |
3397 | 3369 |
|
3398 | | - _matmul_config = {"method": "number_to_point", "unpack": False} |
3399 | | - |
3400 | | - _rmatmul_config = {"method": "point_to_number"} |
3401 | | - |
3402 | 3370 | def __init__(self, **kwargs: Any) -> None: |
3403 | 3371 | super().__init__( |
3404 | 3372 | **kwargs, |
@@ -3444,6 +3412,12 @@ def p2n(self, point: Point3D) -> complex: |
3444 | 3412 | """Abbreviation for :meth:`point_to_number`.""" |
3445 | 3413 | return self.point_to_number(point) |
3446 | 3414 |
|
| 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 | + |
3447 | 3421 | def _get_default_coordinate_values(self) -> list[float | complex]: |
3448 | 3422 | """Generate a list containing the numerical values of the plane's labels. |
3449 | 3423 |
|
|
0 commit comments