chiark / gitweb /
Pos, Area: Provide Mean and middle for T=i32
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 12:52:29 +0000 (12:52 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 12:52:29 +0000 (12:52 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/spec.rs

index 0f2892cc294d71f5e2b619c9a4d9094d188c5580..c2887734cfd3005836b50d8df55e30b5905bd8a4 100644 (file)
@@ -278,6 +278,10 @@ pub mod pos_traits {
 
   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<T:CheckedArith> Add<PosC<T>> for PosC<T> {
     type Output = Result<Self, CoordinateOverflow>;
     #[throws(CoordinateOverflow)]