Repository: ManimCommunity/manim
File: manim/mobject/geometry/line.py (Python)

Code before:
        Parameters
        ----------
        start
            The start point or Mobject of the line.
        end
            The end point or Mobject of the line.
        buff
            The empty space between the start and end of the line, by default 0.
        path_arc
            The angle of a circle spanned by this arc, by default 0 which is a straight line.
        """
        self._set_start_and_end_attrs(start, end)
        if path_arc:
            arc = ArcBetweenPoints(self.start, self.end, angle=self.path_arc)
            self.set_points(arc.points)
        else:
            self.set_points_as_corners(np.asarray([self.start, self.end]))

        self._account_for_buff(buff)

    init_points = generate_points

    def _account_for_buff(self, buff: float) -> None:
        if buff <= 0:
            return
        length = self.get_arc_length() if self.path_arc else self.get_length()
        if length < 2 * buff:
            return
        buff_proportion = buff / length
        self.pointwise_become_partial(self, buff_proportion, 1 - buff_proportion)

    def _set_start_and_end_attrs(
        self, start: Point3DLike | Mobject, end: Point3DLike | Mobject
    ) -> None:
        # If either start or end are Mobjects, this
        # gives their centers
        rough_start = self._pointify(start)
        rough_end = self._pointify(end)
        vect = normalize(rough_end - rough_start)
        # Now that we know the direction between them,
        # we can find the appropriate boundary point from
        # start and end, if they're mobjects
        self.start = self._pointify(start, vect)
        self.end = self._pointify(end, -vect)

    def _pointify(
        self,
        mob_or_point: Mobject | Point3DLike,
        direction: Vector3D | None = None,
    ) -> Point3D:
        """Transforms a mobject into its corresponding point. Does nothing if a point is passed.

Review comment (suggestion):
Since `self.path_arc` is now always a `float`, the previous method with `if self.path_arc == 0` is a better option, because it's more explicit. Using `if variable` is best when `variable` is known to be a bool or possibly `None`.

Code after:
        Parameters
        ----------
        start
            The start point or Mobject of the line.
        end
            The end point or Mobject of the line.
        buff
            The empty space between the start and end of the line, by default 0.
        path_arc
            The angle of a circle spanned by this arc, by default 0 which is a straight line.
        """
        self._set_start_and_end_attrs(start, end)
        if path_arc:
            arc = ArcBetweenPoints(self.start, self.end, angle=self.path_arc)
            self.set_points(arc.points)
        else:
            self.set_points_as_corners(np.asarray([self.start, self.end]))

        self._account_for_buff(buff)

    init_points = generate_points

    def _account_for_buff(self, buff: float) -> None:
        if buff <= 0:
            return
        length = self.get_length() if self.path_arc == 0 else self.get_arc_length()
        if length < 2 * buff:
            return
        buff_proportion = buff / length
        self.pointwise_become_partial(self, buff_proportion, 1 - buff_proportion)

    def _set_start_and_end_attrs(
        self, start: Point3DLike | Mobject, end: Point3DLike | Mobject
    ) -> None:
        # If either start or end are Mobjects, this
        # gives their centers
        rough_start = self._pointify(start)
        rough_end = self._pointify(end)
        vect = normalize(rough_end - rough_start)
        # Now that we know the direction between them,
        # we can find the appropriate boundary point from
        # start and end, if they're mobjects
        self.start = self._pointify(start, vect)
        self.end = self._pointify(end, -vect)

    def _pointify(
        self,
        mob_or_point: Mobject | Point3DLike,
        direction: Vector3D | None = None,
    ) -> Point3D:
        """Transforms a mobject into its corresponding point. Does nothing if a point is passed.