From: Ian Jackson Date: Wed, 24 Mar 2021 12:52:29 +0000 (+0000) Subject: Pos, Area: Provide Mean and middle for T=i32 X-Git-Tag: otter-0.5.0~467 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0829f45b42bc5a4c9b1a6bdbf06883b102aad1cf;p=otter.git Pos, Area: Provide Mean and middle for T=i32 Signed-off-by: Ian Jackson --- diff --git a/src/spec.rs b/src/spec.rs index 0f2892cc..c2887734 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -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 Add> for PosC { type Output = Result; #[throws(CoordinateOverflow)]