From e41377825fbfb5168c6d30dea9861aa357092985 Mon Sep 17 00:00:00 2001 From: Gaute Hope Date: Sun, 18 Aug 2024 08:53:35 +0200 Subject: [PATCH] use prepared geoms --- src/shapes.rs | 13 +++++++------ tests/test_dateline.py | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/shapes.rs b/src/shapes.rs index 365f542..6c61c54 100644 --- a/src/shapes.rs +++ b/src/shapes.rs @@ -4,9 +4,9 @@ use std::io; use std::path::Path; use std::{borrow::Borrow, convert::TryInto}; -use geo::{point, Contains, Geometry, MultiPolygon, Point, Polygon, PreparedGeometry}; +use geo::{point, Contains, Geometry, MultiPolygon, Point, Polygon, PreparedGeometry, Relate}; use numpy::{PyArray, PyReadonlyArrayDyn}; -use rstar::{PointDistance, RTree, RTreeObject, AABB, Envelope}; +use rstar::{Envelope, PointDistance, RTree, RTreeObject, AABB}; pub static GSHHS_F: &str = "gshhs_f_-180.000000E-90.000000N180.000000E90.000000N.wkb.xz"; @@ -18,15 +18,15 @@ pub struct Gshhg { #[derive(Clone)] struct PolW { - p: Polygon, + p: PreparedGeometry<'static>, e: AABB>, } impl PolW { pub fn from(p: Polygon) -> PolW { PolW { - p: p.clone(), - e: p.envelope() + e: p.envelope(), + p: PreparedGeometry::from(p), } } } @@ -51,7 +51,8 @@ impl PointDistance for PolW { return false; } - self.p.contains(point) + self.p.relate(point).is_covers() + // self.p.contains(point) } fn distance_2_if_less_or_equal(&self, _point: &Point, _max_distance: f64) -> Option { diff --git a/tests/test_dateline.py b/tests/test_dateline.py index f877073..4e46b18 100644 --- a/tests/test_dateline.py +++ b/tests/test_dateline.py @@ -9,7 +9,7 @@ def test_dateline(): xx, yy = np.meshgrid(x, y) xx, yy = xx.ravel(), yy.ravel() - mm = mask.contains_many(xx, yy) + mm = mask.contains_many_par(xx, yy) # Offset x2 = np.linspace(180, 540, 100) @@ -18,7 +18,7 @@ def test_dateline(): xx, yy = np.meshgrid(x2, y2) xx, yy = xx.ravel(), yy.ravel() - MM = mask.contains_many(xx, yy) + MM = mask.contains_many_par(xx, yy) np.testing.assert_array_equal(mm, MM)