Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Default on all num types #751

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions geo-types/src/coordinate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{coord, CoordNum, Point};

#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
use crate::CoordFloat;

#[cfg(any(feature = "approx", test))]
use approx::{AbsDiffEq, RelativeEq, UlpsEq};

Expand Down Expand Up @@ -303,7 +306,7 @@ where
#[cfg(feature = "rstar_0_8")]
impl<T> ::rstar_0_8::Point for Coordinate<T>
where
T: ::num_traits::Float + ::rstar_0_8::RTreeNum,
T: CoordFloat + ::rstar_0_8::RTreeNum,
{
type Scalar = T;

Expand Down Expand Up @@ -336,7 +339,7 @@ where
#[cfg(feature = "rstar_0_9")]
impl<T> ::rstar_0_9::Point for Coordinate<T>
where
T: ::num_traits::Float + ::rstar_0_9::RTreeNum,
T: CoordFloat + ::rstar_0_9::RTreeNum,
{
type Scalar = T;

Expand Down
10 changes: 1 addition & 9 deletions geo-types/src/geometry_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,10 @@ use std::ops::{Index, IndexMut};
/// println!("{:?}", gc[0]);
/// ```
///
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Debug, Hash, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct GeometryCollection<T: CoordNum>(pub Vec<Geometry<T>>);

// Implementing Default by hand because T does not have Default restriction
// todo: consider adding Default as a CoordNum requirement
impl<T: CoordNum> Default for GeometryCollection<T> {
fn default() -> Self {
Self(Vec::new())
}
}

impl<T: CoordNum> GeometryCollection<T> {
/// Return an empty GeometryCollection
pub fn new() -> Self {
Expand Down
4 changes: 2 additions & 2 deletions geo-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl<T: Num + Copy + NumCast + PartialOrd + Debug> CoordinateType for T {}
/// For algorithms which only make sense for floating point, like area or length calculations,
/// see [CoordFloat](trait.CoordFloat.html).
#[allow(deprecated)]
pub trait CoordNum: CoordinateType + Debug {}
pub trait CoordNum: CoordinateType + Debug + Default {}
#[allow(deprecated)]
impl<T: CoordinateType + Debug> CoordNum for T {}
impl<T: CoordinateType + Debug + Default> CoordNum for T {}

pub trait CoordFloat: CoordNum + Float {}
impl<T: CoordNum + Float> CoordFloat for T {}
Expand Down
6 changes: 4 additions & 2 deletions geo-types/src/line.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
use crate::CoordFloat;
use crate::{CoordNum, Coordinate, Point};
#[cfg(any(feature = "approx", test))]
use approx::{AbsDiffEq, RelativeEq};
Expand Down Expand Up @@ -226,7 +228,7 @@ macro_rules! impl_rstar_line {
($rstar:ident) => {
impl<T> ::$rstar::RTreeObject for Line<T>
where
T: ::num_traits::Float + ::$rstar::RTreeNum,
T: CoordFloat + ::$rstar::RTreeNum,
{
type Envelope = ::$rstar::AABB<Point<T>>;

Expand All @@ -238,7 +240,7 @@ macro_rules! impl_rstar_line {

impl<T> ::$rstar::PointDistance for Line<T>
where
T: ::num_traits::Float + ::$rstar::RTreeNum,
T: CoordFloat + ::$rstar::RTreeNum,
{
fn distance_2(&self, point: &Point<T>) -> T {
let d = crate::private_utils::point_line_euclidean_distance(*point, *self);
Expand Down
6 changes: 4 additions & 2 deletions geo-types/src/line_string.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(any(feature = "rstar_0_8", feature = "rstar_0_9"))]
use crate::CoordFloat;
#[cfg(any(feature = "approx", test))]
use approx::{AbsDiffEq, RelativeEq};

Expand Down Expand Up @@ -483,7 +485,7 @@ macro_rules! impl_rstar_line_string {
($rstar:ident) => {
impl<T> ::$rstar::RTreeObject for LineString<T>
where
T: ::num_traits::Float + ::$rstar::RTreeNum,
T: CoordFloat + ::$rstar::RTreeNum,
{
type Envelope = ::$rstar::AABB<Point<T>>;

Expand All @@ -505,7 +507,7 @@ macro_rules! impl_rstar_line_string {

impl<T> ::$rstar::PointDistance for LineString<T>
where
T: ::num_traits::Float + ::$rstar::RTreeNum,
T: CoordFloat + ::$rstar::RTreeNum,
{
fn distance_2(&self, point: &Point<T>) -> T {
let d = crate::private_utils::point_line_string_euclidean_distance(*point, self);
Expand Down
4 changes: 2 additions & 2 deletions geo-types/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ where
// These are required for rstar RTree
impl<T> ::rstar_0_8::Point for Point<T>
where
T: ::num_traits::Float + ::rstar_0_8::RTreeNum,
T: CoordFloat + ::rstar_0_8::RTreeNum,
{
type Scalar = T;

Expand Down Expand Up @@ -580,7 +580,7 @@ where
#[cfg(feature = "rstar_0_9")]
impl<T> ::rstar_0_9::Point for Point<T>
where
T: ::num_traits::Float + ::rstar_0_9::RTreeNum,
T: CoordFloat + ::rstar_0_9::RTreeNum,
{
type Scalar = T;

Expand Down
1 change: 1 addition & 0 deletions geo/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Add `LinesIter` algorithm to iterate over the lines in geometries.
* Very similar to `CoordsIter`, but only implemented where it makes sense (e.g., for `Polygon`, `Rect`, but not `Point`).
* <https://github.com/georust/geo/pull/757>
* BREAKING: Add `Default` constraint to all `CoordNum`/`CoordFloat` values.

## 0.19.0

Expand Down