1mod ray;2mod vec3;34use core::f64;56pub use ray::*;7pub use vec3::*;89#[derive(Debug, Copy, Clone, PartialEq)]10pub struct NotNanF64(f64);1112// We can implement these two because we know NotNanF64 can't contain a NaN13impl Eq for NotNanF64 {}14impl PartialOrd for NotNanF64 {15 fn partial_cmp(&self, other: &NotNanF64) -> Option<std::cmp::Ordering> {16 Some(self.cmp(other))17 }18}19impl Ord for NotNanF64 {20 fn cmp(&self, other: &Self) -> std::cmp::Ordering {21 self.0.partial_cmp(&other.0).unwrap()22 }23}2425impl NotNanF64 {26 pub fn new(v: f64) -> Option<NotNanF64> {27 if v.is_nan() { None } else { Some(NotNanF64(v)) }28 }2930 pub fn get(&self) -> f64 {31 self.032 }33}3435#[derive(Debug, Clone)]36pub struct Interval {37 pub min: f64,38 pub max: f64,39}4041impl Interval {42 pub fn new(min: f64, max: f64) -> Option<Interval> {43 if min > max {44 None45 } else {46 Some(Interval { min, max })47 }48 }4950 pub fn contains(&self, t: f64) -> bool {51 self.min <= t && t <= self.max52 }5354 pub fn surrounds(&self, t: f64) -> bool {55 self.min < t && t < self.max56 }57}5859impl Default for Interval {60 fn default() -> Self {61 Interval {62 min: f64::NEG_INFINITY,63 max: f64::INFINITY,64 }65 }66}