Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions manim/mobject/svg/svg_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,17 +510,15 @@ def handle_commands(self) -> None:
all_points: list[np.ndarray] = []
last_move = None
curve_start = None
last_true_move = None

# These lambdas behave the same as similar functions in
# vectorized_mobject, except they add to a list of points instead
# of updating this Mobject's numpy array of points. This way,
# we don't observe O(n^2) behavior for complex paths due to
# numpy's need to re-allocate memory on every append.
def move_pen(pt):
nonlocal last_move, curve_start
def move_pen(pt, true_move=False):
nonlocal last_move, curve_start, last_true_move
last_move = pt
if curve_start is None:
curve_start = last_move
if true_move:
last_true_move = last_move

if self.n_points_per_curve == 4:

Expand Down Expand Up @@ -568,7 +566,7 @@ def add_line(start, end):
for segment in self.path_obj:
segment_class = segment.__class__
if segment_class == se.Move:
move_pen(_convert_point_to_3d(*segment.end))
move_pen(_convert_point_to_3d(*segment.end), True)
elif segment_class == se.Line:
add_line(last_move, _convert_point_to_3d(*segment.end))
elif segment_class == se.QuadraticBezier:
Expand All @@ -588,8 +586,8 @@ def add_line(start, end):
# If the SVG path naturally ends at the beginning of the curve,
# we do *not* need to draw a closing line. To account for floating
# point precision, we use a small value to compare the two points.
if abs(np.linalg.norm(last_move - curve_start)) > 0.0001:
add_line(last_move, curve_start)
if abs(np.linalg.norm(last_move - last_true_move)) > 0.0001:
add_line(last_move, last_true_move)
curve_start = None
else:
raise AssertionError(f"Not implemented: {segment_class}")
Expand Down