From 1efd87a9bf3f4140f252014b59ff174af8e014aa Mon Sep 17 00:00:00 2001 From: Rory McCann Date: Mon, 5 Nov 2018 21:18:37 +0100 Subject: [PATCH] Area can work on some non-Float geometries (e.g. Rect) --- geo/src/algorithm/area.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/geo/src/algorithm/area.rs b/geo/src/algorithm/area.rs index 917f3c0c2..0922265d5 100644 --- a/geo/src/algorithm/area.rs +++ b/geo/src/algorithm/area.rs @@ -1,5 +1,5 @@ use num_traits::Float; -use {Line, LineString, MultiPolygon, Polygon, Rect, Triangle}; +use {Line, LineString, MultiPolygon, Polygon, Rect, Triangle, CoordinateType}; use algorithm::winding_order::twice_signed_ring_area; @@ -7,7 +7,7 @@ use algorithm::winding_order::twice_signed_ring_area; pub trait Area where - T: Float, + T: CoordinateType, { /// Signed area of a geometry. /// @@ -44,7 +44,7 @@ where impl Area for Line where - T: Float, + T: CoordinateType, { fn area(&self) -> T { T::zero() @@ -77,7 +77,7 @@ where impl Area for Rect where - T: Float, + T: CoordinateType { fn area(&self) -> T { (self.max.x - self.min.x) * (self.max.y - self.min.y) @@ -121,11 +121,17 @@ mod test { } #[test] fn rectangle_test() { - let rect = Rect { + let rect1: Rect = Rect { min: Coordinate { x: 10., y: 30. }, max: Coordinate { x: 20., y: 40. }, }; - assert_relative_eq!(rect.area(), 100.); + assert_relative_eq!(rect1.area(), 100.); + + let rect2: Rect = Rect { + min: Coordinate { x: 10, y: 30 }, + max: Coordinate { x: 20, y: 40 }, + }; + assert_eq!(rect2.area(), 100); } #[test] fn area_polygon_inner_test() {