From 955270514d3c978dfea576685160db5f8b0131da Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Mon, 14 Oct 2024 15:15:37 -0400 Subject: [PATCH] Fix geo-types empty Polygon --- geo-traits/src/polygon.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/geo-traits/src/polygon.rs b/geo-traits/src/polygon.rs index 82e9e7c9c..84c6f8bfd 100644 --- a/geo-traits/src/polygon.rs +++ b/geo-traits/src/polygon.rs @@ -61,8 +61,12 @@ impl PolygonTrait for Polygon { } fn exterior(&self) -> Option> { - // geo-types doesn't really have a way to describe an empty polygon - Some(Polygon::exterior(self)) + let ext_ring = Polygon::exterior(self); + if ext_ring.num_points() == 0 { + None + } else { + Some(ext_ring) + } } fn num_interiors(&self) -> usize { @@ -84,8 +88,12 @@ impl<'a, T: CoordNum> PolygonTrait for &'a Polygon { } fn exterior(&self) -> Option> { - // geo-types doesn't really have a way to describe an empty polygon - Some(Polygon::exterior(self)) + let ext_ring = Polygon::exterior(self); + if ext_ring.num_points() == 0 { + None + } else { + Some(ext_ring) + } } fn num_interiors(&self) -> usize {