diff options
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/length.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/geom/length.rs b/src/geom/length.rs index d0f11bd2..de184e6c 100644 --- a/src/geom/length.rs +++ b/src/geom/length.rs @@ -126,6 +126,13 @@ impl Length { pub fn approx_eq(self, other: Self) -> bool { self == other || (self - other).to_raw().abs() < 1e-6 } + + /// Perform a checked division by a number, returning `None` if the result + /// is not finite. + pub fn div_finite(self, number: f64) -> Option<Self> { + let result = self.to_raw() / number; + result.is_finite().then(|| Self::raw(result)) + } } impl Debug for Length { |
