@@ -5,6 +5,8 @@ use types::{Bbox, Point, MultiPoint, Line, LineString, MultiLineString, Polygon,
5
5
/// Calculation of the bounding box of a geometry.
6
6
7
7
pub trait BoundingBox < T : Float > {
8
+ type Output ;
9
+
8
10
/// Return the Bounding Box of a geometry
9
11
///
10
12
/// ```
@@ -24,7 +26,7 @@ pub trait BoundingBox<T: Float> {
24
26
/// assert_eq!(118.34, bbox.ymax);
25
27
/// ```
26
28
///
27
- fn bbox ( & self ) -> Option < Bbox < T > > ;
29
+ fn bbox ( & self ) -> Self :: Output ;
28
30
}
29
31
30
32
@@ -57,56 +59,66 @@ fn get_bbox<'a, I, T>(collection: I) -> Option<Bbox<T>>
57
59
impl < T > BoundingBox < T > for MultiPoint < T >
58
60
where T : Float
59
61
{
62
+ type Output = Option < Bbox < T > > ;
63
+
60
64
///
61
65
/// Return the BoundingBox for a MultiPoint
62
66
///
63
- fn bbox ( & self ) -> Option < Bbox < T > > {
67
+ fn bbox ( & self ) -> Self :: Output {
64
68
get_bbox ( & self . 0 )
65
69
}
66
70
}
67
71
68
72
impl < T > BoundingBox < T > for Line < T >
69
73
where T : Float
70
74
{
71
- fn bbox ( & self ) -> Option < Bbox < T > > {
75
+ type Output = Bbox < T > ;
76
+
77
+ fn bbox ( & self ) -> Self :: Output {
72
78
let a = self . start ;
73
79
let b = self . end ;
74
80
let ( xmin, xmax) = if a. x ( ) <= b. x ( ) { ( a. x ( ) , b. x ( ) ) } else { ( b. x ( ) , a. x ( ) ) } ;
75
81
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}
78
84
}
79
85
}
80
86
81
87
impl < T > BoundingBox < T > for LineString < T >
82
88
where T : Float
83
89
{
90
+ type Output = Option < Bbox < T > > ;
91
+
84
92
///
85
93
/// Return the BoundingBox for a LineString
86
94
///
87
- fn bbox ( & self ) -> Option < Bbox < T > > {
95
+ fn bbox ( & self ) -> Self :: Output {
88
96
get_bbox ( & self . 0 )
89
97
}
90
98
}
91
99
92
100
impl < T > BoundingBox < T > for MultiLineString < T >
93
101
where T : Float
94
102
{
103
+ type Output = Option < Bbox < T > > ;
104
+
95
105
///
96
106
/// Return the BoundingBox for a MultiLineString
97
107
///
98
- fn bbox ( & self ) -> Option < Bbox < T > > {
108
+ fn bbox ( & self ) -> Self :: Output {
99
109
get_bbox ( self . 0 . iter ( ) . flat_map ( |line| line. 0 . iter ( ) ) )
100
110
}
101
111
}
102
112
103
113
impl < T > BoundingBox < T > for Polygon < T >
104
114
where T : Float
105
115
{
116
+ type Output = Option < Bbox < T > > ;
117
+
106
118
///
107
119
/// Return the BoundingBox for a Polygon
108
120
///
109
- fn bbox ( & self ) -> Option < Bbox < T > > {
121
+ fn bbox ( & self ) -> Self :: Output {
110
122
let line = & self . exterior ;
111
123
get_bbox ( & line. 0 )
112
124
}
@@ -115,10 +127,12 @@ impl<T> BoundingBox<T> for Polygon<T>
115
127
impl < T > BoundingBox < T > for MultiPolygon < T >
116
128
where T : Float
117
129
{
130
+ type Output = Option < Bbox < T > > ;
131
+
118
132
///
119
133
/// Return the BoundingBox for a MultiPolygon
120
134
///
121
- fn bbox ( & self ) -> Option < Bbox < T > > {
135
+ fn bbox ( & self ) -> Self :: Output {
122
136
get_bbox ( self . 0 . iter ( ) . flat_map ( |poly| ( poly. exterior ) . 0 . iter ( ) ) )
123
137
}
124
138
}
0 commit comments