|
1 | 1 | import cartopy.crs as ccrs |
2 | 2 | import numpy as np |
3 | 3 | import pytest |
| 4 | +import shapely |
4 | 5 |
|
5 | 6 | import mplotutils as mpu |
6 | 7 |
|
@@ -109,3 +110,46 @@ def test_xyticklabels_not_on_map(): |
109 | 110 |
|
110 | 111 | # assert ax.texts[0].get_text() == "60°E" |
111 | 112 | # assert ax.texts[-1].get_text() == "60°W" |
| 113 | + |
| 114 | + |
| 115 | +def test_determine_intersection(): |
| 116 | + |
| 117 | + box = shapely.box(0, 0, 1, 1) |
| 118 | + |
| 119 | + # case 0 -> the expected two points top & bottom |
| 120 | + |
| 121 | + a = shapely.Point((0.5, -0.5)) |
| 122 | + b = shapely.Point((0.5, 1.5)) |
| 123 | + |
| 124 | + result = mpu._cartopy_utils._determine_intersection(box, a, b) |
| 125 | + expected = np.array([[0.5, 0.0], [0.5, 1.0]]) |
| 126 | + |
| 127 | + np.testing.assert_allclose(result, expected) |
| 128 | + |
| 129 | + # case 1 -> only one intersection (not sure how this would happen) |
| 130 | + |
| 131 | + b = shapely.Point((0.5, 0.5)) |
| 132 | + |
| 133 | + result = mpu._cartopy_utils._determine_intersection(box, a, b) |
| 134 | + expected = np.array([[0.5, 0.0]]) |
| 135 | + np.testing.assert_allclose(result, expected) |
| 136 | + |
| 137 | + # case 2 -> intersection along a polygon edge |
| 138 | + |
| 139 | + b = shapely.Point((1, 1.5)) |
| 140 | + a = shapely.Point((1, -0.5)) |
| 141 | + |
| 142 | + result = mpu._cartopy_utils._determine_intersection(box, a, b) |
| 143 | + expected = np.array([[1.0, 0.0], [1.0, 1.0]]) |
| 144 | + |
| 145 | + np.testing.assert_allclose(result, expected) |
| 146 | + |
| 147 | + # case 3 -> no intersection |
| 148 | + |
| 149 | + a = shapely.Point((1.5, -0.5)) |
| 150 | + b = shapely.Point((1.5, 1.5)) |
| 151 | + result = mpu._cartopy_utils._determine_intersection(box, a, b) |
| 152 | + |
| 153 | + expected = np.array([[]]) |
| 154 | + |
| 155 | + np.testing.assert_allclose(result, expected) |
0 commit comments