line.rs: destructure self with let, save indentation

This commit is contained in:
Jonathan Neuschäfer 2015-03-14 03:44:18 +01:00
parent c80f0889be
commit 556c5f2375
4 changed files with 83 additions and 92 deletions

View file

@ -201,8 +201,7 @@ impl<S: BaseNum> fmt::Debug for Aabb3<S> {
impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Aabb2<S>) { impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Aabb2<S>) {
fn intersection(&self) -> Option<Point2<S>> { fn intersection(&self) -> Option<Point2<S>> {
match *self { let (ref ray, ref aabb) = *self;
(ref ray, ref aabb) => {
let mut tmin: S = Float::neg_infinity(); let mut tmin: S = Float::neg_infinity();
let mut tmax: S = Float::infinity(); let mut tmax: S = Float::infinity();
@ -238,8 +237,6 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Aabb2<S>) {
None None
} }
} }
}
}
} }
impl<S: BaseFloat + 'static> Bound<S> for Aabb3<S> { impl<S: BaseFloat + 'static> Bound<S> for Aabb3<S> {

View file

@ -41,8 +41,8 @@ pub type Line3<S> = Line<Point3<S>>;
/// Determines if an intersection between a ray and a line segments is found. /// 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>) { impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
fn intersection(&self) -> Option<Point2<S>> { fn intersection(&self) -> Option<Point2<S>> {
match *self { let (ref ray, ref line) = *self;
(ref ray, ref line) => {
let p = ray.origin; let p = ray.origin;
let q = line.origin; let q = line.origin;
let r = ray.direction; let r = ray.direction;
@ -88,6 +88,4 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
return None; return None;
} }
}
}
} }

View file

@ -111,14 +111,12 @@ impl<S: BaseFloat> Plane<S> {
impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Plane<S>, Ray3<S>) { impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Plane<S>, Ray3<S>) {
fn intersection(&self) -> Option<Point3<S>> { fn intersection(&self) -> Option<Point3<S>> {
match *self { let (ref p, ref r) = *self;
(ref p, ref r) => {
let t = -(p.d + r.origin.dot(&p.n)) / r.direction.dot(&p.n); let t = -(p.d + r.origin.dot(&p.n)) / r.direction.dot(&p.n);
if t < Zero::zero() { None } if t < Zero::zero() { None }
else { Some(r.origin.add_v(&r.direction.mul_s(t))) } else { Some(r.origin.add_v(&r.direction.mul_s(t))) }
} }
}
}
} }
impl<S: BaseFloat> Intersect<Option<Ray3<S>>> for (Plane<S>, Plane<S>) { impl<S: BaseFloat> Intersect<Option<Ray3<S>>> for (Plane<S>, Plane<S>) {

View file

@ -31,8 +31,8 @@ pub struct Sphere<S> {
impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Sphere<S>, Ray3<S>) { impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Sphere<S>, Ray3<S>) {
fn intersection(&self) -> Option<Point3<S>> { fn intersection(&self) -> Option<Point3<S>> {
match *self { let (ref s, ref r) = *self;
(ref s, ref r) => {
let l = s.center.sub_p(&r.origin); let l = s.center.sub_p(&r.origin);
let tca = l.dot(&r.direction); let tca = l.dot(&r.direction);
if tca < zero() { return None; } 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(); let thc = (s.radius*s.radius - d2).sqrt();
Some(r.origin.add_v(&r.direction.mul_s(tca - thc))) Some(r.origin.add_v(&r.direction.mul_s(tca - thc)))
} }
}
}
} }
impl<S: BaseFloat + 'static> Bound<S> for Sphere<S> { impl<S: BaseFloat + 'static> Bound<S> for Sphere<S> {