Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add docstrings to `Line` and remove `None` handling for `path_arc` parameter (#4223)

Irvanal Haqa2876dc77c2e
diff --git a/manim/mobject/geometry/line.py b/manim/mobject/geometry/line.py
index be6c3a77b..2f1c37fa1 100644
--- a/manim/mobject/geometry/line.py
+++ b/manim/mobject/geometry/line.py
@@ -65,12 +65,41 @@ if TYPE_CHECKING:
class Line(TipableVMobject):
+ """A straight or curved line segment between two points or mobjects.
+
+ Parameters
+ ----------
+ start
+ The starting point or Mobject of the line.
+ end
+ The ending point or Mobject of the line.
+ buff
+ The distance to shorten the line from both ends.
+ path_arc
+ If nonzero, the line will be curved into an arc with this angle (in radians).
+ kwargs
+ Additional arguments to be passed to :class:`TipableVMobject`
+
+ Examples
+ --------
+ .. manim:: LineExample
+ :save_last_frame:
+
+ class LineExample(Scene):
+ def construct(self):
+ line1 = Line(LEFT*2, RIGHT*2)
+ line2 = Line(LEFT*2, RIGHT*2, buff=0.5)
+ line3 = Line(LEFT*2, RIGHT*2, path_arc=PI/2)
+ grp = VGroup(line1,line2,line3).arrange(DOWN, buff=2)
+ self.add(grp)
+ """
+
def __init__(
self,
start: Point3DLike | Mobject = LEFT,
end: Point3DLike | Mobject = RIGHT,
buff: float = 0,
- path_arc: float | None = None,
+ path_arc: float = 0,
**kwargs: Any,
) -> None:
self.dim = 3
@@ -78,14 +107,13 @@ class Line(TipableVMobject):
self.path_arc = path_arc
self._set_start_and_end_attrs(start, end)
super().__init__(**kwargs)
- # TODO: Deal with the situation where path_arc is None
def generate_points(self) -> None:
self.set_points_by_ends(
start=self.start,
end=self.end,
buff=self.buff,
- path_arc=self.path_arc, # type: ignore[arg-type]
+ path_arc=self.path_arc,
)
def set_points_by_ends(
@@ -112,9 +140,6 @@ class Line(TipableVMobject):
"""
self._set_start_and_end_attrs(start, end)
if path_arc:
- # self.path_arc could potentially be None, which is not accepted
- # as parameter.
- assert self.path_arc is not None
arc = ArcBetweenPoints(self.start, self.end, angle=self.path_arc)
self.set_points(arc.points)
else:
@@ -125,16 +150,13 @@ class Line(TipableVMobject):
init_points = generate_points
def _account_for_buff(self, buff: float) -> None:
- if buff == 0:
+ 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)
- return
def _set_start_and_end_attrs(
self, start: Point3DLike | Mobject, end: Point3DLike | Mobject