Skip to content

Commit 845dc3e

Browse files
Add test for __rmatmul__ and add warning
1 parent 610f736 commit 845dc3e

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

manim/mobject/graphing/coordinate_systems.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,13 @@ def __matmul__(self, coord):
18201820
)
18211821

18221822
def __rmatmul__(self, point):
1823+
"""Perform a point-to-coords action for a coordinate scene.
1824+
1825+
.. warning::
1826+
1827+
This will not work with NumPy arrays or other objects that
1828+
implement ``__matmul__``.
1829+
"""
18231830
method = getattr(self, self._rmatmul_config["method"])
18241831
assert callable(method)
18251832
return (

tests/module/mobject/graphing/test_coordinate_system.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,27 @@ def test_matmul_operations():
212212
# Numberline doesn't inherit from CoordinateSystem, but it should still work
213213
n = NumberLine()
214214
assert (n @ 3 == n.number_to_point(3)).all()
215-
mob = Dot().move_to(n @ 3)
216-
assert mob @ n == n.point_to_number(mob.get_center())
215+
216+
217+
def test_rmatmul_operations():
218+
point = (1, 2, 0)
219+
220+
ax = Axes()
221+
assert (point @ ax == ax.point_to_coords(point)).all()
222+
223+
polar = PolarPlane()
224+
assert point @ polar == polar.point_to_polar(point)
225+
226+
complx = ComplexPlane()
227+
assert point @ complx == complx.point_to_number(point)
228+
229+
n = NumberLine()
230+
point = n @ 4
231+
232+
assert (
233+
tuple(point) @ n # ndarray overrides __matmul__
234+
== n.point_to_number(point)
235+
).all()
236+
237+
mob = Dot().move_to(point)
238+
assert (mob @ n == n.point_to_number(mob.get_center())).all()

0 commit comments

Comments
 (0)