diff --git a/geo-types/CHANGES.md b/geo-types/CHANGES.md index 148e831ab..58f97e400 100644 --- a/geo-types/CHANGES.md +++ b/geo-types/CHANGES.md @@ -2,7 +2,8 @@ ## Unreleased -* Add Changes Here +* Implement `Default` on `Coordinate` and `Point` structs (defaults to `(x: 0, y: 0)`) + * ## 0.7.0 diff --git a/geo-types/src/coordinate.rs b/geo-types/src/coordinate.rs index 5c30dd751..5d80e35a3 100644 --- a/geo-types/src/coordinate.rs +++ b/geo-types/src/coordinate.rs @@ -33,6 +33,15 @@ where pub y: T, } +impl Default for Coordinate { + fn default() -> Coordinate { + Coordinate { + x: T::default(), + y: T::default(), + } + } +} + impl From<(T, T)> for Coordinate { fn from(coords: (T, T)) -> Self { Coordinate { diff --git a/geo-types/src/point.rs b/geo-types/src/point.rs index d15791c7f..4715fc7cd 100644 --- a/geo-types/src/point.rs +++ b/geo-types/src/point.rs @@ -26,7 +26,7 @@ use std::ops::{Add, Div, Mul, Neg, Sub}; /// let c = Coordinate { x: 10., y: 20. }; /// let p2: Point = c.into(); /// ``` -#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash)] +#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash, Default)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Point(pub Coordinate) where