Skip to content

Commit b5195e2

Browse files
committed
Add associated return type for BoundingBox algorithm trait.
1 parent b1410a6 commit b5195e2

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/algorithm/boundingbox.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use types::{Bbox, Point, MultiPoint, Line, LineString, MultiLineString, Polygon,
55
/// Calculation of the bounding box of a geometry.
66
77
pub trait BoundingBox<T: Float> {
8+
type Output;
9+
810
/// Return the Bounding Box of a geometry
911
///
1012
/// ```
@@ -24,7 +26,7 @@ pub trait BoundingBox<T: Float> {
2426
/// assert_eq!(118.34, bbox.ymax);
2527
/// ```
2628
///
27-
fn bbox(&self) -> Option<Bbox<T>>;
29+
fn bbox(&self) -> Self::Output;
2830
}
2931

3032

@@ -57,56 +59,66 @@ fn get_bbox<'a, I, T>(collection: I) -> Option<Bbox<T>>
5759
impl<T> BoundingBox<T> for MultiPoint<T>
5860
where T: Float
5961
{
62+
type Output = Option<Bbox<T>>;
63+
6064
///
6165
/// Return the BoundingBox for a MultiPoint
6266
///
63-
fn bbox(&self) -> Option<Bbox<T>> {
67+
fn bbox(&self) -> Self::Output {
6468
get_bbox(&self.0)
6569
}
6670
}
6771

6872
impl<T> BoundingBox<T> for Line<T>
6973
where T: Float
7074
{
71-
fn bbox(&self) -> Option<Bbox<T>> {
75+
type Output = Bbox<T>;
76+
77+
fn bbox(&self) -> Self::Output {
7278
let a = self.start;
7379
let b = self.end;
7480
let (xmin, xmax) = if a.x() <= b.x() {(a.x(), b.x())} else {(b.x(), a.x())};
7581
let (ymin, ymax) = if a.y() <= b.y() {(a.y(), b.y())} else {(b.y(), a.y())};
76-
Some(Bbox {xmin: xmin, xmax: xmax,
77-
ymin: ymin, ymax: ymax})
82+
Bbox {xmin: xmin, xmax: xmax,
83+
ymin: ymin, ymax: ymax}
7884
}
7985
}
8086

8187
impl<T> BoundingBox<T> for LineString<T>
8288
where T: Float
8389
{
90+
type Output = Option<Bbox<T>>;
91+
8492
///
8593
/// Return the BoundingBox for a LineString
8694
///
87-
fn bbox(&self) -> Option<Bbox<T>> {
95+
fn bbox(&self) -> Self::Output {
8896
get_bbox(&self.0)
8997
}
9098
}
9199

92100
impl<T> BoundingBox<T> for MultiLineString<T>
93101
where T: Float
94102
{
103+
type Output = Option<Bbox<T>>;
104+
95105
///
96106
/// Return the BoundingBox for a MultiLineString
97107
///
98-
fn bbox(&self) -> Option<Bbox<T>> {
108+
fn bbox(&self) -> Self::Output {
99109
get_bbox(self.0.iter().flat_map(|line| line.0.iter()))
100110
}
101111
}
102112

103113
impl<T> BoundingBox<T> for Polygon<T>
104114
where T: Float
105115
{
116+
type Output = Option<Bbox<T>>;
117+
106118
///
107119
/// Return the BoundingBox for a Polygon
108120
///
109-
fn bbox(&self) -> Option<Bbox<T>> {
121+
fn bbox(&self) -> Self::Output {
110122
let line = &self.exterior;
111123
get_bbox(&line.0)
112124
}
@@ -115,10 +127,12 @@ impl<T> BoundingBox<T> for Polygon<T>
115127
impl<T> BoundingBox<T> for MultiPolygon<T>
116128
where T: Float
117129
{
130+
type Output = Option<Bbox<T>>;
131+
118132
///
119133
/// Return the BoundingBox for a MultiPolygon
120134
///
121-
fn bbox(&self) -> Option<Bbox<T>> {
135+
fn bbox(&self) -> Self::Output {
122136
get_bbox(self.0.iter().flat_map(|poly| (poly.exterior).0.iter()))
123137
}
124138
}

0 commit comments

Comments
 (0)