manim icon indicating copy to clipboard operation
manim copied to clipboard

graphing: align coords_to_point return type in base class with subclass behaviour

Open Drunsdo opened this issue 5 months ago • 1 comments

Source

manim/mobject/graphing/coordinate_systems.py, line 159 (as of HEAD ):

def coords_to_point(self, *coords: ManimFloat) -> Point3D:
        # TODO: I think the method should be able to return more than just a single point.
        # E.g. see the implementation of it on line 2065.
        raise NotImplementedError()

(Note: the "line 2065" reference in the original TODO is stale. The concrete implementations of coords_to_point live in subclasses such as Axes and NumberPlane, see def coords_to_point matches in the same file.)

Problem

The abstract coords_to_point declares a return type of Point3D (a single point), but the concrete implementations in subclasses return multiple points when given multiple input coordinates. The base class signature is inconsistent with the actual behaviour of its subclasses.

This affects:

  • Type checkers, which will accept code that breaks at runtime.
  • Users reading the API, who cannot infer that batch input is supported.
  • Future implementers of the abstract base, who may write a single-point-only override that is incompatible with how callers use the method.

Suggested approaches

  • Change the return type annotation in the base class to reflect the batch behaviour, e.g. Point3D | list[Point3D] or Point3D | npt.NDArray.
  • Audit all subclass implementations to confirm they handle both single-coord and multi-coord input consistently.
  • Update point_to_coords similarly if it has the same gap.

Drunsdo avatar Jun 12 '26 16:06 Drunsdo

PR #4848 aligns the base coords_to_point/point_to_coords/p2c annotations with the Axes/NumberPlane implementations (batch coords, np.ndarray return) and drops the stale TODO.

chessing234 avatar Jun 30 '26 10:06 chessing234