From f08ec00a68a98a979c7a080fe3b58fdf01ac9a1a Mon Sep 17 00:00:00 2001 From: prushton2 Date: Sat, 11 Apr 2026 15:32:10 -0400 Subject: [PATCH] added eq and hash to vector3 --- src/ds/vector3.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ds/vector3.rs b/src/ds/vector3.rs index 9295895..27a7e82 100644 --- a/src/ds/vector3.rs +++ b/src/ds/vector3.rs @@ -1,8 +1,9 @@ use auto_ops::*; use rand; use rand::RngExt; +use std::hash::{Hash, Hasher}; -#[derive(PartialEq, Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug)] pub struct Vector3 { pub x: f64, pub y: f64, @@ -91,6 +92,24 @@ impl Vector3 { } } +impl PartialEq for Vector3 { + fn eq(&self, other: &Self) -> bool { + self.x.to_bits() == other.x.to_bits() && + self.y.to_bits() == other.y.to_bits() && + self.z.to_bits() == other.z.to_bits() + } +} + +impl Eq for Vector3 {} + +impl Hash for Vector3 { + fn hash(&self, state: &mut H) { + self.x.to_bits().hash(state); + self.y.to_bits().hash(state); + self.z.to_bits().hash(state); + } +} + impl_op_ex!(+ |a: &Vector3, b: &Vector3| -> Vector3{ Vector3{ x: a.x + b.x,