diff --git a/manimlib/mobject/functions.py b/manimlib/mobject/functions.py index 495b3e67..11e8daf5 100644 --- a/manimlib/mobject/functions.py +++ b/manimlib/mobject/functions.py @@ -30,39 +30,17 @@ class ParametricCurve(VMobject): return self.t_func(t) def init_points(self): - # TODO, this seems like a mess. t_min, t_max, step = self.t_range - epsilon = self.epsilon - discontinuities = filter( - lambda t: t_min <= t <= t_max, - self.discontinuities - ) - discontinuities = np.array(list(discontinuities)) - boundary_times = [ - t_min, t_max, - *(discontinuities - epsilon), - *(discontinuities + epsilon), - ] + jumps = np.array(self.discontinuities) + jumps = jumps[(jumps > t_min) & (jumps < t_max)] + boundary_times = [t_min, t_max, *(jumps - self.epsilon), *(jumps + self.epsilon)] boundary_times.sort() for t1, t2 in zip(boundary_times[0::2], boundary_times[1::2]): - # Get an initial sample of points - t_range = list(np.linspace(t1, t2, self.min_samples + 1)) - samples = np.array([self.t_func(t) for t in t_range]) - - # Take more samples based on the distances between them - norms = [get_norm(p2 - p1) for p1, p2 in zip(samples, samples[1:])] - full_t_range = [t1] - for s1, s2, norm in zip(t_range, t_range[1:], norms): - n_inserts = int(norm / step) - full_t_range += list(np.linspace(s1, s2, n_inserts + 1)[1:]) - - points = np.array([self.t_func(t) for t in full_t_range]) - valid_indices = np.isfinite(points).all(1) - points = points[valid_indices] - if len(points) > 0: - self.start_new_path(points[0]) - self.add_points_as_corners(points[1:]) + t_range = [*np.arange(t1, t2, step), t2] + points = np.array([self.t_func(t) for t in t_range]) + self.start_new_path(points[0]) + self.add_points_as_corners(points[1:]) self.make_smooth() return self @@ -70,7 +48,7 @@ class ParametricCurve(VMobject): class FunctionGraph(ParametricCurve): CONFIG = { "color": YELLOW, - "x_range": [-8, 8, 0.5], + "x_range": [-8, 8, 0.25], } def __init__(self, function, x_range=None, **kwargs):