Skip to content

geometry: unify generate_points and init_points in Arc #4803

Description

@Drunsdo

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 in manim/mobject/geometry/) for the same duplication pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions