6565
6666
6767class Line (TipableVMobject ):
68+ """A straight or curved line segment between two points or mobjects.
69+
70+ Parameters
71+ ----------
72+ start
73+ The starting point or Mobject of the line.
74+ end
75+ The ending point or Mobject of the line.
76+ buff
77+ The distance to shorten the line from both ends.
78+ path_arc
79+ If nonzero, the line will be curved into an arc with this angle (in radians).
80+ kwargs
81+ Additional arguments to be passed to :class:`TipableVMobject`
82+
83+ Examples
84+ --------
85+ .. manim:: LineExample
86+ :save_last_frame:
87+
88+ class LineExample(Scene):
89+ def construct(self):
90+ line1 = Line(LEFT*2, RIGHT*2)
91+ line2 = Line(LEFT*2, RIGHT*2, buff=0.5)
92+ line3 = Line(LEFT*2, RIGHT*2, path_arc=PI/2)
93+ grp = VGroup(line1,line2,line3).arrange(DOWN, buff=2)
94+ self.add(grp)
95+ """
96+
6897 def __init__ (
6998 self ,
7099 start : Point3DLike | Mobject = LEFT ,
71100 end : Point3DLike | Mobject = RIGHT ,
72101 buff : float = 0 ,
73- path_arc : float | None = None ,
102+ path_arc : float = 0 ,
74103 ** kwargs : Any ,
75104 ) -> None :
76105 self .dim = 3
77106 self .buff = buff
78107 self .path_arc = path_arc
79108 self ._set_start_and_end_attrs (start , end )
80109 super ().__init__ (** kwargs )
81- # TODO: Deal with the situation where path_arc is None
82110
83111 def generate_points (self ) -> None :
84112 self .set_points_by_ends (
85113 start = self .start ,
86114 end = self .end ,
87115 buff = self .buff ,
88- path_arc = self .path_arc , # type: ignore[arg-type]
116+ path_arc = self .path_arc ,
89117 )
90118
91119 def set_points_by_ends (
@@ -112,9 +140,6 @@ def set_points_by_ends(
112140 """
113141 self ._set_start_and_end_attrs (start , end )
114142 if path_arc :
115- # self.path_arc could potentially be None, which is not accepted
116- # as parameter.
117- assert self .path_arc is not None
118143 arc = ArcBetweenPoints (self .start , self .end , angle = self .path_arc )
119144 self .set_points (arc .points )
120145 else :
@@ -125,16 +150,13 @@ def set_points_by_ends(
125150 init_points = generate_points
126151
127152 def _account_for_buff (self , buff : float ) -> None :
128- if buff = = 0 :
153+ if buff < = 0 :
129154 return
130- #
131155 length = self .get_length () if self .path_arc == 0 else self .get_arc_length ()
132- #
133156 if length < 2 * buff :
134157 return
135158 buff_proportion = buff / length
136159 self .pointwise_become_partial (self , buff_proportion , 1 - buff_proportion )
137- return
138160
139161 def _set_start_and_end_attrs (
140162 self , start : Point3DLike | Mobject , end : Point3DLike | Mobject
0 commit comments