Skip to content

Commit

Permalink
added test for point_in_polly
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBarker-NOAA committed May 23, 2024
1 parent 572cddb commit 7ad5786
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import numpy as np
import pytest

from xarray_subset_grid.utils import normalize_polygon_x_coords
from xarray_subset_grid.utils import (normalize_polygon_x_coords,
ray_tracing_numpy,
)

# normalize_polygon_x_coords tests.

poly1_180 = np.array([
[-73, 41],
Expand Down Expand Up @@ -74,3 +78,27 @@ def test_normalize_x_coords(lons, poly, norm_poly):
# ]
# ),
# )

def test_ray_tracing_numpy():
"""
minimal test, but at least it'll show it's not totally broken
NOTE: this function was compared to shapely and a Cython implementation
"""
poly = [
(3.0, 3.0),
(5.0, 8.0),
(10.0, 5.0),
(7.0, 1.0),
]

points = np.array([
(3.0, 6.0), # outside
(6.0, 4.0), # inside
(9.0, 7.0), # outside
])

result = ray_tracing_numpy(points[:, 0], points[:, 1], poly)

assert np.array_equal(result, [False, True, False])

0 comments on commit 7ad5786

Please sign in to comment.