Add trait for defining intersections

This commit is contained in:
Brendan Zabarauskas 2013-09-10 14:51:14 +10:00
parent 6e3860f232
commit 28dd7963ba
3 changed files with 41 additions and 1 deletions

18
src/cgmath/intersect.rs Normal file
View file

@ -0,0 +1,18 @@
// Copyright 2013 The CGMath Developers. For a full listing of the authors,
// refer to the AUTHORS file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pub trait Intersect<Result> {
fn intersection(&self) -> Result;
}

View file

@ -33,11 +33,12 @@ pub mod point;
pub mod ray;
pub mod rotation;
pub mod frustum;
pub mod projection;
pub mod aabb;
pub mod cylinder;
pub mod frustum;
pub mod intersect;
pub mod obb;
pub mod sphere;

View file

@ -13,6 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use intersect::Intersect;
use point::Point3;
use ray::Ray3;
use vector::Vec3;
use std::fmt;
@ -32,6 +35,24 @@ pub struct Plane<S> {
distance: S,
}
impl<S: Clone + Float> Intersect<Option<Point3<S>>> for (Plane<S>, Ray3<S>) {
fn intersection(&self) -> Option<Point3<S>> {
fail!("Not yet implemented");
}
}
impl<S: Clone + Float> Intersect<Option<Ray3<S>>> for (Plane<S>, Plane<S>) {
fn intersection(&self) -> Option<Ray3<S>> {
fail!("Not yet implemented");
}
}
impl<S: Clone + Float> Intersect<Option<Point3<S>>> for (Plane<S>, Plane<S>, Plane<S>) {
fn intersection(&self) -> Option<Point3<S>> {
fail!("Not yet implemented");
}
}
impl<S: Clone + fmt::Float> ToStr for Plane<S> {
fn to_str(&self) -> ~str {
format!("{:f}x + {:f}y + {:f}z + {:f} = 0",