intersections: implement a PartialEq that handles floats.

This commit is contained in:
Bill Thiede 2021-07-21 19:41:14 -07:00
parent a553786807
commit 952ed8bf81

View File

@ -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`.