Skip to content

Commit

Permalink
Merge pull request #1143 from urschrei/rstar_012
Browse files Browse the repository at this point in the history
Update geo and geo-types to RStar v0.12.0
  • Loading branch information
urschrei authored Jan 28, 2024
2 parents a517137 + 9b51c0f commit c99c426
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 6 deletions.
1 change: 1 addition & 0 deletions geo-types/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* POSSIBLY BREAKING: Minimum supported version of Rust (MSRV) is now 1.70
* <https://github.com/georust/geo/pull/1134>
* Add feature for rstar v0.12.0

## 0.7.12

Expand Down
2 changes: 2 additions & 0 deletions geo-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use-rstar_0_8 = ["rstar_0_8", "approx"]
use-rstar_0_9 = ["rstar_0_9", "approx"]
use-rstar_0_10 = ["rstar_0_10", "approx"]
use-rstar_0_11 = ["rstar_0_11", "approx"]
use-rstar_0_12 = ["rstar_0_12", "approx"]

[dependencies]
approx = { version = ">= 0.4.0, < 0.6.0", optional = true, default-features = false }
Expand All @@ -31,6 +32,7 @@ rstar_0_8 = { package = "rstar", version = "0.8", optional = true }
rstar_0_9 = { package = "rstar", version = "0.9", optional = true }
rstar_0_10 = { package = "rstar", version = "0.10", optional = true }
rstar_0_11 = { package = "rstar", version = "0.11", optional = true }
rstar_0_12 = { package = "rstar", version = "0.12", optional = true }
serde = { version = "1", optional = true, default-features = false, features = ["alloc", "derive"] }

[dev-dependencies]
Expand Down
36 changes: 36 additions & 0 deletions geo-types/src/geometry/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,39 @@ where
}
}
}

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

const DIMENSIONS: usize = 2;

#[inline]
fn generate(mut generator: impl FnMut(usize) -> Self::Scalar) -> Self {
coord! {
x: generator(0),
y: generator(1),
}
}

#[inline]
fn nth(&self, index: usize) -> Self::Scalar {
match index {
0 => self.x,
1 => self.y,
_ => unreachable!(),
}
}

#[inline]
fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar {
match index {
0 => &mut self.x,
1 => &mut self.y,
_ => unreachable!(),
}
}
}
6 changes: 5 additions & 1 deletion geo-types/src/geometry/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq for Line<T> {
feature = "rstar_0_8",
feature = "rstar_0_9",
feature = "rstar_0_10",
feature = "rstar_0_11"
feature = "rstar_0_11",
feature = "rstar_0_12"
))]
macro_rules! impl_rstar_line {
($rstar:ident) => {
Expand Down Expand Up @@ -265,6 +266,9 @@ impl_rstar_line!(rstar_0_10);
#[cfg(feature = "rstar_0_11")]
impl_rstar_line!(rstar_0_11);

#[cfg(feature = "rstar_0_12")]
impl_rstar_line!(rstar_0_12);

#[cfg(test)]
mod test {
use super::*;
Expand Down
6 changes: 5 additions & 1 deletion geo-types/src/geometry/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq for LineString<T> {
feature = "rstar_0_8",
feature = "rstar_0_9",
feature = "rstar_0_10",
feature = "rstar_0_11"
feature = "rstar_0_11",
feature = "rstar_0_12"
))]
macro_rules! impl_rstar_line_string {
($rstar:ident) => {
Expand Down Expand Up @@ -544,6 +545,9 @@ impl_rstar_line_string!(rstar_0_10);
#[cfg(feature = "rstar_0_11")]
impl_rstar_line_string!(rstar_0_11);

#[cfg(feature = "rstar_0_12")]
impl_rstar_line_string!(rstar_0_12);

#[cfg(test)]
mod test {
use super::*;
Expand Down
29 changes: 29 additions & 0 deletions geo-types/src/geometry/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,35 @@ where
}
}

#[cfg(feature = "rstar_0_12")]
impl<T> ::rstar_0_12::Point for Point<T>
where
T: ::num_traits::Float + ::rstar_0_12::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(test)]
mod test {
use super::*;
Expand Down
6 changes: 5 additions & 1 deletion geo-types/src/geometry/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq for Polygon<T> {
feature = "rstar_0_8",
feature = "rstar_0_9",
feature = "rstar_0_10",
feature = "rstar_0_11"
feature = "rstar_0_11",
feature = "rstar_0_12"
))]
macro_rules! impl_rstar_polygon {
($rstar:ident) => {
Expand Down Expand Up @@ -599,3 +600,6 @@ impl_rstar_polygon!(rstar_0_10);

#[cfg(feature = "rstar_0_11")]
impl_rstar_polygon!(rstar_0_11);

#[cfg(feature = "rstar_0_12")]
impl_rstar_polygon!(rstar_0_12);
19 changes: 18 additions & 1 deletion geo-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
//! - `use-rstar_0_9`: Allows geometry types to be inserted into [rstar] R*-trees (`rstar v0.9`)
//! - `use-rstar_0_10`: Allows geometry types to be inserted into [rstar] R*-trees (`rstar v0.10`)
//! - `use-rstar_0_11`: Allows geometry types to be inserted into [rstar] R*-trees (`rstar v0.11`)
//! - `use-rstar_0_12`: Allows geometry types to be inserted into [rstar] R*-trees (`rstar v0.12`)
//!
//! This library can be used in `#![no_std]` environments if the default `std` feature is disabled. At
//! the moment, the `arbitrary` and `use-rstar_0_8` features require `std`. This may change in a
Expand Down Expand Up @@ -140,7 +141,8 @@ mod arbitrary;
feature = "rstar_0_8",
feature = "rstar_0_9",
feature = "rstar_0_10",
feature = "rstar_0_11"
feature = "rstar_0_11",
feature = "rstar_0_12"
))]
#[doc(hidden)]
pub mod private_utils;
Expand Down Expand Up @@ -291,6 +293,21 @@ mod tests {
assert_relative_eq!(25.999999999999996, l.distance_2(&Point::new(4.0, 10.0)));
}

#[cfg(feature = "rstar_0_12")]
#[test]
/// ensure Line's SpatialObject impl is correct
fn line_test_0_12() {
use rstar_0_12::primitives::Line as RStarLine;
use rstar_0_12::{PointDistance, RTreeObject};

let rl = RStarLine::new(Point::new(0.0, 0.0), Point::new(5.0, 5.0));
let l = Line::new(coord! { x: 0.0, y: 0.0 }, coord! { x: 5., y: 5. });
assert_eq!(rl.envelope(), l.envelope());
// difference in 15th decimal place
assert_relative_eq!(26.0, rl.distance_2(&Point::new(4.0, 10.0)));
assert_relative_eq!(25.999999999999996, l.distance_2(&Point::new(4.0, 10.0)));
}

#[test]
fn test_rects() {
let r = Rect::new(coord! { x: -1., y: -1. }, coord! { x: 1., y: 1. });
Expand Down
1 change: 1 addition & 0 deletions geo/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* <https://github.com/georust/geo/pull/1135>
* Add remaining Relate predicates
* <https://github.com/georust/geo/pull/1136>
* Update rstar to v0.12.0

## 0.27.0

Expand Down
4 changes: 2 additions & 2 deletions geo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ use-serde = ["serde", "geo-types/serde"]
earcutr = { version = "0.4.2", optional = true }
spade = { version = "2.2.0", optional = true }
float_next_after = "1.0.0"
geo-types = { version = "0.7.12", features = ["approx", "use-rstar_0_11"] }
geo-types = { version = "0.7.12", features = ["approx", "use-rstar_0_12"] }
geographiclib-rs = { version = "0.2.3", default-features = false }
log = "0.4.11"
num-traits = "0.2"
proj = { version = "0.27.0", optional = true }
robust = "1.1.0"
rstar = "0.11.0"
rstar = "0.12.0"
serde = { version = "1.0", optional = true, features = ["derive"] }

[dev-dependencies]
Expand Down

0 comments on commit c99c426

Please sign in to comment.