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>) {
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();
@ -239,8 +238,6 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Aabb2<S>) {
}
}
}
}
}
impl<S: BaseFloat + 'static> Bound<S> for Aabb3<S> {
fn relate_plane(&self, plane: &Plane<S>) -> Relation {

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.
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;
@ -89,5 +89,3 @@ impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
return None;
}
}
}
}

View file

@ -111,15 +111,13 @@ 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>) {
fn intersection(&self) -> Option<Ray3<S>> {

View file

@ -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; }
@ -42,8 +42,6 @@ impl<S: BaseFloat> Intersect<Option<Point3<S>>> for (Sphere<S>, Ray3<S>) {
Some(r.origin.add_v(&r.direction.mul_s(tca - thc)))
}
}
}
}
impl<S: BaseFloat + 'static> Bound<S> for Sphere<S> {
fn relate_plane(&self, plane: &Plane<S>) -> Relation {