Skip to content

Commit

Permalink
Add RTreeObject geom impls for rstar 0.10
Browse files Browse the repository at this point in the history
Also tidy up rstar::Point impl for geo_types::Point
  • Loading branch information
urschrei committed Apr 14, 2023
1 parent 5c32920 commit 9366b58
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 99 deletions.
9 changes: 6 additions & 3 deletions geo-types/src/geometry/geometry_collection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use crate::Point;
use crate::{CoordNum, Geometry};
use alloc::vec;
Expand All @@ -7,7 +7,7 @@ use alloc::vec::Vec;
use approx::{AbsDiffEq, RelativeEq};
use core::iter::FromIterator;
use core::ops::{Index, IndexMut};
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use num_traits::Bounded;

/// A collection of [`Geometry`](enum.Geometry.html) types.
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<'a, T: CoordNum> GeometryCollection<T> {
}
}

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
macro_rules! impl_rstar_geometry_collection {
($rstar:ident) => {
impl<T> $rstar::RTreeObject for GeometryCollection<T>
Expand Down Expand Up @@ -289,6 +289,9 @@ impl_rstar_geometry_collection!(rstar_0_8);
#[cfg(feature = "rstar_0_9")]
impl_rstar_geometry_collection!(rstar_0_9);

#[cfg(feature = "rstar_0_10")]
impl_rstar_geometry_collection!(rstar_0_10);

#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for GeometryCollection<T>
where
Expand Down
5 changes: 4 additions & 1 deletion geo-types/src/geometry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ where
}
}

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
macro_rules! impl_rstar_geometry {
($rstar:ident) => {
impl<T> $rstar::RTreeObject for Geometry<T>
Expand Down Expand Up @@ -302,6 +302,9 @@ impl_rstar_geometry!(rstar_0_8);
#[cfg(feature = "rstar_0_9")]
impl_rstar_geometry!(rstar_0_9);

#[cfg(feature = "rstar_0_10")]
impl_rstar_geometry!(rstar_0_10);

#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for Geometry<T>
where
Expand Down
9 changes: 6 additions & 3 deletions geo-types/src/geometry/multi_line_string.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use crate::Point;
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use num_traits::Bounded;

use crate::{CoordNum, LineString};
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<T: CoordNum> MultiLineString<T> {
}
}

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
macro_rules! impl_rstar_multi_linestring {
($rstar:ident) => {
impl<T> $rstar::RTreeObject for MultiLineString<T>
Expand Down Expand Up @@ -157,6 +157,9 @@ impl_rstar_multi_linestring!(rstar_0_8);
#[cfg(feature = "rstar_0_9")]
impl_rstar_multi_linestring!(rstar_0_9);

#[cfg(feature = "rstar_0_10")]
impl_rstar_multi_linestring!(rstar_0_10);

#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for MultiLineString<T>
where
Expand Down
7 changes: 5 additions & 2 deletions geo-types/src/geometry/multi_point.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{CoordNum, Point};
#[cfg(any(feature = "approx", test))]
use approx::{AbsDiffEq, RelativeEq};
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use num_traits::Bounded;

use alloc::vec;
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<T: CoordNum> MultiPoint<T> {
}
}

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
macro_rules! impl_rstar_multi_point {
($rstar:ident) => {
impl<T> $rstar::RTreeObject for MultiPoint<T>
Expand Down Expand Up @@ -133,6 +133,9 @@ impl_rstar_multi_point!(rstar_0_8);
#[cfg(feature = "rstar_0_9")]
impl_rstar_multi_point!(rstar_0_9);

#[cfg(feature = "rstar_0_10")]
impl_rstar_multi_point!(rstar_0_10);

#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for MultiPoint<T>
where
Expand Down
9 changes: 6 additions & 3 deletions geo-types/src/geometry/multi_polygon.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use crate::Point;
use crate::{CoordNum, Polygon};
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use num_traits::Bounded;

use alloc::vec;
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<T: CoordNum> MultiPolygon<T> {
}
}

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
macro_rules! impl_rstar_multi_polygon {
($rstar:ident) => {
impl<T> $rstar::RTreeObject for MultiPolygon<T>
Expand Down Expand Up @@ -130,6 +130,9 @@ impl_rstar_multi_polygon!(rstar_0_8);
#[cfg(feature = "rstar_0_9")]
impl_rstar_multi_polygon!(rstar_0_9);

#[cfg(feature = "rstar_0_10")]
impl_rstar_multi_polygon!(rstar_0_10);

#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for MultiPolygon<T>
where
Expand Down
117 changes: 36 additions & 81 deletions geo-types/src/geometry/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,93 +586,48 @@ where
}
}

#[cfg(feature = "rstar_0_8")]
// These are required for rstar RTree
impl<T> ::rstar_0_8::Point for Point<T>
where
T: ::num_traits::Float + ::rstar_0_8::RTreeNum,
{
type Scalar = T;

const DIMENSIONS: usize = 2;

fn generate(generator: impl Fn(usize) -> Self::Scalar) -> Self {
Point::new(generator(0), generator(1))
}

fn nth(&self, index: usize) -> Self::Scalar {
match index {
0 => self.0.x,
1 => self.0.y,
_ => unreachable!(),
}
}
fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar {
match index {
0 => &mut self.0.x,
1 => &mut self.0.y,
_ => unreachable!(),
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
macro_rules! impl_rstar_point {
($rstar:ident) => {
// These are required for rstar RTree
impl<T> $rstar::Point for Point<T>
where
T: ::num_traits::Float + ::$rstar::RTreeNum,
{
type Scalar = T;

const DIMENSIONS: usize = 2;

fn generate(mut generator: impl FnMut(usize) -> Self::Scalar) -> Self {
Point::new(generator(0), generator(1))
}

fn nth(&self, index: usize) -> Self::Scalar {
match index {
0 => self.0.x,
1 => self.0.y,
_ => unreachable!(),
}
}
fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar {
match index {
0 => &mut self.0.x,
1 => &mut self.0.y,
_ => unreachable!(),
}
}
}
}
};
}

#[cfg(feature = "rstar_0_9")]
impl<T> ::rstar_0_9::Point for Point<T>
where
T: ::num_traits::Float + ::rstar_0_9::RTreeNum,
{
type Scalar = T;

const DIMENSIONS: usize = 2;

fn generate(mut generator: impl FnMut(usize) -> Self::Scalar) -> Self {
Point::new(generator(0), generator(1))
}
#[cfg(feature = "rstar_0_8")]
impl_rstar_point!(rstar_0_8);

fn nth(&self, index: usize) -> Self::Scalar {
match index {
0 => self.0.x,
1 => self.0.y,
_ => unreachable!(),
}
}
fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar {
match index {
0 => &mut self.0.x,
1 => &mut self.0.y,
_ => unreachable!(),
}
}
}
#[cfg(feature = "rstar_0_9")]
impl_rstar_point!(rstar_0_9);

#[cfg(feature = "rstar_0_10")]
impl<T> ::rstar_0_10::Point for Point<T>
where
T: ::num_traits::Float + ::rstar_0_10::RTreeNum,
{
type Scalar = T;

const DIMENSIONS: usize = 2;

fn generate(mut generator: impl FnMut(usize) -> Self::Scalar) -> Self {
Point::new(generator(0), generator(1))
}

fn nth(&self, index: usize) -> Self::Scalar {
match index {
0 => self.0.x,
1 => self.0.y,
_ => unreachable!(),
}
}
fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar {
match index {
0 => &mut self.0.x,
1 => &mut self.0.y,
_ => unreachable!(),
}
}
}
impl_rstar_point!(rstar_0_10);

#[cfg(test)]
mod test {
Expand Down
7 changes: 5 additions & 2 deletions geo-types/src/geometry/rect.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{coord, polygon, Coord, CoordFloat, CoordNum, Line, Polygon};

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use crate::Point;
#[cfg(any(feature = "approx", test))]
use approx::{AbsDiffEq, RelativeEq};
Expand Down Expand Up @@ -380,7 +380,7 @@ impl<T: CoordFloat> Rect<T> {

static RECT_INVALID_BOUNDS_ERROR: &str = "Failed to create Rect: 'min' coordinate's x/y value must be smaller or equal to the 'max' x/y value";

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
macro_rules! impl_rstar_rect {
($rstar:ident) => {
impl<T> $rstar::RTreeObject for Rect<T>
Expand All @@ -405,6 +405,9 @@ impl_rstar_rect!(rstar_0_8);
#[cfg(feature = "rstar_0_9")]
impl_rstar_rect!(rstar_0_9);

#[cfg(feature = "rstar_0_10")]
impl_rstar_rect!(rstar_0_10);

#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for Rect<T>
where
Expand Down
11 changes: 7 additions & 4 deletions geo-types/src/geometry/triangle.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{polygon, Coord, CoordNum, Line, Polygon};
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use num_traits::Bounded;

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use crate::private_utils::get_bounding_rect;
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
use crate::Point;

#[cfg(any(feature = "approx", test))]
Expand Down Expand Up @@ -70,7 +70,7 @@ impl<IC: Into<Coord<T>> + Copy, T: CoordNum> From<[IC; 3]> for Triangle<T> {
}
}

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9", feature = "rstar_0_10"))]
macro_rules! impl_rstar_triangle {
($rstar:ident) => {
impl<T> $rstar::RTreeObject for Triangle<T>
Expand Down Expand Up @@ -102,6 +102,9 @@ impl_rstar_triangle!(rstar_0_8);
#[cfg(feature = "rstar_0_9")]
impl_rstar_triangle!(rstar_0_9);

#[cfg(feature = "rstar_0_10")]
impl_rstar_triangle!(rstar_0_10);

#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for Triangle<T>
where
Expand Down

0 comments on commit 9366b58

Please sign in to comment.