chiark / gitweb /
impl Mean for f64
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 May 2022 20:11:04 +0000 (21:11 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 May 2022 23:19:17 +0000 (00:19 +0100)
We'll want this to calculate middles of SVGs.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
base/geometry.rs

index 2733632ed09d420a2e8a60aa5d1943da1dcd4196..6983a3a0707d22f055ffaeec7f95c794d6e9a52f 100644 (file)
@@ -85,6 +85,9 @@ pub trait Mean { fn mean(&self, other: &Self) -> Self; }
 impl Mean for i32 { fn mean(&self, other: &Self) -> Self {
   ((*self as i64 + *other as i64) / 2) as i32
 } }
+impl Mean for f64 { fn mean(&self, other: &Self) -> Self {
+  self * 0.5 + other * 0.5
+} }
 
 //---------- Pos ----------