Add PhantomData to ray
This commit is contained in:
parent
104742c8a4
commit
f6b86fe4bd
3 changed files with 14 additions and 9 deletions
19
src/ray.rs
19
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<P,V> {
|
||||
pub struct Ray<S, P, V> {
|
||||
pub origin: P,
|
||||
pub direction: V,
|
||||
phantom_s: PhantomData<S>
|
||||
}
|
||||
|
||||
#[old_impl_check]
|
||||
impl<S: BaseNum, V: Vector<S>, P: Point<S, V>> Ray<P, V> {
|
||||
pub fn new(origin: P, direction: V) -> Ray<P,V> {
|
||||
Ray { origin: origin, direction: direction }
|
||||
impl<S: BaseNum, V: Vector<S>, P: Point<S, V>> Ray<S, P, V> {
|
||||
pub fn new(origin: P, direction: V) -> Ray<S, P, V> {
|
||||
Ray {
|
||||
origin: origin,
|
||||
direction: direction,
|
||||
phantom_s: PhantomData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type Ray2<S> = Ray<Point2<S>, Vector2<S>>;
|
||||
pub type Ray3<S> = Ray<Point3<S>, Vector3<S>>;
|
||||
pub type Ray2<S> = Ray<S, Point2<S>, Vector2<S>>;
|
||||
pub type Ray3<S> = Ray<S, Point3<S>, Vector3<S>>;
|
||||
|
|
|
@ -49,7 +49,7 @@ pub trait Rotation<S: BaseNum, V: Vector<S>, P: Point<S, V>>: PartialEq + Approx
|
|||
|
||||
/// Rotate a ray using this rotation.
|
||||
#[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))
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ pub trait Transform<S: BaseNum, V: Vector<S>, P: Point<S, V>>: Sized + PhantomFn
|
|||
|
||||
/// Transform a ray using this transform.
|
||||
#[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))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue