Decouple vec module from Point2 and Point3
This commit is contained in:
parent
7615a55d84
commit
ad59c9b16f
3 changed files with 37 additions and 42 deletions
|
@ -13,12 +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.
|
||||||
|
|
||||||
#[cfg(geom)]
|
|
||||||
use std::cast;
|
|
||||||
|
|
||||||
use core::{Dimensional, Swap};
|
use core::{Dimensional, Swap};
|
||||||
#[cfg(geom)]
|
|
||||||
use geom::{Point2, Point3};
|
|
||||||
|
|
||||||
#[deriving(Clone, Eq)]
|
#[deriving(Clone, Eq)]
|
||||||
pub struct Vec2<T> { x: T, y: T }
|
pub struct Vec2<T> { x: T, y: T }
|
||||||
|
@ -66,24 +61,6 @@ impl<T> Vec2<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(geom)]
|
|
||||||
impl<T> Vec2<T> {
|
|
||||||
#[inline]
|
|
||||||
pub fn from_point(point: Point2<T>) -> Vec2<T> {
|
|
||||||
unsafe { cast::transmute(point) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn as_point<'a>(&'a self) -> &'a Point2<T> {
|
|
||||||
unsafe { cast::transmute(self) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn as_mut_point<'a>(&'a mut self) -> &'a mut Point2<T> {
|
|
||||||
unsafe { cast::transmute(self) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T:Clone> Vec2<T> {
|
impl<T:Clone> Vec2<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_value(value: T) -> Vec2<T> {
|
pub fn from_value(value: T) -> Vec2<T> {
|
||||||
|
@ -588,24 +565,6 @@ impl<T> Vec3<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(geom)]
|
|
||||||
impl<T> Vec3<T> {
|
|
||||||
#[inline]
|
|
||||||
pub fn from_point(point: Point3<T>) -> Vec3<T> {
|
|
||||||
unsafe { cast::transmute(point) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn as_point<'a>(&'a self) -> &'a Point3<T> {
|
|
||||||
unsafe { cast::transmute(self) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn as_mut_point<'a>(&'a mut self) -> &'a mut Point3<T> {
|
|
||||||
unsafe { cast::transmute(self) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T:Clone> Vec3<T> {
|
impl<T:Clone> Vec3<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_value(value: T) -> Vec3<T> {
|
pub fn from_value(value: T) -> Vec3<T> {
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
pub use self::aabb::{AABB2, AABB3};
|
pub use self::aabb::{AABB2, AABB3};
|
||||||
pub use self::frustum::{Frustum, FrustumPoints};
|
pub use self::frustum::{Frustum, FrustumPoints};
|
||||||
pub use self::plane::Plane3;
|
pub use self::plane::Plane3;
|
||||||
pub use self::point::{Point, Point2, Point3};
|
pub use self::point::Point;
|
||||||
|
pub use self::point::{Point2, AsPoint2};
|
||||||
|
pub use self::point::{Point3, AsPoint3};
|
||||||
pub use self::ray::{Ray2, Ray3};
|
pub use self::ray::{Ray2, Ray3};
|
||||||
pub use self::sphere::Sphere;
|
pub use self::sphere::Sphere;
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,23 @@ impl_dimensional!(Point2, T, 2)
|
||||||
impl_swap!(Point2)
|
impl_swap!(Point2)
|
||||||
impl_approx!(Point2 { x, y })
|
impl_approx!(Point2 { x, y })
|
||||||
|
|
||||||
|
pub trait AsPoint2<T> {
|
||||||
|
pub fn as_point2<'a>(&'a self) -> &'a Point2<T>;
|
||||||
|
pub fn as_mut_point2<'a>(&'a mut self) -> &'a mut Point2<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T:Clone + Num> AsPoint2<T> for Vec2<T> {
|
||||||
|
#[inline]
|
||||||
|
pub fn as_point2<'a>(&'a self) -> &'a Point2<T> {
|
||||||
|
unsafe { cast::transmute(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn as_mut_point2<'a>(&'a mut self) -> &'a mut Point2<T> {
|
||||||
|
unsafe { cast::transmute(self) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T:Num> Point2<T> {
|
impl<T:Num> Point2<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(x: T, y: T) -> Point2<T> {
|
pub fn new(x: T, y: T) -> Point2<T> {
|
||||||
|
@ -192,6 +209,23 @@ impl_dimensional!(Point3, T, 3)
|
||||||
impl_swap!(Point3)
|
impl_swap!(Point3)
|
||||||
impl_approx!(Point3 { x, y, z })
|
impl_approx!(Point3 { x, y, z })
|
||||||
|
|
||||||
|
pub trait AsPoint3<T> {
|
||||||
|
pub fn as_point3<'a>(&'a self) -> &'a Point3<T>;
|
||||||
|
pub fn as_mut_point3<'a>(&'a mut self) -> &'a mut Point3<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T:Clone + Num> AsPoint3<T> for Vec3<T> {
|
||||||
|
#[inline]
|
||||||
|
pub fn as_point3<'a>(&'a self) -> &'a Point3<T> {
|
||||||
|
unsafe { cast::transmute(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn as_mut_point3<'a>(&'a mut self) -> &'a mut Point3<T> {
|
||||||
|
unsafe { cast::transmute(self) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T:Num> Point3<T> {
|
impl<T:Num> Point3<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(x: T, y: T, z: T) -> Point3<T> {
|
pub fn new(x: T, y: T, z: T) -> Point3<T> {
|
||||||
|
|
Loading…
Reference in a new issue