Skip to content

Commit

Permalink
Merge #435
Browse files Browse the repository at this point in the history
435: derive Eq for other core geo types r=frewsxcv a=michaelkirk

Adds `Eq` conformance to other core geo types, building off of #431

> Seems reasonable to me! Yeah +1 to adding the same impl for all the other core geo types

Rather than spelling out the impl, I've taken advantage of how `derive` already bounds the generated impl for us. See rust-lang/rust#21237 for more details

I wrote a few doc-tests while developing, but I reverted them in fc33f9f since they're pretty verbose, and seem superfluous since they're only asserting rust language semantics rather than anything substantial in this lib.

I can un-revert them if you'd prefer. 

Co-authored-by: Michael Kirk <[email protected]>
  • Loading branch information
bors[bot] and michaelkirk authored Apr 2, 2020
2 parents a057c21 + fc33f9f commit 903a048
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 14 deletions.
4 changes: 1 addition & 3 deletions geo-types/src/coordinate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{CoordinateType, Point};
/// as an envelope, a precision model, and spatial reference system
/// information), a `Coordinate` only contains ordinate values and accessor
/// methods.
#[derive(PartialEq, Clone, Copy, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Coordinate<T>
where
Expand All @@ -17,8 +17,6 @@ where
pub y: T,
}

impl<T: CoordinateType> std::cmp::Eq for Coordinate<T> where T: std::cmp::Eq {}

impl<T: CoordinateType> From<(T, T)> for Coordinate<T> {
fn from(coords: (T, T)) -> Self {
Coordinate {
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::fmt;
/// let pn = Point::try_from(pe).unwrap();
/// ```
///
#[derive(PartialEq, Clone, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
pub enum Geometry<T>
where
T: CoordinateType,
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/geometry_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use std::ops::{Index, IndexMut};
/// println!("{:?}", gc[0]);
/// ```
///
#[derive(PartialEq, Clone, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
pub struct GeometryCollection<T>(pub Vec<Geometry<T>>)
where
T: CoordinateType;
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/line.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{Coordinate, CoordinateType, Point};

/// A line segment made up of exactly two [`Point`s](struct.Point.html).
#[derive(PartialEq, Clone, Copy, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Line<T>
where
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use std::ops::{Index, IndexMut};
/// }
/// ```
#[derive(PartialEq, Clone, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct LineString<T>(pub Vec<Coordinate<T>>)
where
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/multi_line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::iter::FromIterator;
/// Can be created from a `Vec` of `LineString`s, or from an Iterator which yields `LineString`s.
///
/// Iterating over this objects, yields the component `LineString`s.
#[derive(PartialEq, Clone, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MultiLineString<T>(pub Vec<LineString<T>>)
where
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/multi_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::iter::FromIterator;
/// println!("Point x = {}, y = {}", point.x(), point.y());
/// }
/// ```
#[derive(PartialEq, Clone, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MultiPoint<T>(pub Vec<Point<T>>)
where
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/multi_polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::iter::FromIterator;
/// Can be created from a `Vec` of `Polygon`s, or `collect`ed from an Iterator which yields `Polygon`s.
///
/// Iterating over this object yields the component Polygons.
#[derive(PartialEq, Clone, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MultiPolygon<T>(pub Vec<Polygon<T>>)
where
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::ops::Sub;
/// let c = Coordinate { x: 10., y: 20. };
/// let p2: Point<f64> = c.into();
/// ```
#[derive(PartialEq, Clone, Copy, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Point<T>(pub Coordinate<T>)
where
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use num_traits::{Float, Signed};
/// the first `Coordinate`.
///
/// [`LineString`]: line_string/struct.LineString.html
#[derive(PartialEq, Clone, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Polygon<T>
where
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/rect.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{polygon, Coordinate, CoordinateType, Polygon};

/// A bounded 2D quadrilateral whose area is defined by minimum and maximum `Coordinates`.
#[derive(PartialEq, Clone, Copy, Debug, Hash)]
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Rect<T>
where
Expand Down
2 changes: 1 addition & 1 deletion geo-types/src/triangle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{polygon, Coordinate, CoordinateType, Line, Polygon};

/// A bounded 2D area whose three vertices are defined by `Coordinate`s.
#[derive(Copy, Clone, Debug, Hash, PartialEq)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Triangle<T: CoordinateType>(pub Coordinate<T>, pub Coordinate<T>, pub Coordinate<T>);

Expand Down

0 comments on commit 903a048

Please sign in to comment.