Use PhantomData for Line

This commit is contained in:
Colin Sherratt 2015-03-29 17:39:47 -04:00
parent f6b86fe4bd
commit 4d1e21d609
2 changed files with 16 additions and 9 deletions

View file

@ -15,7 +15,7 @@
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![feature(old_impl_check, plugin, core, std_misc, custom_derive)]
#![feature(plugin, core, std_misc, custom_derive)]
//! Computer graphics-centric math.
//!

View file

@ -15,28 +15,35 @@
//! Line segments
use std::marker::PhantomData;
use num::{BaseNum, BaseFloat, Zero, zero, One, one};
use point::{Point, Point2, Point3};
use vector::{Vector, Vector2};
use vector::{Vector, Vector2, Vector3};
use ray::{Ray2};
use intersect::Intersect;
/// A generic directed line segment from `origin` to `dest`.
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
pub struct Line<P> {
pub struct Line<S, V, P> {
pub origin: P,
pub dest: P,
phantom_s: PhantomData<S>,
phantom_v: PhantomData<V>
}
#[old_impl_check]
impl<S: BaseNum, V: Vector<S>, P: Point<S, V>> Line<P> {
pub fn new(origin: P, dest: P) -> Line<P> {
Line { origin:origin, dest:dest }
impl<S: BaseNum, V: Vector<S>, P: Point<S, V>> Line<S, V, P> {
pub fn new(origin: P, dest: P) -> Line<S, V, P> {
Line {
origin: origin,
dest: dest,
phantom_v: PhantomData,
phantom_s: PhantomData
}
}
}
pub type Line2<S> = Line<Point2<S>>;
pub type Line3<S> = Line<Point3<S>>;
pub type Line2<S> = Line<S, Vector2<S>, Point2<S>>;
pub type Line3<S> = Line<S, Vector3<S>, Point3<S>>;
/// Determines if an intersection between a ray and a line segment is found.
impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {