From 31cc2671e5c511690360178581e139b1a9c7b1f7 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 13 Jan 2023 16:35:18 -0800 Subject: [PATCH] Have line_intersects_path not assume closed path --- manimlib/utils/space_ops.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/manimlib/utils/space_ops.py b/manimlib/utils/space_ops.py index 50b05365..737966ad 100644 --- a/manimlib/utils/space_ops.py +++ b/manimlib/utils/space_ops.py @@ -321,11 +321,13 @@ def line_intersects_path( Tests whether the line (start, end) intersects a polygonal path defined by its vertices """ - n = len(path) - p1 = np.tile(start[:2], n).reshape((n, 2)) - q1 = np.tile(end[:2], n).reshape((n, 2)) - p2 = path[:, :2] - q2 = np.vstack([path[1:, :2], path[:1, :2]]) + n = len(path) - 1 + p1 = np.empty((n, 2)) + q1 = np.empty((n, 2)) + p1[:] = start[:2] + q1[:] = end[:2] + p2 = path[:-1, :2] + q2 = path[1:, :2] v1 = q1 - p1 v2 = q2 - p2