Use PhantomData for Line
This commit is contained in:
parent
f6b86fe4bd
commit
4d1e21d609
2 changed files with 16 additions and 9 deletions
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#![crate_type = "rlib"]
|
#![crate_type = "rlib"]
|
||||||
#![crate_type = "dylib"]
|
#![crate_type = "dylib"]
|
||||||
#![feature(old_impl_check, plugin, core, std_misc, custom_derive)]
|
#![feature(plugin, core, std_misc, custom_derive)]
|
||||||
|
|
||||||
//! Computer graphics-centric math.
|
//! Computer graphics-centric math.
|
||||||
//!
|
//!
|
||||||
|
|
23
src/line.rs
23
src/line.rs
|
@ -15,28 +15,35 @@
|
||||||
|
|
||||||
//! Line segments
|
//! Line segments
|
||||||
|
|
||||||
|
use std::marker::PhantomData;
|
||||||
use num::{BaseNum, BaseFloat, Zero, zero, One, one};
|
use num::{BaseNum, BaseFloat, Zero, zero, One, one};
|
||||||
use point::{Point, Point2, Point3};
|
use point::{Point, Point2, Point3};
|
||||||
use vector::{Vector, Vector2};
|
use vector::{Vector, Vector2, Vector3};
|
||||||
use ray::{Ray2};
|
use ray::{Ray2};
|
||||||
use intersect::Intersect;
|
use intersect::Intersect;
|
||||||
|
|
||||||
/// A generic directed line segment from `origin` to `dest`.
|
/// A generic directed line segment from `origin` to `dest`.
|
||||||
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Line<P> {
|
pub struct Line<S, V, P> {
|
||||||
pub origin: P,
|
pub origin: P,
|
||||||
pub dest: 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<S, V, P> {
|
||||||
impl<S: BaseNum, V: Vector<S>, P: Point<S, V>> Line<P> {
|
pub fn new(origin: P, dest: P) -> Line<S, V, P> {
|
||||||
pub fn new(origin: P, dest: P) -> Line<P> {
|
Line {
|
||||||
Line { origin:origin, dest:dest }
|
origin: origin,
|
||||||
|
dest: dest,
|
||||||
|
phantom_v: PhantomData,
|
||||||
|
phantom_s: PhantomData
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Line2<S> = Line<Point2<S>>;
|
pub type Line2<S> = Line<S, Vector2<S>, Point2<S>>;
|
||||||
pub type Line3<S> = Line<Point3<S>>;
|
pub type Line3<S> = Line<S, Vector3<S>, Point3<S>>;
|
||||||
|
|
||||||
/// Determines if an intersection between a ray and a line segment is found.
|
/// 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>) {
|
impl<S: BaseFloat> Intersect<Option<Point2<S>>> for (Ray2<S>, Line2<S>) {
|
||||||
|
|
Loading…
Reference in a new issue