Don't get rid of null curves each frame, instead do it once for SVG mobjects.

This commit is contained in:
Grant Sanderson
2020-06-09 20:39:32 -07:00
parent cf8790eefa
commit a4d4ae9b47
2 changed files with 4 additions and 6 deletions

View File

@ -329,7 +329,7 @@ class VMobjectFromSVGPathstring(VMobject):
def __init__(self, path_string, **kwargs):
self.path_string = path_string
VMobject.__init__(self, **kwargs)
super().__init__(**kwargs)
def init_points(self):
# TODO, move this caching operation
@ -355,10 +355,10 @@ class VMobjectFromSVGPathstring(VMobject):
self.subdivide_sharp_curves()
# SVG treats y-coordinate differently
self.stretch(-1, 1, about_point=ORIGIN)
# Get rid of any null curves
self.points = self.get_points_without_null_curves()
# Save to a file for future use
np.save(filepath, self.points)
# Faster rendering
self.lock_triangulation()
def get_commands_and_coord_strings(self):
all_commands = list(self.get_command_to_function_map().keys())

View File

@ -608,8 +608,6 @@ class VMobject(Mobject):
def get_points_without_null_curves(self, atol=1e-9):
nppc = self.n_points_per_curve
if len(self.points) <= nppc + 1:
return self.points
distinct_curves = reduce(op.or_, [
(abs(self.points[i::nppc] - self.points[0::nppc]) > atol).any(1)
for i in range(1, nppc)
@ -912,7 +910,7 @@ class VMobject(Mobject):
if len(stroke_width) > 1:
stroke_width = self.stretched_style_array_matching_points(stroke_width)
points = self.get_points_without_null_curves()
points = self.points
nppc = self.n_points_per_curve
data = self.get_blank_shader_data_array(len(points), "stroke_data")