Skip to content

Commit 48e9fae

Browse files
committed
apply GeoNum
I think this will be clearer than "HasKernel". We still often use CoordNum (things which *don't* implement HasKernel). Do we actually care to make that distinction? Seems like it complicates things a bit for a usecase I'm not sure exists in the wild.
1 parent e58bf76 commit 48e9fae

14 files changed

+77
-87
lines changed

geo/src/algorithm/contains/geometry.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::Contains;
2-
use crate::kernels::*;
32
use crate::*;
43

54
// ┌──────────────────────────────┐
@@ -8,7 +7,7 @@ use crate::*;
87

98
impl<T> Contains<Coordinate<T>> for Geometry<T>
109
where
11-
T: HasKernel,
10+
T: GeoNum,
1211
{
1312
fn contains(&self, coord: &Coordinate<T>) -> bool {
1413
match self {
@@ -28,7 +27,7 @@ where
2827

2928
impl<T> Contains<Point<T>> for Geometry<T>
3029
where
31-
T: HasKernel,
30+
T: GeoNum,
3231
{
3332
fn contains(&self, point: &Point<T>) -> bool {
3433
self.contains(&point.0)
@@ -41,7 +40,7 @@ where
4140

4241
impl<T> Contains<Coordinate<T>> for GeometryCollection<T>
4342
where
44-
T: HasKernel,
43+
T: GeoNum,
4544
{
4645
fn contains(&self, coord: &Coordinate<T>) -> bool {
4746
self.iter().any(|geometry| geometry.contains(coord))
@@ -50,7 +49,7 @@ where
5049

5150
impl<T> Contains<Point<T>> for GeometryCollection<T>
5251
where
53-
T: HasKernel,
52+
T: GeoNum,
5453
{
5554
fn contains(&self, point: &Point<T>) -> bool {
5655
self.contains(&point.0)

geo/src/algorithm/contains/line.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use super::Contains;
22
use crate::intersects::Intersects;
3-
use crate::kernels::*;
4-
use crate::*;
3+
use crate::{Coordinate, GeoNum, Line, LineString, Point};
54

65
// ┌──────────────────────────┐
76
// │ Implementations for Line │
87
// └──────────────────────────┘
98

109
impl<T> Contains<Coordinate<T>> for Line<T>
1110
where
12-
T: HasKernel,
11+
T: GeoNum,
1312
{
1413
fn contains(&self, coord: &Coordinate<T>) -> bool {
1514
if self.start == self.end {
@@ -22,7 +21,7 @@ where
2221

2322
impl<T> Contains<Point<T>> for Line<T>
2423
where
25-
T: HasKernel,
24+
T: GeoNum,
2625
{
2726
fn contains(&self, p: &Point<T>) -> bool {
2827
self.contains(&p.0)
@@ -31,7 +30,7 @@ where
3130

3231
impl<T> Contains<Line<T>> for Line<T>
3332
where
34-
T: HasKernel,
33+
T: GeoNum,
3534
{
3635
fn contains(&self, line: &Line<T>) -> bool {
3736
if line.start == line.end {
@@ -44,7 +43,7 @@ where
4443

4544
impl<T> Contains<LineString<T>> for Line<T>
4645
where
47-
T: HasKernel,
46+
T: GeoNum,
4847
{
4948
fn contains(&self, linestring: &LineString<T>) -> bool {
5049
// Empty linestring has no interior, and not

geo/src/algorithm/contains/line_string.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use super::Contains;
2-
use crate::kernels::*;
3-
use crate::*;
4-
use intersects::Intersects;
2+
use crate::intersects::Intersects;
3+
use crate::{CoordNum, Coordinate, GeoNum, Line, LineString, MultiLineString, Point};
54

65
// ┌────────────────────────────────┐
76
// │ Implementations for LineString │
87
// └────────────────────────────────┘
98

109
impl<T> Contains<Coordinate<T>> for LineString<T>
1110
where
12-
T: HasKernel,
11+
T: GeoNum,
1312
{
1413
fn contains(&self, coord: &Coordinate<T>) -> bool {
1514
if self.0.is_empty() {
@@ -28,7 +27,7 @@ where
2827

2928
impl<T> Contains<Point<T>> for LineString<T>
3029
where
31-
T: HasKernel,
30+
T: GeoNum,
3231
{
3332
fn contains(&self, p: &Point<T>) -> bool {
3433
self.contains(&p.0)
@@ -37,7 +36,7 @@ where
3736

3837
impl<T> Contains<Line<T>> for LineString<T>
3938
where
40-
T: HasKernel,
39+
T: GeoNum,
4140
{
4241
fn contains(&self, line: &Line<T>) -> bool {
4342
if line.start == line.end {
@@ -107,7 +106,7 @@ where
107106

108107
impl<T> Contains<LineString<T>> for LineString<T>
109108
where
110-
T: HasKernel,
109+
T: GeoNum,
111110
{
112111
fn contains(&self, rhs: &LineString<T>) -> bool {
113112
rhs.lines().all(|l| self.contains(&l))

geo/src/algorithm/contains/polygon.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
use super::Contains;
22
use crate::intersects::Intersects;
3-
use crate::kernels::HasKernel;
4-
use crate::{CoordNum, Coordinate, Line, LineString, MultiPolygon, Point, Polygon};
3+
use crate::{CoordNum, Coordinate, GeoNum, Line, LineString, MultiPolygon, Point, Polygon};
54

65
// ┌─────────────────────────────┐
76
// │ Implementations for Polygon │
87
// └─────────────────────────────┘
98

109
impl<T> Contains<Coordinate<T>> for Polygon<T>
1110
where
12-
T: HasKernel,
11+
T: GeoNum,
1312
{
1413
fn contains(&self, coord: &Coordinate<T>) -> bool {
1514
use crate::algorithm::coordinate_position::{CoordPos, CoordinatePosition};
@@ -20,7 +19,7 @@ where
2019

2120
impl<T> Contains<Point<T>> for Polygon<T>
2221
where
23-
T: HasKernel,
22+
T: GeoNum,
2423
{
2524
fn contains(&self, p: &Point<T>) -> bool {
2625
self.contains(&p.0)
@@ -31,7 +30,7 @@ where
3130
// line.start and line.end is on the boundaries
3231
impl<T> Contains<Line<T>> for Polygon<T>
3332
where
34-
T: HasKernel,
33+
T: GeoNum,
3534
{
3635
fn contains(&self, line: &Line<T>) -> bool {
3736
// both endpoints are contained in the polygon and the line
@@ -46,7 +45,7 @@ where
4645
// TODO: also check interiors
4746
impl<T> Contains<Polygon<T>> for Polygon<T>
4847
where
49-
T: HasKernel,
48+
T: GeoNum,
5049
{
5150
fn contains(&self, poly: &Polygon<T>) -> bool {
5251
// decompose poly's exterior ring into Lines, and check each for containment
@@ -57,7 +56,7 @@ where
5756
// TODO: ensure DE-9IM compliance
5857
impl<T> Contains<LineString<T>> for Polygon<T>
5958
where
60-
T: HasKernel,
59+
T: GeoNum,
6160
{
6261
fn contains(&self, linestring: &LineString<T>) -> bool {
6362
// All LineString points must be inside the Polygon

geo/src/algorithm/contains/triangle.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
use super::Contains;
2-
use crate::kernels::*;
3-
use crate::*;
2+
use crate::{Coordinate, GeoNum, LineString, Point, Triangle};
43

54
// ┌──────────────────────────────┐
65
// │ Implementations for Triangle │
76
// └──────────────────────────────┘
87

98
impl<T> Contains<Coordinate<T>> for Triangle<T>
109
where
11-
T: HasKernel,
10+
T: GeoNum,
1211
{
1312
fn contains(&self, coord: &Coordinate<T>) -> bool {
1413
let ls = LineString(vec![self.0, self.1, self.2, self.0]);
15-
use utils::*;
14+
use crate::utils::{coord_pos_relative_to_ring, CoordPos};
1615
coord_pos_relative_to_ring(*coord, &ls) == CoordPos::Inside
1716
}
1817
}
1918

2019
impl<T> Contains<Point<T>> for Triangle<T>
2120
where
22-
T: HasKernel,
21+
T: GeoNum,
2322
{
2423
fn contains(&self, point: &Point<T>) -> bool {
2524
self.contains(&point.0)

geo/src/algorithm/convex_hull/graham.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{swap_remove_to_first, trivial_hull};
22
use crate::algorithm::kernels::*;
3-
use crate::{Coordinate, LineString};
3+
use crate::{Coordinate, GeoNum, LineString};
44

55
/// The [Graham's scan] algorithm to compute the convex hull
66
/// of a collection of points. This algorithm is less
@@ -20,7 +20,7 @@ use crate::{Coordinate, LineString};
2020
/// [Graham's scan]: //en.wikipedia.org/wiki/Graham_scan
2121
pub fn graham_hull<T>(mut points: &mut [Coordinate<T>], include_on_hull: bool) -> LineString<T>
2222
where
23-
T: HasKernel,
23+
T: GeoNum,
2424
{
2525
if points.len() < 4 {
2626
// Nothing to build with fewer than four points.
@@ -89,8 +89,7 @@ where
8989
mod test {
9090
use super::*;
9191
use crate::algorithm::is_convex::IsConvex;
92-
use std::fmt::Debug;
93-
fn test_convexity<T: HasKernel + Debug>(initial: &[(T, T)]) {
92+
fn test_convexity<T: GeoNum>(initial: &[(T, T)]) {
9493
let mut v: Vec<_> = initial
9594
.iter()
9695
.map(|e| Coordinate::from((e.0, e.1)))

geo/src/algorithm/convex_hull/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use super::kernels::*;
2-
use crate::*;
1+
use crate::{Coordinate, GeoNum, LineString, MultiLineString, MultiPoint, MultiPolygon, Polygon};
32

43
/// Returns the convex hull of a Polygon. The hull is always oriented counter-clockwise.
54
///
@@ -38,13 +37,13 @@ use crate::*;
3837
/// assert_eq!(res.exterior(), &correct_hull);
3938
/// ```
4039
pub trait ConvexHull {
41-
type Scalar: CoordNum;
40+
type Scalar: GeoNum;
4241
fn convex_hull(&self) -> Polygon<Self::Scalar>;
4342
}
4443

4544
impl<T> ConvexHull for Polygon<T>
4645
where
47-
T: HasKernel,
46+
T: GeoNum,
4847
{
4948
type Scalar = T;
5049
fn convex_hull(&self) -> Polygon<T> {
@@ -54,7 +53,7 @@ where
5453

5554
impl<T> ConvexHull for MultiPolygon<T>
5655
where
57-
T: HasKernel,
56+
T: GeoNum,
5857
{
5958
type Scalar = T;
6059
fn convex_hull(&self) -> Polygon<T> {
@@ -69,7 +68,7 @@ where
6968

7069
impl<T> ConvexHull for LineString<T>
7170
where
72-
T: HasKernel,
71+
T: GeoNum,
7372
{
7473
type Scalar = T;
7574
fn convex_hull(&self) -> Polygon<T> {
@@ -79,7 +78,7 @@ where
7978

8079
impl<T> ConvexHull for MultiLineString<T>
8180
where
82-
T: HasKernel,
81+
T: GeoNum,
8382
{
8483
type Scalar = T;
8584
fn convex_hull(&self) -> Polygon<T> {
@@ -90,7 +89,7 @@ where
9089

9190
impl<T> ConvexHull for MultiPoint<T>
9291
where
93-
T: HasKernel,
92+
T: GeoNum,
9493
{
9594
type Scalar = T;
9695
fn convex_hull(&self) -> Polygon<T> {
@@ -111,7 +110,7 @@ pub use graham::graham_hull;
111110
// required.
112111
fn trivial_hull<T>(points: &mut [Coordinate<T>], include_on_hull: bool) -> LineString<T>
113112
where
114-
T: HasKernel,
113+
T: GeoNum,
115114
{
116115
assert!(points.len() < 4);
117116

geo/src/algorithm/convex_hull/qhull.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{swap_remove_to_first, trivial_hull};
2-
use crate::algorithm::kernels::*;
2+
use crate::kernels::{HasKernel, Kernel, Orientation};
33
use crate::utils::partition_slice;
4-
use crate::{Coordinate, LineString};
4+
use crate::{Coordinate, GeoNum, LineString};
55

66
// Determines if `p_c` lies on the positive side of the
77
// segment `p_a` to `p_b`. In other words, whether segment
@@ -11,16 +11,16 @@ use crate::{Coordinate, LineString};
1111
#[inline]
1212
fn is_ccw<T>(p_a: Coordinate<T>, p_b: Coordinate<T>, p_c: Coordinate<T>) -> bool
1313
where
14-
T: HasKernel,
14+
T: GeoNum,
1515
{
16-
let o = T::Ker::orient2d(p_a, p_b, p_c);
16+
let o = <T as HasKernel>::Ker::orient2d(p_a, p_b, p_c);
1717
o == Orientation::CounterClockwise
1818
}
1919

2020
// Adapted from https://web.archive.org/web/20180409175413/http://www.ahristov.com/tutorial/geometry-games/convex-hull.html
2121
pub fn quick_hull<T>(mut points: &mut [Coordinate<T>]) -> LineString<T>
2222
where
23-
T: HasKernel,
23+
T: GeoNum,
2424
{
2525
// can't build a hull from fewer than four points
2626
if points.len() < 4 {
@@ -70,7 +70,7 @@ fn hull_set<T>(
7070
mut set: &mut [Coordinate<T>],
7171
hull: &mut Vec<Coordinate<T>>,
7272
) where
73-
T: HasKernel,
73+
T: GeoNum,
7474
{
7575
if set.is_empty() {
7676
return;

0 commit comments

Comments
 (0)