65
65
66
66
67
67
class 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
+
68
97
def __init__ (
69
98
self ,
70
99
start : Point3DLike | Mobject = LEFT ,
71
100
end : Point3DLike | Mobject = RIGHT ,
72
101
buff : float = 0 ,
73
- path_arc : float | None = None ,
102
+ path_arc : float = 0 ,
74
103
** kwargs : Any ,
75
104
) -> None :
76
105
self .dim = 3
77
106
self .buff = buff
78
107
self .path_arc = path_arc
79
108
self ._set_start_and_end_attrs (start , end )
80
109
super ().__init__ (** kwargs )
81
- # TODO: Deal with the situation where path_arc is None
82
110
83
111
def generate_points (self ) -> None :
84
112
self .set_points_by_ends (
85
113
start = self .start ,
86
114
end = self .end ,
87
115
buff = self .buff ,
88
- path_arc = self .path_arc , # type: ignore[arg-type]
116
+ path_arc = self .path_arc ,
89
117
)
90
118
91
119
def set_points_by_ends (
@@ -112,9 +140,6 @@ def set_points_by_ends(
112
140
"""
113
141
self ._set_start_and_end_attrs (start , end )
114
142
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
118
143
arc = ArcBetweenPoints (self .start , self .end , angle = self .path_arc )
119
144
self .set_points (arc .points )
120
145
else :
@@ -125,16 +150,13 @@ def set_points_by_ends(
125
150
init_points = generate_points
126
151
127
152
def _account_for_buff (self , buff : float ) -> None :
128
- if buff = = 0 :
153
+ if buff < = 0 :
129
154
return
130
- #
131
155
length = self .get_length () if self .path_arc == 0 else self .get_arc_length ()
132
- #
133
156
if length < 2 * buff :
134
157
return
135
158
buff_proportion = buff / length
136
159
self .pointwise_become_partial (self , buff_proportion , 1 - buff_proportion )
137
- return
138
160
139
161
def _set_start_and_end_attrs (
140
162
self , start : Point3DLike | Mobject , end : Point3DLike | Mobject
0 commit comments