line.rs: destructure self with let, save indentation
This commit is contained in:
parent
c80f0889be
commit
556c5f2375
4 changed files with 83 additions and 92 deletions
|
@ -201,8 +201,7 @@ impl<S: BaseNum> fmt::Debug for Aabb3<S> {
|
|||
|
||||
impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Aabb2<S>) {
|
||||
fn intersection(&self) -> Option<Point2<S>> {
|
||||
match *self {
|
||||
(ref ray, ref aabb) => {
|
||||
let (ref ray, ref aabb) = *self;
|
||||
|
||||
let mut tmin: S = Float::neg_infinity();
|
||||
let mut tmax: S = Float::infinity();
|
||||
|
@ -238,8 +237,6 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Aabb2<S>) {
|
|||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: BaseFloat + 'static> Bound<S> for Aabb3<S> {
|
||||
|
|
|
@ -41,8 +41,8 @@ pub type Line3<S> = Line<Point3<S>>;
|
|||
/// Determines if an intersection between a ray and a line segments is found.
|
||||
impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
|
||||
fn intersection(&self) -> Option<Point2<S>> {
|
||||
match *self {
|
||||
(ref ray, ref line) => {
|
||||
let (ref ray, ref line) = *self;
|
||||
|
||||
let p = ray.origin;
|
||||
let q = line.origin;
|
||||
let r = ray.direction;
|
||||
|
@ -88,6 +88,4 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
|
|||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,14 +111,12 @@ impl<S: BaseFloat> Plane<S> {
|
|||
|
||||
impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Plane<S>, Ray3<S>) {
|
||||
fn intersection(&self) -> Option<Point3<S>> {
|
||||
match *self {
|
||||
(ref p, ref r) => {
|
||||
let (ref p, ref r) = *self;
|
||||
|
||||
let t = -(p.d + r.origin.dot(&p.n)) / r.direction.dot(&p.n);
|
||||
if t < Zero::zero() { None }
|
||||
else { Some(r.origin.add_v(&r.direction.mul_s(t))) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: BaseFloat> Intersect<Option<Ray3<S>>> for (Plane<S>, Plane<S>) {
|
||||
|
|
|
@ -31,8 +31,8 @@ pub struct Sphere<S> {
|
|||
|
||||
impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Sphere<S>, Ray3<S>) {
|
||||
fn intersection(&self) -> Option<Point3<S>> {
|
||||
match *self {
|
||||
(ref s, ref r) => {
|
||||
let (ref s, ref r) = *self;
|
||||
|
||||
let l = s.center.sub_p(&r.origin);
|
||||
let tca = l.dot(&r.direction);
|
||||
if tca < zero() { return None; }
|
||||
|
@ -41,8 +41,6 @@ impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Sphere<S>, Ray3<S>) {
|
|||
let thc = (s.radius*s.radius - d2).sqrt();
|
||||
Some(r.origin.add_v(&r.direction.mul_s(tca - thc)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: BaseFloat + 'static> Bound<S> for Sphere<S> {
|
||||
|
|
Loading…
Reference in a new issue