use crate::gaussian_integer::GaussianInteger;
use core::cmp::Ordering::{self, Equal};
use malachite_base::num::arithmetic::traits::AbsSquared;
use malachite_base::num::comparison::traits::{OrdAbs, PartialOrdAbs};
fn combine(x: Ordering, y: Ordering) -> Option<Ordering> {
if x == y || y == Equal {
Some(x)
} else if x == Equal {
Some(y)
} else {
None
}
}
impl PartialOrdAbs for GaussianInteger {
#[inline]
fn partial_cmp_abs(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp_abs(other))
}
}
impl OrdAbs for GaussianInteger {
fn cmp_abs(&self, other: &Self) -> Ordering {
if let Some(o) = combine(
self.real.cmp_abs(&other.real),
self.imaginary.cmp_abs(&other.imaginary),
) {
return o;
}
if let Some(o) = combine(
self.real.cmp_abs(&other.imaginary),
self.imaginary.cmp_abs(&other.real),
) {
return o;
}
self.abs_squared().cmp(&other.abs_squared())
}
}