From 5b12c2203479d127cfdee51e8c088f55d3973c25 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 15 Jan 2017 10:26:58 -0500 Subject: [PATCH] Add traits for each geometry type. https://github.com/georust/rust-geo/issues/67 --- src/traits.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/traits.rs b/src/traits.rs index ae0eb84348..1695920591 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -6,3 +6,49 @@ pub trait ToGeo { fn to_geo(&self) -> Geometry; } + +pub trait Point { + fn x(&self) -> f64; + fn y(&self) -> f64; + fn opt_z(&self) -> Option { + None + } + fn opt_m(&self) -> Option { + None + } +} + +pub trait LineString<'a> { + type ItemType: 'a + Point; + type Iter: Iterator; + + fn points(&'a self) -> Self::Iter; +} + +pub trait Polygon<'a> { + type ItemType: 'a + LineString<'a>; + type Iter: Iterator; + + fn rings(&'a self) -> Self::Iter; +} + +pub trait MultiPoint<'a> { + type ItemType: 'a + Point; + type Iter: Iterator; + + fn points(&'a self) -> Self::Iter; +} + +pub trait MultiLineString<'a> { + type ItemType: 'a + LineString<'a>; + type Iter: Iterator; + + fn lines(&'a self) -> Self::Iter; +} + +pub trait MultiPolygon<'a> { + type ItemType: 'a + Polygon<'a>; + type Iter: Iterator; + + fn polygons(&'a self) -> Self::Iter; +}