Skip to content

Commit e413778

Browse files
committed
use prepared geoms
1 parent c017b53 commit e413778

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/shapes.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::io;
44
use std::path::Path;
55
use std::{borrow::Borrow, convert::TryInto};
66

7-
use geo::{point, Contains, Geometry, MultiPolygon, Point, Polygon, PreparedGeometry};
7+
use geo::{point, Contains, Geometry, MultiPolygon, Point, Polygon, PreparedGeometry, Relate};
88
use numpy::{PyArray, PyReadonlyArrayDyn};
9-
use rstar::{PointDistance, RTree, RTreeObject, AABB, Envelope};
9+
use rstar::{Envelope, PointDistance, RTree, RTreeObject, AABB};
1010

1111
pub static GSHHS_F: &str = "gshhs_f_-180.000000E-90.000000N180.000000E90.000000N.wkb.xz";
1212

@@ -18,15 +18,15 @@ pub struct Gshhg {
1818

1919
#[derive(Clone)]
2020
struct PolW {
21-
p: Polygon,
21+
p: PreparedGeometry<'static>,
2222
e: AABB<Point<f64>>,
2323
}
2424

2525
impl PolW {
2626
pub fn from(p: Polygon) -> PolW {
2727
PolW {
28-
p: p.clone(),
29-
e: p.envelope()
28+
e: p.envelope(),
29+
p: PreparedGeometry::from(p),
3030
}
3131
}
3232
}
@@ -51,7 +51,8 @@ impl PointDistance for PolW {
5151
return false;
5252
}
5353

54-
self.p.contains(point)
54+
self.p.relate(point).is_covers()
55+
// self.p.contains(point)
5556
}
5657

5758
fn distance_2_if_less_or_equal(&self, _point: &Point<f64>, _max_distance: f64) -> Option<f64> {

tests/test_dateline.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_dateline():
99

1010
xx, yy = np.meshgrid(x, y)
1111
xx, yy = xx.ravel(), yy.ravel()
12-
mm = mask.contains_many(xx, yy)
12+
mm = mask.contains_many_par(xx, yy)
1313

1414
# Offset
1515
x2 = np.linspace(180, 540, 100)
@@ -18,7 +18,7 @@ def test_dateline():
1818

1919
xx, yy = np.meshgrid(x2, y2)
2020
xx, yy = xx.ravel(), yy.ravel()
21-
MM = mask.contains_many(xx, yy)
21+
MM = mask.contains_many_par(xx, yy)
2222

2323
np.testing.assert_array_equal(mm, MM)
2424

0 commit comments

Comments
 (0)