summaryrefslogtreecommitdiff
path: root/src/geom/length.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/geom/length.rs')
-rw-r--r--src/geom/length.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/geom/length.rs b/src/geom/length.rs
index de184e6c..68261d5f 100644
--- a/src/geom/length.rs
+++ b/src/geom/length.rs
@@ -127,11 +127,15 @@ impl Length {
self == other || (self - other).to_raw().abs() < 1e-6
}
- /// Perform a checked division by a number, returning `None` if the result
+ /// Perform a checked division by a number, returning zero if the result
/// is not finite.
- pub fn div_finite(self, number: f64) -> Option<Self> {
+ pub fn safe_div(self, number: f64) -> Self {
let result = self.to_raw() / number;
- result.is_finite().then(|| Self::raw(result))
+ if result.is_finite() {
+ Self::raw(result)
+ } else {
+ Self::zero()
+ }
}
}