mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Speed up bind_graph_to_func
This commit is contained in:
parent
148898f983
commit
e6abff4299
1 changed files with 9 additions and 10 deletions
|
@ -54,7 +54,7 @@ class CoordinateSystem(ABC):
|
||||||
self,
|
self,
|
||||||
x_range: RangeSpecifier = DEFAULT_X_RANGE,
|
x_range: RangeSpecifier = DEFAULT_X_RANGE,
|
||||||
y_range: RangeSpecifier = DEFAULT_Y_RANGE,
|
y_range: RangeSpecifier = DEFAULT_Y_RANGE,
|
||||||
num_sampled_graph_points_per_tick: int = 20,
|
num_sampled_graph_points_per_tick: int = 5,
|
||||||
):
|
):
|
||||||
self.x_range = x_range
|
self.x_range = x_range
|
||||||
self.y_range = y_range
|
self.y_range = y_range
|
||||||
|
@ -241,21 +241,20 @@ class CoordinateSystem(ABC):
|
||||||
Use for graphing functions which might change over time, or change with
|
Use for graphing functions which might change over time, or change with
|
||||||
conditions
|
conditions
|
||||||
"""
|
"""
|
||||||
x_values = [self.x_axis.p2n(p) for p in graph.get_points()]
|
x_values = np.array([self.x_axis.p2n(p) for p in graph.get_points()])
|
||||||
|
|
||||||
def get_x_values():
|
def get_graph_points():
|
||||||
|
xs = x_values
|
||||||
if get_discontinuities:
|
if get_discontinuities:
|
||||||
ds = get_discontinuities()
|
ds = get_discontinuities()
|
||||||
ep = 1e-6
|
ep = 1e-6
|
||||||
added_xs = it.chain(*((d - ep, d + ep) for d in ds))
|
added_xs = it.chain(*((d - ep, d + ep) for d in ds))
|
||||||
return sorted([*x_values, *added_xs])[:len(x_values)]
|
xs[:] = sorted([*x_values, *added_xs])[:len(x_values)]
|
||||||
else:
|
return self.c2p(xs, func(xs))
|
||||||
return x_values
|
|
||||||
|
|
||||||
graph.add_updater(lambda g: g.set_points_as_corners([
|
graph.add_updater(lambda g: g.set_points_as_corners(
|
||||||
self.c2p(x, func(x))
|
get_graph_points()
|
||||||
for x in get_x_values()
|
))
|
||||||
]))
|
|
||||||
if not jagged:
|
if not jagged:
|
||||||
graph.add_updater(lambda g: g.make_approximately_smooth())
|
graph.add_updater(lambda g: g.make_approximately_smooth())
|
||||||
return graph
|
return graph
|
||||||
|
|
Loading…
Add table
Reference in a new issue