From 8ae4e9e0efe59610fc0e9db80d1844418aa0c937 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Fri, 27 Mar 2026 12:22:27 +0100 Subject: [PATCH 1/2] test _determine_intersection --- mplotutils/_cartopy_utils.py | 2 +- mplotutils/tests/test_mapticklabels.py | 44 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/mplotutils/_cartopy_utils.py b/mplotutils/_cartopy_utils.py index 2661bb2..7084aae 100644 --- a/mplotutils/_cartopy_utils.py +++ b/mplotutils/_cartopy_utils.py @@ -479,7 +479,7 @@ def _determine_intersection(polygon, xy1, xy2): arr = np.atleast_2d(arr) elif isinstance(intersection, shapely.geometry.LineString): if intersection.is_empty: - return np.array([]) + return np.array([[]]) else: return np.array(intersection.coords) else: diff --git a/mplotutils/tests/test_mapticklabels.py b/mplotutils/tests/test_mapticklabels.py index 5c7c1f2..48e9bd2 100644 --- a/mplotutils/tests/test_mapticklabels.py +++ b/mplotutils/tests/test_mapticklabels.py @@ -1,6 +1,7 @@ import cartopy.crs as ccrs import numpy as np import pytest +import shapely import mplotutils as mpu @@ -109,3 +110,46 @@ def test_xyticklabels_not_on_map(): # assert ax.texts[0].get_text() == "60°E" # assert ax.texts[-1].get_text() == "60°W" + + +def test_determine_intersection(): + + box = shapely.box(0, 0, 1, 1) + + # case 0 -> the expected two points top & bottom + + a = shapely.Point((0.5, -0.5)) + b = shapely.Point((0.5, 1.5)) + + result = mpu._cartopy_utils._determine_intersection(box, a, b) + expected = np.array([[0.5, 0.0], [0.5, 1.0]]) + + np.testing.assert_allclose(result, expected) + + # case 1 -> only one intersection (not sure how this would happen) + + b = shapely.Point((0.5, 0.5)) + + result = mpu._cartopy_utils._determine_intersection(box, a, b) + expected = np.array([[0.5, 0.0]]) + np.testing.assert_allclose(result, expected) + + # case 2 -> intersection along a polygon edge + + b = shapely.Point((1, 1.5)) + a = shapely.Point((1, -0.5)) + + result = mpu._cartopy_utils._determine_intersection(box, a, b) + expected = np.array([[1.0, 0.0], [1.0, 1.0]]) + + np.testing.assert_allclose(result, expected) + + # case 3 -> no intersection + + a = shapely.Point((1.5, -0.5)) + b = shapely.Point((1.5, 1.5)) + result = mpu._cartopy_utils._determine_intersection(box, a, b) + + expected = np.array([[]]) + + np.testing.assert_allclose(result, expected) From 93d692d6d468369ccb64e07cb700d7b2d4af5fc8 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Fri, 27 Mar 2026 12:23:55 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0c609a..5f96129 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,8 @@ - Add python 3.13 to list of supported versions ([#158](https://github.com/mpytools/mplotutils/pull/158)). - Increased test coverage ([#180](https://github.com/mpytools/mplotutils/pull/180), [#181](https://github.com/mpytools/mplotutils/pull/181), - [#182](https://github.com/mpytools/mplotutils/pull/182), and [#207](https://github.com/mpytools/mplotutils/pull/207)). + [#182](https://github.com/mpytools/mplotutils/pull/182), [#207](https://github.com/mpytools/mplotutils/pull/207), + and [#208](https://github.com/mpytools/mplotutils/pull/208),). ### Bug fixes