Skip to content

Commit d5cdd79

Browse files
Nikhil-42pre-commit-ci[bot]chopan050
authored
Fix DiGraph edges not fading correctly on FadeIn and FadeOut (#3786)
* Make `Line::set_points_by_ends` behavior consistent with constructor * Use `Line::set_points_by_ends` in edge updaters * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Undo unnecessary change to Graph * Update manim/mobject/geometry/line.py Co-authored-by: Francisco Manríquez Novoa <[email protected]> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Francisco Manríquez Novoa <[email protected]>
1 parent fdb4e37 commit d5cdd79

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

manim/mobject/geometry/line.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
class Line(TipableVMobject):
4242
def __init__(
4343
self,
44-
start: Point3D = LEFT,
45-
end: Point3D = RIGHT,
44+
start: Point3D | Mobject = LEFT,
45+
end: Point3D | Mobject = RIGHT,
4646
buff: float = 0,
4747
path_arc: float | None = None,
4848
**kwargs,
@@ -63,16 +63,32 @@ def generate_points(self) -> None:
6363

6464
def set_points_by_ends(
6565
self,
66-
start: Point3D,
67-
end: Point3D,
66+
start: Point3D | Mobject,
67+
end: Point3D | Mobject,
6868
buff: float = 0,
6969
path_arc: float = 0,
7070
) -> None:
71+
"""Sets the points of the line based on its start and end points.
72+
Unlike :meth:`put_start_and_end_on`, this method respects `self.buff` and
73+
Mobject bounding boxes.
74+
75+
Parameters
76+
----------
77+
start
78+
The start point or Mobject of the line.
79+
end
80+
The end point or Mobject of the line.
81+
buff
82+
The empty space between the start and end of the line, by default 0.
83+
path_arc
84+
The angle of a circle spanned by this arc, by default 0 which is a straight line.
85+
"""
86+
self._set_start_and_end_attrs(start, end)
7187
if path_arc:
7288
arc = ArcBetweenPoints(self.start, self.end, angle=self.path_arc)
7389
self.set_points(arc.points)
7490
else:
75-
self.set_points_as_corners([start, end])
91+
self.set_points_as_corners([self.start, self.end])
7692

7793
self._account_for_buff(buff)
7894

@@ -93,7 +109,9 @@ def _account_for_buff(self, buff: float) -> Self:
93109
self.pointwise_become_partial(self, buff_proportion, 1 - buff_proportion)
94110
return self
95111

96-
def _set_start_and_end_attrs(self, start: Point3D, end: Point3D) -> None:
112+
def _set_start_and_end_attrs(
113+
self, start: Point3D | Mobject, end: Point3D | Mobject
114+
) -> None:
97115
# If either start or end are Mobjects, this
98116
# gives their centers
99117
rough_start = self._pointify(start)

manim/mobject/graph.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ class GenericGraph(VMobject, metaclass=ConvertToOpenGL):
561561
all other configuration options for a vertex.
562562
edge_type
563563
The mobject class used for displaying edges in the scene.
564+
Must be a subclass of :class:`~.Line` for default updaters to work.
564565
edge_config
565566
Either a dictionary containing keyword arguments to be passed
566567
to the class specified via ``edge_type``, or a dictionary whose
@@ -1559,7 +1560,12 @@ def _populate_edge_dict(
15591560
def update_edges(self, graph):
15601561
for (u, v), edge in graph.edges.items():
15611562
# Undirected graph has a Line edge
1562-
edge.put_start_and_end_on(graph[u].get_center(), graph[v].get_center())
1563+
edge.set_points_by_ends(
1564+
graph[u].get_center(),
1565+
graph[v].get_center(),
1566+
buff=self._edge_config.get("buff", 0),
1567+
path_arc=self._edge_config.get("path_arc", 0),
1568+
)
15631569

15641570
def __repr__(self: Graph) -> str:
15651571
return f"Undirected graph on {len(self.vertices)} vertices and {len(self.edges)} edges"
@@ -1768,10 +1774,15 @@ def update_edges(self, graph):
17681774
deformed.
17691775
"""
17701776
for (u, v), edge in graph.edges.items():
1771-
edge_type = type(edge)
17721777
tip = edge.pop_tips()[0]
1773-
new_edge = edge_type(self[u], self[v], **self._edge_config[(u, v)])
1774-
edge.become(new_edge)
1778+
# Passing the Mobject instead of the vertex makes the tip
1779+
# stop on the bounding box of the vertex.
1780+
edge.set_points_by_ends(
1781+
graph[u],
1782+
graph[v],
1783+
buff=self._edge_config.get("buff", 0),
1784+
path_arc=self._edge_config.get("path_arc", 0),
1785+
)
17751786
edge.add_tip(tip)
17761787

17771788
def __repr__(self: DiGraph) -> str:

0 commit comments

Comments
 (0)