geometry: unify generate_points and init_points in Arc
Source
manim/mobject/geometry/arc.py, line 345 (as of HEAD
def generate_points(self) -> None:
self._set_pre_positioned_points()
self.scale(self.radius, about_point=ORIGIN)
self.shift(self.arc_center)
# Points are set a bit differently when rendering via OpenGL.
# TODO: refactor Arc so that only one strategy for setting points
# has to be used.
def init_points(self) -> None:
self.set_points(
Arc._create_quadratic_bezier_points(
angle=self.angle,
start_angle=self.start_angle,
n_components=self.num_components,
),
)
self.scale(self.radius, about_point=ORIGIN)
self.shift(self.arc_center)
Problem
The Arc class exposes two methods that compute and position points in slightly different ways: generate_points() and init_points(). The duplication exists because the Cairo and OpenGL renderers historically needed different point-setting strategies. The trailing operations (scale and shift) are identical between the two.
Maintaining both methods doubles the surface for regressions — any change to how arc points are positioned has to be made in both places, and it is easy to update one and forget the other.
Suggested approaches
- Extract the common scale/shift tail into a helper, and have both methods delegate the actual point computation to a single strategy selected by renderer type.
- Investigate whether the Cairo/OpenGL distinction is still necessary, or whether the codebase has converged enough that a single point-setting routine suffices.
- Audit related geometry classes (subclasses of
Arc, and other shapes inmanim/mobject/geometry/) for the same duplication pattern.
Hi! I'd like to work on this issue as part of a university course. Unless someone is already on it, I'll open a PR soon. Thanks!