Skip to content
Merged
Changes from 3 commits
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
33 changes: 32 additions & 1 deletion manim/utils/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,38 @@ def get_quadratic_approximation_of_cubic(


def is_closed(points: Point3D_Array) -> bool:
return np.allclose(points[0], points[-1]) # type: ignore
"""Returns ``True`` if the spline given by ``points`` is closed, by
checking if its first and last points are close to each other, or``False``
otherwise.

.. note::

This function reimplements :meth:`np.allclose`, because repeated
calling of :meth:`np.allclose` for only 2 points is inefficient.

Parameters
----------
points
An array of points defining a spline.

Returns
-------
:class:`bool`
Whether the first and last points of the array are close enough or not
to be considered the same, thus considering the defined spline as
closed.
"""
start, end = points[0], points[-1]
rtol = 1e-5
atol = 1e-8
tolerance = atol + rtol * start
if abs(end[0] - start[0]) > tolerance[0]:
return False
if abs(end[1] - start[1]) > tolerance[1]:
return False
if abs(end[2] - start[2]) > tolerance[2]:
return False
return True


def proportions_along_bezier_curve_for_point(
Expand Down