Skip to content

Commit

Permalink
Merge pull request #1 from georust/mkirk/approx-feature-juggling
Browse files Browse the repository at this point in the history
Rename `relative_eq` feature to `approx` and make optional
  • Loading branch information
martinfrances107 committed Jan 2, 2021
2 parents d347afd + fde7395 commit e90ee64
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 36 deletions.
2 changes: 2 additions & 0 deletions geo-types/CHANGES.md
Expand Up @@ -4,6 +4,8 @@

* `geo_types::LineString::num_coords` has been deprecated in favor of `geo::algorithm::coords_iter::CoordsIter::coords_count`
* <https://github.com/georust/geo/pull/563>
* Introduce `use-rstar` feature rather than `rstar` so that `approx` dependency can be optional
* <https://github.com/georust/geo/pull/567>

## 0.6.2

Expand Down
14 changes: 12 additions & 2 deletions geo-types/Cargo.toml
Expand Up @@ -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"],
]
12 changes: 5 additions & 7 deletions 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.
///
Expand Down Expand Up @@ -243,7 +241,7 @@ impl<T: CoordinateType> Zero for Coordinate<T> {
}
}

#[cfg(feature = "relative_eq")]
#[cfg(any(feature = "approx", test))]
impl<T: CoordinateType + AbsDiffEq> AbsDiffEq for Coordinate<T>
where
T::Epsilon: Copy,
Expand All @@ -261,7 +259,7 @@ where
}
}

#[cfg(feature = "relative_eq")]
#[cfg(any(feature = "approx", test))]
impl<T: CoordinateType + RelativeEq> RelativeEq for Coordinate<T>
where
T::Epsilon: Copy,
Expand All @@ -278,7 +276,7 @@ where
}
}

#[cfg(test)]
#[cfg(any(feature = "approx", test))]
impl<T: CoordinateType + UlpsEq> UlpsEq for Coordinate<T>
where
T::Epsilon: Copy,
Expand Down
2 changes: 2 additions & 0 deletions geo-types/src/lib.rs
Expand Up @@ -28,6 +28,7 @@ extern crate serde;
#[cfg(feature = "rstar")]
extern crate rstar;

#[cfg(test)]
#[macro_use]
extern crate approx;

Expand Down Expand Up @@ -79,6 +80,7 @@ pub use crate::rect::{InvalidRectCoordinatesError, Rect};
#[macro_use]
mod macros;

#[cfg(feature = "rstar")]
#[doc(hidden)]
pub mod private_utils;

Expand Down
10 changes: 4 additions & 6 deletions 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).
Expand Down Expand Up @@ -168,7 +166,7 @@ impl<T: CoordinateType> From<[(T, T); 2]> for Line<T> {
Line::new(coord[0], coord[1])
}
}
#[cfg(feature = "relative_eq")]
#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for Line<T>
where
T: AbsDiffEq<Epsilon = T> + CoordinateType + RelativeEq,
Expand Down Expand Up @@ -202,7 +200,7 @@ where
}
}

#[cfg(feature = "relative_eq")]
#[cfg(any(feature = "approx", test))]
impl<T: AbsDiffEq<Epsilon = T> + CoordinateType> AbsDiffEq for Line<T> {
type Epsilon = T;

Expand Down
10 changes: 4 additions & 6 deletions 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;
Expand Down Expand Up @@ -287,7 +285,7 @@ impl<T: CoordinateType> IndexMut<usize> for LineString<T> {
}
}

#[cfg(feature = "relative_eq")]
#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for LineString<T>
where
T: AbsDiffEq<Epsilon = T> + CoordinateType + RelativeEq,
Expand Down Expand Up @@ -334,7 +332,7 @@ where
}
}

#[cfg(feature = "relative_eq")]
#[cfg(any(feature = "approx", test))]
impl<T: AbsDiffEq<Epsilon = T> + CoordinateType> AbsDiffEq for LineString<T> {
type Epsilon = T;

Expand Down
11 changes: 5 additions & 6 deletions 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;

Expand Down Expand Up @@ -96,7 +95,7 @@ impl<T: CoordinateType> MultiPoint<T> {
}
}

#[cfg(feature = "relative_eq")]
#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for MultiPoint<T>
where
T: AbsDiffEq<Epsilon = T> + CoordinateType + RelativeEq,
Expand Down Expand Up @@ -135,7 +134,7 @@ where
}
}

#[cfg(feature = "relative_eq")]
#[cfg(any(feature = "approx", test))]
impl<T> AbsDiffEq for MultiPoint<T>
where
T: AbsDiffEq<Epsilon = T> + CoordinateType,
Expand Down
10 changes: 5 additions & 5 deletions 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};
Expand Down Expand Up @@ -414,7 +413,7 @@ where
}
}

#[cfg(feature = "relative_eq")]
#[cfg(any(feature = "approx", test))]
impl<T> RelativeEq for Point<T>
where
T: AbsDiffEq<Epsilon = T> + CoordinateType + RelativeEq,
Expand Down Expand Up @@ -446,7 +445,8 @@ where
self.0.relative_eq(&other.0, epsilon, max_relative)
}
}
#[cfg(feature = "relative_eq")]

#[cfg(any(feature = "approx", test))]
impl<T> AbsDiffEq for Point<T>
where
T: AbsDiffEq<Epsilon = T> + CoordinateType,
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/private_utils.rs
Expand Up @@ -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<T>(line_string: &LineString<T>, point: Point<T>) -> bool
Expand Down
4 changes: 1 addition & 3 deletions geo/Cargo.toml
Expand Up @@ -22,20 +22,18 @@ 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"]

[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]]
Expand Down

0 comments on commit e90ee64

Please sign in to comment.