Skip to content

Commit

Permalink
Merge #616
Browse files Browse the repository at this point in the history
616: Implement Default for Coordinate and Point r=frewsxcv a=sbland

- [/ ] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md).
- [/ ] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

PR for issue #612

Co-authored-by: Sam Bland <sbland.co.uk@gmail.com>
Co-authored-by: Corey Farwell <coreyf@rwell.org>
  • Loading branch information
3 people committed Feb 5, 2021
2 parents e59fb5a + a26c02b commit 6a74467
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion geo-types/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Unreleased

* Add Changes Here
* Implement `Default` on `Coordinate` and `Point` structs (defaults to `(x: 0, y: 0)`)
* <https://github.com/georust/geo/pull/616>

## 0.7.0

Expand Down
9 changes: 9 additions & 0 deletions geo-types/src/coordinate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ where
pub y: T,
}

impl<T: Default + CoordNum> Default for Coordinate<T> {
fn default() -> Coordinate<T> {
Coordinate {
x: T::default(),
y: T::default(),
}
}
}

impl<T: CoordNum> From<(T, T)> for Coordinate<T> {
fn from(coords: (T, T)) -> Self {
Coordinate {
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 @@ -26,7 +26,7 @@ use std::ops::{Add, Div, Mul, Neg, Sub};
/// let c = Coordinate { x: 10., y: 20. };
/// let p2: Point<f64> = 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<T>(pub Coordinate<T>)
where
Expand Down

0 comments on commit 6a74467

Please sign in to comment.