Skip to content

Commit

Permalink
use prepared geoms
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Aug 18, 2024
1 parent c017b53 commit e413778
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -18,15 +18,15 @@ pub struct Gshhg {

#[derive(Clone)]
struct PolW {
p: Polygon,
p: PreparedGeometry<'static>,
e: AABB<Point<f64>>,
}

impl PolW {
pub fn from(p: Polygon) -> PolW {
PolW {
p: p.clone(),
e: p.envelope()
e: p.envelope(),
p: PreparedGeometry::from(p),
}
}
}
Expand All @@ -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<f64>, _max_distance: f64) -> Option<f64> {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dateline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

0 comments on commit e413778

Please sign in to comment.