Repository: ManimCommunity/manim
File: manim/mobject/svg/svg_mobject.py (Python)

Code before:
        self.long_lines = long_lines
        self.should_subdivide_sharp_curves = should_subdivide_sharp_curves
        self.should_remove_null_curves = should_remove_null_curves

        super().__init__(**kwargs)

    def init_points(self) -> None:
        # TODO: cache mobject in a re-importable way

        self.handle_commands()

        if config.renderer == "opengl":
            if self.should_subdivide_sharp_curves:
                # For a healthy triangulation later
                self.subdivide_sharp_curves()
            if self.should_remove_null_curves:
                # Get rid of any null curves
                self.set_points(self.get_points_without_null_curves())

    generate_points = init_points

    def handle_commands(self) -> None:
        all_points: list[np.ndarray] = []
        last_move: np.ndarray = None
        curve_start = None
        last_true_move = None

        def move_pen(pt: np.ndarray, *, true_move: bool = False) -> None:
            nonlocal last_move, curve_start, last_true_move
            last_move = pt
            if curve_start is None:
                curve_start = last_move
            if true_move:
                last_true_move = last_move

        if self.n_points_per_curve == 4:

            def add_cubic(
                start: np.ndarray, cp1: np.ndarray, cp2: np.ndarray, end: np.ndarray
            ) -> None:
                nonlocal all_points
                assert len(all_points) % 4 == 0, len(all_points)
                all_points += [start, cp1, cp2, end]
                move_pen(end)

            def add_quad(start: np.ndarray, cp: np.ndarray, end: np.ndarray) -> None:
                add_cubic(start, (start + cp + cp) / 3, (cp + cp + end) / 3, end)
                move_pen(end)

            def add_line(start: np.ndarray, end: np.ndarray) -> None:
                add_cubic(

Review comment (suggestion):
The `np.ndarray` type seems to work here. But is there any better? I don't think it should be `Point3DLike`.

Code after:
        self.path_obj = path_obj

        self.long_lines = long_lines
        self.should_subdivide_sharp_curves = should_subdivide_sharp_curves
        self.should_remove_null_curves = should_remove_null_curves

        super().__init__(**kwargs)

    def init_points(self) -> None:
        # TODO: cache mobject in a re-importable way

        self.handle_commands()

        if config.renderer == "opengl":
            if self.should_subdivide_sharp_curves:
                # For a healthy triangulation later
                self.subdivide_sharp_curves()
            if self.should_remove_null_curves:
                # Get rid of any null curves
                self.set_points(self.get_points_without_null_curves())

    generate_points = init_points

    def handle_commands(self) -> None:
        all_points: list[np.ndarray] = []
        last_move: np.ndarray = None
        curve_start = None
        last_true_move = None

        def move_pen(pt: np.ndarray, *, true_move: bool = False) -> None:
            nonlocal last_move, curve_start, last_true_move
            last_move = pt
            if curve_start is None:
                curve_start = last_move
            if true_move:
                last_true_move = last_move

        if self.n_points_per_curve == 4:

            def add_cubic(
                start: np.ndarray, cp1: np.ndarray, cp2: np.ndarray, end: np.ndarray
            ) -> None:
                nonlocal all_points
                assert len(all_points) % 4 == 0, len(all_points)
                all_points += [start, cp1, cp2, end]
                move_pen(end)

            def add_quad(start: np.ndarray, cp: np.ndarray, end: np.ndarray) -> None:
                add_cubic(start, (start + cp + cp) / 3, (cp + cp + end) / 3, end)
                move_pen(end)