Skip to content

Commit

Permalink
Merge georust#339
Browse files Browse the repository at this point in the history
339: Geometrycollection ergonomics r=frewsxcv a=rory

just some minor ergonomic improvements

Co-authored-by: Rory McCann <rory@technomancy.org>
Co-authored-by: Corey Farwell <coreyf@rwell.org>
  • Loading branch information
3 people committed Feb 17, 2019
2 parents b8a9514 + 382c020 commit fc4a6ee
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions geo-types/src/geometry_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,33 @@ pub struct GeometryCollection<T>(pub Vec<Geometry<T>>)
where
T: CoordinateType;

impl<T: CoordinateType> GeometryCollection<T> {
/// Return an empty GeometryCollection
pub fn new() -> GeometryCollection<T> {
GeometryCollection(Vec::new())
}

/// Number of geometries in this GeometryCollection
pub fn len(&self) -> usize {
self.0.len()
}

/// Is this GeometryCollection empty
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}


/// Convert any Geometry (or anything that can be converted to a Geometry) into a
/// GeometryCollection
impl<T: CoordinateType, IG: Into<Geometry<T>>> From<IG> for GeometryCollection<T> {
fn from(x: IG) -> Self {
GeometryCollection(vec![x.into()])
}
}

/// Collect Geometries (or what can be converted to a Geometry) into a GeometryCollection
impl<T: CoordinateType, IG: Into<Geometry<T>>> FromIterator<IG> for GeometryCollection<T> {
fn from_iter<I: IntoIterator<Item = IG>>(iter: I) -> Self {
GeometryCollection(iter.into_iter().map(|g| g.into()).collect())
Expand Down

0 comments on commit fc4a6ee

Please sign in to comment.