diff --git a/geo-types/CHANGES.md b/geo-types/CHANGES.md index 61caf57f3..6fb77e72a 100644 --- a/geo-types/CHANGES.md +++ b/geo-types/CHANGES.md @@ -4,6 +4,8 @@ * `geo_types::LineString::num_coords` has been deprecated in favor of `geo::algorithm::coords_iter::CoordsIter::coords_count` * +* Introduce `use-rstar` feature rather than `rstar` so that `approx` dependency can be optional + * ## 0.6.2 diff --git a/geo-types/Cargo.toml b/geo-types/Cargo.toml index 325c02894..be6c37332 100644 --- a/geo-types/Cargo.toml +++ b/geo-types/Cargo.toml @@ -11,13 +11,23 @@ description = "Geospatial primitive data types" edition = "2018" [features] -relative_eq = [] +use-rstar = ["rstar", "approx"] [dependencies] -approx = "0.4.0" +approx = { version = "0.4.0", optional = true } num-traits = "0.2" serde = { version = "1", optional = true, features = ["derive"] } +# Prefer `use-rstar` feature rather than enabling rstar directly. +# rstar integration relies on the optional approx crate, but implicit features cannot yet enable other features. +# See: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#namespaced-features rstar = { version = "0.8", optional = true } [dev-dependencies] approx = "0.4.0" + +[package.metadata.cargo-all-features] + +skip_feature_sets = [ + # must be enabled via use-rstar + ["rstar"], +] \ No newline at end of file diff --git a/geo-types/src/coordinate.rs b/geo-types/src/coordinate.rs index 450e3961c..c51c94a14 100644 --- a/geo-types/src/coordinate.rs +++ b/geo-types/src/coordinate.rs @@ -1,10 +1,8 @@ use crate::{CoordinateType, Point}; -#[cfg(any(feature = "relative_eq", test))] -use approx::{AbsDiffEq, RelativeEq}; +#[cfg(any(feature = "approx", test))] +use approx::{AbsDiffEq, RelativeEq, UlpsEq}; -#[cfg(test)] -use approx::UlpsEq; /// A lightweight struct used to store coordinates on the 2-dimensional /// Cartesian plane. /// @@ -243,7 +241,7 @@ impl Zero for Coordinate { } } -#[cfg(feature = "relative_eq")] +#[cfg(any(feature = "approx", test))] impl AbsDiffEq for Coordinate where T::Epsilon: Copy, @@ -261,7 +259,7 @@ where } } -#[cfg(feature = "relative_eq")] +#[cfg(any(feature = "approx", test))] impl RelativeEq for Coordinate where T::Epsilon: Copy, @@ -278,7 +276,7 @@ where } } -#[cfg(test)] +#[cfg(any(feature = "approx", test))] impl UlpsEq for Coordinate where T::Epsilon: Copy, diff --git a/geo-types/src/lib.rs b/geo-types/src/lib.rs index 74499fb0a..56b947ec5 100644 --- a/geo-types/src/lib.rs +++ b/geo-types/src/lib.rs @@ -28,6 +28,7 @@ extern crate serde; #[cfg(feature = "rstar")] extern crate rstar; +#[cfg(test)] #[macro_use] extern crate approx; @@ -79,6 +80,7 @@ pub use crate::rect::{InvalidRectCoordinatesError, Rect}; #[macro_use] mod macros; +#[cfg(feature = "rstar")] #[doc(hidden)] pub mod private_utils; diff --git a/geo-types/src/line.rs b/geo-types/src/line.rs index f69a29e93..95b5a2839 100644 --- a/geo-types/src/line.rs +++ b/geo-types/src/line.rs @@ -1,8 +1,6 @@ use crate::{Coordinate, CoordinateType, Point}; -#[cfg(feature = "relative_eq")] -use approx::AbsDiffEq; -#[cfg(feature = "relative_eq")] -use approx::RelativeEq; +#[cfg(any(feature = "approx", test))] +use approx::{AbsDiffEq, RelativeEq}; /// A line segment made up of exactly two /// [`Coordinate`s](struct.Coordinate.html). @@ -168,7 +166,7 @@ impl From<[(T, T); 2]> for Line { Line::new(coord[0], coord[1]) } } -#[cfg(feature = "relative_eq")] +#[cfg(any(feature = "approx", test))] impl RelativeEq for Line where T: AbsDiffEq + CoordinateType + RelativeEq, @@ -202,7 +200,7 @@ where } } -#[cfg(feature = "relative_eq")] +#[cfg(any(feature = "approx", test))] impl + CoordinateType> AbsDiffEq for Line { type Epsilon = T; diff --git a/geo-types/src/line_string.rs b/geo-types/src/line_string.rs index c9754e579..31f5aacfb 100644 --- a/geo-types/src/line_string.rs +++ b/geo-types/src/line_string.rs @@ -1,7 +1,5 @@ -#[cfg(feature = "relative_eq")] -use approx::AbsDiffEq; -#[cfg(feature = "relative_eq")] -use approx::RelativeEq; +#[cfg(any(feature = "approx", test))] +use approx::{AbsDiffEq, RelativeEq}; use crate::{Coordinate, CoordinateType, Line, Point, Triangle}; use std::iter::FromIterator; @@ -287,7 +285,7 @@ impl IndexMut for LineString { } } -#[cfg(feature = "relative_eq")] +#[cfg(any(feature = "approx", test))] impl RelativeEq for LineString where T: AbsDiffEq + CoordinateType + RelativeEq, @@ -334,7 +332,7 @@ where } } -#[cfg(feature = "relative_eq")] +#[cfg(any(feature = "approx", test))] impl + CoordinateType> AbsDiffEq for LineString { type Epsilon = T; diff --git a/geo-types/src/multi_point.rs b/geo-types/src/multi_point.rs index be97a09b8..83facc604 100644 --- a/geo-types/src/multi_point.rs +++ b/geo-types/src/multi_point.rs @@ -1,8 +1,7 @@ use crate::{CoordinateType, Point}; -#[cfg(feature = "relative_eq")] -use approx::AbsDiffEq; -#[cfg(feature = "relative_eq")] -use approx::RelativeEq; + +#[cfg(any(feature = "approx", test))] +use approx::{AbsDiffEq, RelativeEq}; use std::iter::FromIterator; @@ -96,7 +95,7 @@ impl MultiPoint { } } -#[cfg(feature = "relative_eq")] +#[cfg(any(feature = "approx", test))] impl RelativeEq for MultiPoint where T: AbsDiffEq + CoordinateType + RelativeEq, @@ -135,7 +134,7 @@ where } } -#[cfg(feature = "relative_eq")] +#[cfg(any(feature = "approx", test))] impl AbsDiffEq for MultiPoint where T: AbsDiffEq + CoordinateType, diff --git a/geo-types/src/point.rs b/geo-types/src/point.rs index e1cbe9d01..02a2a2de9 100644 --- a/geo-types/src/point.rs +++ b/geo-types/src/point.rs @@ -1,8 +1,7 @@ use crate::{Coordinate, CoordinateType}; -use approx::AbsDiffEq; -#[cfg(feature = "relative_eq")] -use approx::RelativeEq; +#[cfg(any(feature = "approx", test))] +use approx::{AbsDiffEq, RelativeEq}; use num_traits::Float; use std::ops::{Add, Div, Mul, Neg, Sub}; @@ -414,7 +413,7 @@ where } } -#[cfg(feature = "relative_eq")] +#[cfg(any(feature = "approx", test))] impl RelativeEq for Point where T: AbsDiffEq + CoordinateType + RelativeEq, @@ -446,7 +445,8 @@ where self.0.relative_eq(&other.0, epsilon, max_relative) } } -#[cfg(feature = "relative_eq")] + +#[cfg(any(feature = "approx", test))] impl AbsDiffEq for Point where T: AbsDiffEq + CoordinateType, diff --git a/geo-types/src/private_utils.rs b/geo-types/src/private_utils.rs index efdda6f71..b84f258be 100644 --- a/geo-types/src/private_utils.rs +++ b/geo-types/src/private_utils.rs @@ -127,7 +127,7 @@ where T: Float, { let distance = line_euclidean_length(Line::new(p1, p2)).to_f32().unwrap(); - relative_eq!(distance, 0.0) + approx::relative_eq!(distance, 0.0) } pub fn line_string_contains_point(line_string: &LineString, point: Point) -> bool diff --git a/geo/Cargo.toml b/geo/Cargo.toml index 12097a746..52da54c36 100644 --- a/geo/Cargo.toml +++ b/geo/Cargo.toml @@ -22,12 +22,11 @@ geographiclib-rs = { version = "0.2" } proj = { version = "0.20.3", optional = true } -geo-types = { version = "0.6.2", optional = true, path = "../geo-types", features = ["rstar"] } +geo-types = { version = "0.6.2", path = "../geo-types", features = ["approx", "use-rstar"] } robust = { version = "0.2.2" } [features] -default = ["geo-types"] use-proj = ["proj"] proj-network = ["use-proj", "proj/network"] use-serde = ["serde", "geo-types/serde"] @@ -35,7 +34,6 @@ use-serde = ["serde", "geo-types/serde"] [dev-dependencies] approx = "0.4.0" criterion = { version = "0.3" } -geo-types = { version = "0.6.2", path = "../geo-types", features = ["relative_eq", "rstar"] } rand = "0.8.0" [[bench]]