From 952ed8bf810916919e8fddc03957f546311a89aa Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Wed, 21 Jul 2021 19:41:14 -0700 Subject: [PATCH] intersections: implement a PartialEq that handles floats. --- rtchallenge/src/intersections.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rtchallenge/src/intersections.rs b/rtchallenge/src/intersections.rs index 2802eb4..d0b16d9 100644 --- a/rtchallenge/src/intersections.rs +++ b/rtchallenge/src/intersections.rs @@ -7,11 +7,16 @@ use crate::{ Float, EPSILON, }; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] pub struct Intersection<'i> { pub t: Float, pub object: &'i Shape, } +impl<'i> PartialEq for Intersection<'i> { + fn eq(&self, rhs: &Intersection) -> bool { + ((self.t - rhs.t).abs() < EPSILON) && (self.object == rhs.object) + } +} impl<'i> Intersection<'i> { /// Create new `Intersection` at the given `t` that hits the given `object`.