mirror of
https://github.com/ManimCommunity/manim.git
synced 2026-06-22 10:01:47 +00:00
Add docstrings to Line and remove None handling for path_arc parameter (#4223)
* In Line: simplify _account_for_buff and set default path_arc to 0.0 * In Line: add docstring * change 0.0 to 0 * Use explicit check for path_arc == 0 in _account_for_buff --------- Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
This commit is contained in:
parent
de210bad8b
commit
a2876dc77c
1 changed files with 32 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue