From f6b86fe4bdb86a39fc44c2ac6d412d0e24716db9 Mon Sep 17 00:00:00 2001 From: Colin Sherratt Date: Sun, 29 Mar 2015 17:35:47 -0400 Subject: [PATCH] Add PhantomData to ray --- src/ray.rs | 19 ++++++++++++------- src/rotation.rs | 2 +- src/transform.rs | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ray.rs b/src/ray.rs index 6490e20..be43aaa 100644 --- a/src/ray.rs +++ b/src/ray.rs @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::marker::PhantomData; use num::BaseNum; use point::{Point, Point2, Point3}; use vector::{Vector, Vector2, Vector3}; @@ -20,17 +21,21 @@ use vector::{Vector, Vector2, Vector3}; /// A generic ray starting at `origin` and extending infinitely in /// `direction`. #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] -pub struct Ray { +pub struct Ray { pub origin: P, pub direction: V, + phantom_s: PhantomData } -#[old_impl_check] -impl, P: Point> Ray { - pub fn new(origin: P, direction: V) -> Ray { - Ray { origin: origin, direction: direction } +impl, P: Point> Ray { + pub fn new(origin: P, direction: V) -> Ray { + Ray { + origin: origin, + direction: direction, + phantom_s: PhantomData + } } } -pub type Ray2 = Ray, Vector2>; -pub type Ray3 = Ray, Vector3>; +pub type Ray2 = Ray, Vector2>; +pub type Ray3 = Ray, Vector3>; diff --git a/src/rotation.rs b/src/rotation.rs index 8e92d31..d2335dc 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -49,7 +49,7 @@ pub trait Rotation, P: Point>: PartialEq + Approx /// Rotate a ray using this rotation. #[inline] - fn rotate_ray(&self, ray: &Ray) -> Ray { + fn rotate_ray(&self, ray: &Ray) -> Ray { Ray::new(ray.origin.clone(), self.rotate_vector(&ray.direction)) } diff --git a/src/transform.rs b/src/transform.rs index 936b3af..0382839 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -44,7 +44,7 @@ pub trait Transform, P: Point>: Sized + PhantomFn /// Transform a ray using this transform. #[inline] - fn transform_ray(&self, ray: &Ray) -> Ray { + fn transform_ray(&self, ray: &Ray) -> Ray { Ray::new(self.transform_point(&ray.origin), self.transform_vector(&ray.direction)) }