Created
September 14, 2018 02:30
-
-
Save djg/d8e984d9c55fff3b38fdf5111abd0196 to your computer and use it in GitHub Desktop.
functional programming cry for help
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn hit_zip(aabb: &Aabb, r: &Ray, t_min: f32, t_max: f32) -> bool { | |
r.direction | |
.iter() | |
.zip( | |
r.point | |
.iter() | |
.zip(aabb.min.iter().zip(aabb.max.iter())), | |
).all(|(d, (p, (min, max)))| { | |
let inv_d = 1. / d; | |
let t0 = (min - p) * inv_d; | |
let t1 = (max - p) * inv_d; | |
let (t0, t1) = if inv_d < 0. { (t1, t0) } else { (t0, t1) }; | |
let t_min = if t0 > t_min { t0 } else { t_min }; | |
let t_max = if t1 < t_max { t1 } else { t_max }; | |
t_min < t_max | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment