From 260ed0fd5c38ec09f815e8da74bcab78a97380c7 Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Fri, 13 Sep 2024 14:00:13 -0700
Subject: [PATCH] ratio: PartialEq, Eq, PartialOrd, Ord

---
 ratio_ops/src/ratio.rs | 45 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/ratio_ops/src/ratio.rs b/ratio_ops/src/ratio.rs
index fdb5f39eb..a7f8928d6 100644
--- a/ratio_ops/src/ratio.rs
+++ b/ratio_ops/src/ratio.rs
@@ -175,3 +175,48 @@ macro_rules! impl_ratio_assign_operator {
 impl_ratio_assign_operator!(AddAssign,add_assign);
 impl_ratio_assign_operator!(SubAssign,sub_assign);
 impl_ratio_assign_operator!(RemAssign,rem_assign);
+
+// Only implement PartialEq<Self>
+// Rust's operators aren't actually that good
+
+impl<Num,Den,T> PartialEq for Ratio<Num,Den>
+	where
+		Num:Copy,
+		Den:Copy,
+		Num:core::ops::Mul<Den,Output=T>,
+		T:PartialEq,
+{
+	#[inline]
+	fn eq(&self,&other:&Self)->bool{
+		(self.num*other.den).eq(&(other.num*self.den))
+	}
+}
+impl<Num,Den> Eq for Ratio<Num,Den>
+	where
+		Ratio<Num,Den>:PartialEq,
+{}
+
+impl<Num,Den,T> PartialOrd for Ratio<Num,Den>
+	where
+		Num:Copy,
+		Den:Copy,
+		Num:core::ops::Mul<Den,Output=T>,
+		T:PartialOrd,
+{
+	#[inline]
+	fn partial_cmp(&self,&other:&Self)->Option<core::cmp::Ordering>{
+		(self.num*other.den).partial_cmp(&(other.num*self.den))
+	}
+}
+impl<Num,Den,T> Ord for Ratio<Num,Den>
+	where
+		Num:Copy,
+		Den:Copy,
+		Num:core::ops::Mul<Den,Output=T>,
+		T:Ord,
+{
+	#[inline]
+	fn cmp(&self,other:&Self)->std::cmp::Ordering{
+		(self.num*other.den).cmp(&(other.num*self.den))
+	}
+}