From b64b949403a4264ccd0070f4a626b3fc57b64b0e Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 21 Jul 2026 13:45:26 +1000 Subject: [PATCH 1/2] Prevent deprecation warning from future numpy update by replacing cross product of 2d vectors to 3d --- ultraplot/axes/geo.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ultraplot/axes/geo.py b/ultraplot/axes/geo.py index 657136f0a..8a9463fdf 100644 --- a/ultraplot/axes/geo.py +++ b/ultraplot/axes/geo.py @@ -286,8 +286,13 @@ def _infer_hawkeye_relation(parent_extent, inset_extent): def _segments_intersect(start1, end1, start2, end2): """Return whether two display-coordinate line segments intersect.""" - def _cross(origin, point1, point2): - return np.cross(point1 - origin, point2 - origin) + def _cross(origin: np.ndarray, point1: np.ndarray, point2: np.ndarray) -> float: + if len(origin) != 3: + # Cross needs at least 3D + tmp = np.stack([origin, point1, point2]) + tmp = np.pad(tmp, ((0, 0), (0, 3 - tmp.shape[1])), mode="constant") + origin, point1, point2 = tmp + return np.cross(point1 - origin, point2 - origin).sum() cross1 = _cross(start1, end1, start2) cross2 = _cross(start1, end1, end2) From e98d52018a95e5e9215c9f44cc1d2a53a1b9f82c Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 21 Jul 2026 13:48:23 +1000 Subject: [PATCH 2/2] Simplify --- ultraplot/axes/geo.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ultraplot/axes/geo.py b/ultraplot/axes/geo.py index 8a9463fdf..786fbff54 100644 --- a/ultraplot/axes/geo.py +++ b/ultraplot/axes/geo.py @@ -287,12 +287,11 @@ def _segments_intersect(start1, end1, start2, end2): """Return whether two display-coordinate line segments intersect.""" def _cross(origin: np.ndarray, point1: np.ndarray, point2: np.ndarray) -> float: - if len(origin) != 3: - # Cross needs at least 3D - tmp = np.stack([origin, point1, point2]) - tmp = np.pad(tmp, ((0, 0), (0, 3 - tmp.shape[1])), mode="constant") - origin, point1, point2 = tmp - return np.cross(point1 - origin, point2 - origin).sum() + if len(origin) == 2: + diff1 = point1 - origin + diff2 = point2 - origin + return diff1[0] * diff2[1] - diff1[1] * diff2[0] + return np.cross(point1 - origin, point2 - origin) cross1 = _cross(start1, end1, start2) cross2 = _cross(start1, end1, end2)