Skip to content

Commit a36f696

Browse files
committed
CONTROVERSIAL: make GeoFloat compat with RTreeNum
If we want to rely on using an RTree for some of our operations (like the Relate trait) we have to ensure our numeric types are RTree compatible. == Alternative considered Since RTreeNum isn't necessarily a float, we could instead add these new bounds to GeoNum instead of GeoFloat. However, doing so would mean dropping support for unsigned ints from GeoNum. Note that using unsigned ints now, while supported, can easily lead to underflow if you're using one of the many operations that involve subtraction. It would also put one more barrier between ever getting BigDecimal support in geo - which is not Bounded. Also, apparently Float isn't necessarily Signed, but having never personally encountered unsigned floating point in the wild, I don't have strong feelings about retaining support for it. And since Relate doesn't current support non-floats, this would be a cost with no benefit. If that changes, we could reconsider this decision, or perhaps add the required behavior to some derivative type, like one of the HasKernel implementations.
1 parent e024f7e commit a36f696

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

geo/src/algorithm/euclidean_distance.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ where
142142
.0
143143
.iter()
144144
.map(|p| self.euclidean_distance(p))
145-
.fold(T::max_value(), |accum, val| accum.min(val))
145+
.fold(<T as Bounded>::max_value(), |accum, val| accum.min(val))
146146
}
147147
}
148148

@@ -175,7 +175,7 @@ where
175175
mls.0
176176
.iter()
177177
.map(|ls| self.euclidean_distance(ls))
178-
.fold(T::max_value(), |accum, val| accum.min(val))
178+
.fold(<T as Bounded>::max_value(), |accum, val| accum.min(val))
179179
}
180180
}
181181

@@ -195,7 +195,7 @@ where
195195
.interiors()
196196
.iter()
197197
.map(|ring| self.euclidean_distance(ring))
198-
.fold(T::max_value(), |accum, val| accum.min(val))
198+
.fold(<T as Bounded>::max_value(), |accum, val| accum.min(val))
199199
.min(
200200
polygon
201201
.exterior()
@@ -205,7 +205,7 @@ where
205205
self.0, line.start, line.end,
206206
)
207207
})
208-
.fold(T::max_value(), |accum, val| accum.min(val)),
208+
.fold(<T as Bounded>::max_value(), |accum, val| accum.min(val)),
209209
)
210210
}
211211
}
@@ -220,7 +220,7 @@ where
220220
.0
221221
.iter()
222222
.map(|p| self.euclidean_distance(p))
223-
.fold(T::max_value(), |accum, val| accum.min(val))
223+
.fold(<T as Bounded>::max_value(), |accum, val| accum.min(val))
224224
}
225225
}
226226

@@ -530,7 +530,7 @@ where
530530
[(self.0, self.1), (self.1, self.2), (self.2, self.0)]
531531
.iter()
532532
.map(|edge| ::geo_types::private_utils::line_segment_distance(point.0, edge.0, edge.1))
533-
.fold(T::max_value(), |accum, val| accum.min(val))
533+
.fold(<T as Bounded>::max_value(), |accum, val| accum.min(val))
534534
}
535535
}
536536

geo/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ pub mod prelude {
293293
/// })
294294
/// }
295295
/// ```
296-
pub trait GeoFloat: num_traits::Float + GeoNum {}
297-
impl<T> GeoFloat for T where T: num_traits::Float + GeoNum {}
296+
pub trait GeoFloat: num_traits::Float + num_traits::Signed + num_traits::Bounded + GeoNum {}
297+
impl<T> GeoFloat for T where T: num_traits::Float + num_traits::Signed + num_traits::Bounded + GeoNum
298+
{}
298299

299300
pub trait GeoNum: CoordNum + algorithm::kernels::HasKernel {}
300301
impl<T> GeoNum for T where T: CoordNum + algorithm::kernels::HasKernel {}

0 commit comments

Comments
 (0)