-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Improve @
operator to work on different coordinate systems
#3879
base: main
Are you sure you want to change the base?
Changes from all commits
56187a6
827d9f5
f952d52
ad78681
1c68e52
ccdd84c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -147,7 +147,7 @@ def __init__( | |||||
self.y_length = y_length | ||||||
self.num_sampled_graph_points_per_tick = 10 | ||||||
|
||||||
def coords_to_point(self, *coords: ManimFloat): | ||||||
def coords_to_point(self, *coords: float): | ||||||
raise NotImplementedError() | ||||||
|
||||||
def point_to_coords(self, point: Point3D): | ||||||
|
@@ -1836,12 +1836,19 @@ def construct(self): | |||||
|
||||||
return T_label_group | ||||||
|
||||||
def __matmul__(self, coord: Point3D | Mobject): | ||||||
def __matmul__(self, coord: Iterable[float] | Mobject): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left a suggestion regarding the return type. About the parameter type, I'm not sure. The Liskov substitution principle says that, when overriding methods, parameter types are contravariant and return types are covariant, which means that the parameter type cannot get more specific when overriding a method. It can only get broader or stay the same. The reverse is true for return types. Maybe the parameter type could be
Suggested change
|
||||||
if isinstance(coord, Mobject): | ||||||
coord = coord.get_center() | ||||||
return self.coords_to_point(*coord) | ||||||
|
||||||
def __rmatmul__(self, point: Point3D): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the return type should be something like this?
Suggested change
|
||||||
"""Perform a point-to-coords action for a coordinate scene. | ||||||
|
||||||
.. warning:: | ||||||
|
||||||
This will not work with NumPy arrays or other objects that | ||||||
implement ``__matmul__``. | ||||||
""" | ||||||
return self.point_to_coords(point) | ||||||
|
||||||
|
||||||
|
@@ -3327,6 +3334,12 @@ def get_radian_label(self, number, font_size: float = 24, **kwargs: Any) -> Math | |||||
|
||||||
return MathTex(string, font_size=font_size, **kwargs) | ||||||
|
||||||
def __matmul__(self, coord: Point2D): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return self.polar_to_point(*coord) | ||||||
|
||||||
def __rmatmul__(self, point: Point2D): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return self.point_to_polar(point) | ||||||
|
||||||
|
||||||
class ComplexPlane(NumberPlane): | ||||||
"""A :class:`~.NumberPlane` specialized for use with complex numbers. | ||||||
|
@@ -3399,6 +3412,12 @@ def p2n(self, point: Point3D) -> complex: | |||||
"""Abbreviation for :meth:`point_to_number`.""" | ||||||
return self.point_to_number(point) | ||||||
|
||||||
def __matmul__(self, coord: float | complex): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that
Suggested change
|
||||||
return self.number_to_point(coord) | ||||||
|
||||||
def __rmatmul__(self, point: Point3D): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return self.point_to_number(point) | ||||||
|
||||||
def _get_default_coordinate_values(self) -> list[float | complex]: | ||||||
"""Generate a list containing the numerical values of the plane's labels. | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.