Skip to content

Commit 2fdb879

Browse files
committed
Removed consider_points_different and added docstrings to VMobject.get_subpath_split_indices
1 parent 7d3d477 commit 2fdb879

File tree

1 file changed

+13
-81
lines changed

1 file changed

+13
-81
lines changed

manim/mobject/types/vectorized_mobject.py

Lines changed: 13 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,84 +1096,6 @@ def consider_points_equals_2d(
10961096
is_close = abs(p1 - p0) <= atol
10971097
return is_close[:, 0] & is_close[:, 1]
10981098

1099-
def consider_points_different(
1100-
self,
1101-
p0: Iterable[float] | Iterable[Iterable[float]],
1102-
p1: Iterable[float] | Iterable[Iterable[float]],
1103-
) -> bool | np.ndarray:
1104-
"""Determine if two points are distant enough to be considered different.
1105-
1106-
This function reimplements np.allclose, because repeated calling of
1107-
np.allclose for only 2 points is inefficient.
1108-
----------
1109-
p0
1110-
first point
1111-
p1
1112-
second point
1113-
1114-
Returns
1115-
-------
1116-
bool | np.ndarray
1117-
Whether the points p0 and p1 are considered different or not.
1118-
"""
1119-
p0 = np.asarray(p0)
1120-
p1 = np.asarray(p1)
1121-
atol = self.tolerance_for_point_equality
1122-
1123-
# Case 1: single pair of points
1124-
if p0.ndim == 1 and p1.ndim == 1:
1125-
if abs(p0[0] - p1[0]) > atol:
1126-
return True
1127-
if abs(p0[1] - p1[1]) > atol:
1128-
return True
1129-
if abs(p0[2] - p1[2]) > atol:
1130-
return True
1131-
return False
1132-
1133-
# Case 2: multiple pairs of points
1134-
is_far = abs(p1 - p0) > atol
1135-
return is_far[:, 0] | is_far[:, 1] | is_far[:, 2]
1136-
1137-
def consider_points_different_2d(
1138-
self,
1139-
p0: Iterable[float] | Iterable[Iterable[float]],
1140-
p1: Iterable[float] | Iterable[Iterable[float]],
1141-
) -> bool | np.ndarray:
1142-
"""Determine if two points are distant enough to be considered different.
1143-
1144-
This uses the algorithm from np.isclose(), but expanded here for the
1145-
2D point case. NumPy is overkill for such a small question.
1146-
Parameters
1147-
----------
1148-
p0
1149-
first point
1150-
p1
1151-
second point
1152-
1153-
Returns
1154-
-------
1155-
bool | np.ndarray
1156-
Whether the points p0 and p1 are considered different or not.
1157-
"""
1158-
p0 = np.asarray(p0)
1159-
p1 = np.asarray(p1)
1160-
atol = self.tolerance_for_point_equality
1161-
1162-
# Case 1: single pair of points
1163-
if p0.ndim == 1 and p1.ndim == 1:
1164-
if abs(p0[0] - p1[0]) > atol:
1165-
return True
1166-
if abs(p0[1] - p1[1]) > atol:
1167-
return True
1168-
return False
1169-
1170-
# Case 2: multiple pairs of points
1171-
# Ensure that we're only working with 2D components
1172-
p0 = p0.reshape(-1, self.dim)[:, :2]
1173-
p1 = p1.reshape(-1, self.dim)[:, :2]
1174-
is_far = abs(p1 - p0) > atol
1175-
return is_far[:, 0] | is_far[:, 1]
1176-
11771099
# Information about line
11781100
def get_cubic_bezier_tuples_from_points(self, points: np.ndarray) -> np.ndarray:
11791101
return self.gen_cubic_bezier_tuples_from_points(points)
@@ -1295,12 +1217,10 @@ def get_subpath_split_indices_from_points(
12951217

12961218
if n_dims == 2:
12971219
are_points_equal = self.consider_points_equals_2d
1298-
are_points_different = self.consider_points_different_2d
12991220
else:
13001221
are_points_equal = self.consider_points_equals
1301-
are_points_different = self.consider_points_different
13021222

1303-
diff_bools = are_points_different(starts[1:], ends[:-1])
1223+
diff_bools = ~are_points_equal(starts[1:], ends[:-1])
13041224
diff_indices = np.arange(1, diff_bools.shape[0] + 1)[diff_bools]
13051225

13061226
split_indices = np.empty((diff_indices.shape[0] + 1, 2), dtype=int)
@@ -1330,6 +1250,18 @@ def get_subpath_split_indices(
13301250
n_dims: int = 3,
13311251
strip_null_end_curves: bool = False,
13321252
) -> np.ndarray:
1253+
"""Returns the necessary indices to split :attr:`.VMobject.points` into
1254+
the corresponding subpaths.
1255+
1256+
Subpaths are ranges of curves with each pair of consecutive curves
1257+
having their end/start points coincident.
1258+
1259+
Returns
1260+
-------
1261+
np.ndarray
1262+
(n_subpaths, 2)-shaped array, where the first and second columns
1263+
indicate respectively the start and end indices for each subpath.
1264+
"""
13331265
return self.get_subpath_split_indices_from_points(
13341266
self.points, n_dims, strip_null_end_curves
13351267
)

0 commit comments

Comments
 (0)