Replace VMobject.make_approximately_smooth with VMobject.make_smooth(approx=True)

This commit is contained in:
Grant Sanderson 2023-01-19 11:34:13 -08:00
parent 6839de9a31
commit 1c2ec03f7d
4 changed files with 15 additions and 27 deletions

View file

@ -252,11 +252,11 @@ class CoordinateSystem(ABC):
xs[:] = sorted([*x_values, *added_xs])[:len(x_values)] xs[:] = sorted([*x_values, *added_xs])[:len(x_values)]
return self.c2p(xs, func(xs)) return self.c2p(xs, func(xs))
graph.add_updater(lambda g: g.set_points_as_corners( graph.add_updater(
get_graph_points() lambda g: g.set_points_as_corners(get_graph_points())
)) )
if not jagged: if not jagged:
graph.add_updater(lambda g: g.make_approximately_smooth()) graph.add_updater(lambda g: g.make_smooth(approx=True))
return graph return graph
def get_graph_label( def get_graph_label(

View file

@ -48,7 +48,7 @@ class ParametricCurve(VMobject):
self.start_new_path(points[0]) self.start_new_path(points[0])
self.add_points_as_corners(points[1:]) self.add_points_as_corners(points[1:])
if self.use_smoothing: if self.use_smoothing:
self.make_approximately_smooth() self.make_smooth(approx=True)
if not self.has_points(): if not self.has_points():
self.set_points(np.array([self.t_func(t_min)])) self.set_points(np.array([self.t_func(t_min)]))
return self return self

View file

@ -578,13 +578,10 @@ class VMobject(Mobject):
def set_points_smoothly( def set_points_smoothly(
self, self,
points: Iterable[Vect3], points: Iterable[Vect3],
true_smooth: bool = False approx: bool = False
): ):
self.set_points_as_corners(points) self.set_points_as_corners(points)
if true_smooth: self.make_smooth(approx=approx)
self.make_smooth()
else:
self.make_approximately_smooth()
return self return self
def is_smooth(self) -> bool: def is_smooth(self) -> bool:
@ -608,32 +605,23 @@ class VMobject(Mobject):
self.add_subpath(new_subpath) self.add_subpath(new_subpath)
return self return self
def make_smooth(self, recurse=True): def make_smooth(self, approx=False, recurse=True):
""" """
Edits the path so as to pass smoothly through all Edits the path so as to pass smoothly through all
the current anchor points. the current anchor points.
This may increase the total number of points. If approx is False, this may increase the total
number of points.
""" """
mode = "approx_smooth" if approx else "true_smooth"
for submob in self.get_family(recurse): for submob in self.get_family(recurse):
if submob.is_smooth(): if submob.is_smooth():
continue continue
submob.change_anchor_mode("true_smooth") submob.change_anchor_mode(mode)
return self return self
def make_approximately_smooth(self, recurse=True): def make_approximately_smooth(self, recurse=True):
""" self.make_smooth(approx=True, recurse=recurse)
Unlike make_smooth, this will not change the number of
points, but it also does not result in a perfectly smooth
curve. It's most useful when the points have been
sampled at a not-too-low rate from a continuous function,
as in the case of ParametricCurve
"""
for submob in self.get_family(recurse):
if submob.is_smooth():
continue
submob.change_anchor_mode("approx_smooth")
return self
def make_jagged(self, recurse=True): def make_jagged(self, recurse=True):
for submob in self.get_family(recurse): for submob in self.get_family(recurse):
@ -1145,7 +1133,7 @@ class VMobject(Mobject):
): ):
super().apply_function(function, **kwargs) super().apply_function(function, **kwargs)
if self.make_smooth_after_applying_functions or make_smooth: if self.make_smooth_after_applying_functions or make_smooth:
self.make_approximately_smooth() self.make_smooth(approx=True)
return self return self
def apply_points_function(self, *args, **kwargs): def apply_points_function(self, *args, **kwargs):

View file

@ -250,7 +250,7 @@ class StreamLines(VGroup):
line.virtual_time = time line.virtual_time = time
step = max(1, int(len(points) / self.n_samples_per_line)) step = max(1, int(len(points) / self.n_samples_per_line))
line.set_points_as_corners(points[::step]) line.set_points_as_corners(points[::step])
line.make_approximately_smooth() line.make_smooth(approx=True)
lines.append(line) lines.append(line)
self.set_submobjects(lines) self.set_submobjects(lines)