Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion mplotutils/_cartopy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 44 additions & 0 deletions mplotutils/tests/test_mapticklabels.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cartopy.crs as ccrs
import numpy as np
import pytest
import shapely

import mplotutils as mpu

Expand Down Expand Up @@ -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)
Loading