pub trait SplitBetween {
fn split_between(&self, other: &Self) -> Self;
}
impl SplitBetween for f64 {
fn split_between(&self, other: &Self) -> Self {
(self + other) / 2.0
}
}
impl SplitBetween for f32 {
fn split_between(&self, other: &Self) -> Self {
(self + other) / 2.0
}
}
impl SplitBetween for i64 {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}
impl SplitBetween for u64 {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}
impl SplitBetween for isize {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}
impl SplitBetween for usize {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}
impl SplitBetween for i32 {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}
impl SplitBetween for u32 {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}
impl SplitBetween for i16 {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}
impl SplitBetween for u16 {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}
impl SplitBetween for i8 {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}
impl SplitBetween for u8 {
fn split_between(&self, other: &Self) -> Self {
let diff = other - self;
if diff % 2 == 0 {
self + diff / 2
} else {
self + diff / 2 + 1
}
}
}