From c9b923786f0147bb27ae673c911350cc37d06e99 Mon Sep 17 00:00:00 2001 From: Rory McCann Date: Wed, 13 Feb 2019 13:18:37 +0100 Subject: [PATCH 1/3] GeometryCollection gets ::empty constructor and things to see how many geometries it contains --- geo-types/src/geometry_collection.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/geo-types/src/geometry_collection.rs b/geo-types/src/geometry_collection.rs index 45410e7cb..0d9a14b2d 100644 --- a/geo-types/src/geometry_collection.rs +++ b/geo-types/src/geometry_collection.rs @@ -11,6 +11,24 @@ pub struct GeometryCollection(pub Vec>) where T: CoordinateType; +impl GeometryCollection { + /// Return an empty GeometryCollection + pub fn empty() -> GeometryCollection { + 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() + } +} + + impl>> From for GeometryCollection { fn from(x: IG) -> Self { GeometryCollection(vec![x.into()]) From dbf121fa5d15f045cc6ee28a16f0898b151c78bb Mon Sep 17 00:00:00 2001 From: Rory McCann Date: Wed, 13 Feb 2019 13:19:59 +0100 Subject: [PATCH 2/3] doc comments --- geo-types/src/geometry_collection.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/geo-types/src/geometry_collection.rs b/geo-types/src/geometry_collection.rs index 0d9a14b2d..2663a64ff 100644 --- a/geo-types/src/geometry_collection.rs +++ b/geo-types/src/geometry_collection.rs @@ -29,12 +29,15 @@ impl GeometryCollection { } +/// Convert any Geometry (or anything that can be converted to a Geometry) into a +/// GeometryCollection impl>> From for GeometryCollection { fn from(x: IG) -> Self { GeometryCollection(vec![x.into()]) } } +/// Collect Geometries (or what can be converted to a Geometry) into a GeometryCollection impl>> FromIterator for GeometryCollection { fn from_iter>(iter: I) -> Self { GeometryCollection(iter.into_iter().map(|g| g.into()).collect()) From 382c0200b7401dcc27ec75b4fc11c7b547312997 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 16 Feb 2019 21:01:04 -0500 Subject: [PATCH 3/3] Update geometry_collection.rs --- geo-types/src/geometry_collection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geo-types/src/geometry_collection.rs b/geo-types/src/geometry_collection.rs index 2663a64ff..90e154734 100644 --- a/geo-types/src/geometry_collection.rs +++ b/geo-types/src/geometry_collection.rs @@ -13,7 +13,7 @@ where impl GeometryCollection { /// Return an empty GeometryCollection - pub fn empty() -> GeometryCollection { + pub fn new() -> GeometryCollection { GeometryCollection(Vec::new()) }