Add PhantomData to ray

This commit is contained in:
Colin Sherratt 2015-03-29 17:35:47 -04:00
parent 104742c8a4
commit f6b86fe4bd
3 changed files with 14 additions and 9 deletions

View file

@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::marker::PhantomData;
use num::BaseNum; use num::BaseNum;
use point::{Point, Point2, Point3}; use point::{Point, Point2, Point3};
use vector::{Vector, Vector2, Vector3}; use vector::{Vector, Vector2, Vector3};
@ -20,17 +21,21 @@ use vector::{Vector, Vector2, Vector3};
/// A generic ray starting at `origin` and extending infinitely in /// A generic ray starting at `origin` and extending infinitely in
/// `direction`. /// `direction`.
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)] #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
pub struct Ray<P,V> { pub struct Ray<S, P, V> {
pub origin: P, pub origin: P,
pub direction: V, pub direction: V,
phantom_s: PhantomData<S>
} }
#[old_impl_check] impl<S: BaseNum, V: Vector<S>, P: Point<S, V>> Ray<S, P, V> {
impl<S: BaseNum, V: Vector<S>, P: Point<S, V>> Ray<P, V> { pub fn new(origin: P, direction: V) -> Ray<S, P, V> {
pub fn new(origin: P, direction: V) -> Ray<P,V> { Ray {
Ray { origin: origin, direction: direction } origin: origin,
direction: direction,
phantom_s: PhantomData
}
} }
} }
pub type Ray2<S> = Ray<Point2<S>, Vector2<S>>; pub type Ray2<S> = Ray<S, Point2<S>, Vector2<S>>;
pub type Ray3<S> = Ray<Point3<S>, Vector3<S>>; pub type Ray3<S> = Ray<S, Point3<S>, Vector3<S>>;

View file

@ -49,7 +49,7 @@ pub trait Rotation<S: BaseNum, V: Vector<S>, P: Point<S, V>>: PartialEq + Approx
/// Rotate a ray using this rotation. /// Rotate a ray using this rotation.
#[inline] #[inline]
fn rotate_ray(&self, ray: &Ray<P, V>) -> Ray<P,V> { fn rotate_ray(&self, ray: &Ray<S, P, V>) -> Ray<S, P,V> {
Ray::new(ray.origin.clone(), self.rotate_vector(&ray.direction)) Ray::new(ray.origin.clone(), self.rotate_vector(&ray.direction))
} }

View file

@ -44,7 +44,7 @@ pub trait Transform<S: BaseNum, V: Vector<S>, P: Point<S, V>>: Sized + PhantomFn
/// Transform a ray using this transform. /// Transform a ray using this transform.
#[inline] #[inline]
fn transform_ray(&self, ray: &Ray<P,V>) -> Ray<P, V> { fn transform_ray(&self, ray: &Ray<S, P,V>) -> Ray<S, P, V> {
Ray::new(self.transform_point(&ray.origin), self.transform_vector(&ray.direction)) Ray::new(self.transform_point(&ray.origin), self.transform_vector(&ray.direction))
} }