From c20f3111caa7a5f61324b125db9f05c65d1fb99d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 2 Apr 2021 22:41:38 +0100 Subject: [PATCH] geometry: Provide len Signed-off-by: Ian Jackson --- base/geometry.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/base/geometry.rs b/base/geometry.rs index ab5527aa..6d424f06 100644 --- a/base/geometry.rs +++ b/base/geometry.rs @@ -113,6 +113,14 @@ impl PosC { b.checked_add(c2) })? } + + #[throws(CoordinateOverflow)] + pub fn len(self) -> f64 where PosC: PosPromote { + let d2 = self.len2()?; + let d = d2.sqrt(); + if !d.is_finite() { throw!(CoordinateOverflow) } + d + } } impl PosC where T: Copy { pub fn x(self) -> T { self.coords[0] } -- 2.30.2