Updated to rust nightly
This commit is contained in:
parent
2a8e526d88
commit
22c2fe4755
22 changed files with 92 additions and 81 deletions
|
@ -76,7 +76,7 @@ macro_rules! bench_unop(
|
||||||
i = (i + 1) & (LEN - 1);
|
i = (i + 1) & (LEN - 1);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
test::black_box(elems.unsafe_mut(i).$unop())
|
test::black_box(elems.unchecked_mut(i).$unop())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ extern crate test;
|
||||||
extern crate cgmath;
|
extern crate cgmath;
|
||||||
|
|
||||||
use std::rand::{IsaacRng, Rng};
|
use std::rand::{IsaacRng, Rng};
|
||||||
|
use std::iter;
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
use cgmath::{Quaternion, Basis2, Basis3, Vector3, Rotation2, Rotation3, Rad};
|
use cgmath::{Quaternion, Basis2, Basis3, Vector3, Rotation2, Rotation3, Rad};
|
||||||
|
|
||||||
|
@ -30,15 +31,15 @@ fn bench_from_axis_angle<T: Rotation3<f32>>(bh: &mut Bencher) {
|
||||||
|
|
||||||
let mut rng = IsaacRng::new_unseeded();
|
let mut rng = IsaacRng::new_unseeded();
|
||||||
|
|
||||||
let axis = Vec::from_fn(LEN, |_| rng.gen::<Vector3<f32>>());
|
let axis: Vec<_> = iter::range(0, LEN).map(|_| rng.gen::<Vector3<f32>>()).collect();
|
||||||
let angle = Vec::from_fn(LEN, |_| rng.gen::<Rad<f32>>());
|
let angle: Vec<_> = iter::range(0, LEN).map(|_| rng.gen::<Rad<f32>>()).collect();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
||||||
bh.iter(|| {
|
bh.iter(|| {
|
||||||
i = (i + 1) & (LEN - 1);
|
i = (i + 1) & (LEN - 1);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let res: T = Rotation3::from_axis_angle(axis.unsafe_get(i), *angle.unsafe_get(i));
|
let res: T = Rotation3::from_axis_angle(axis.get_unchecked(i), *angle.get_unchecked(i));
|
||||||
test::black_box(res)
|
test::black_box(res)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -28,7 +28,7 @@ use num::{zero, one, BaseNum, BaseFloat};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::num::Float;
|
use std::num::Float;
|
||||||
|
|
||||||
pub trait Aabb<S: BaseNum, V: Vector<S>, P: Point<S, V>> {
|
pub trait Aabb<S: BaseNum, V: Vector<S>, P: Point<S, V>>: Sized {
|
||||||
/// Create a new AABB using two points as opposing corners.
|
/// Create a new AABB using two points as opposing corners.
|
||||||
fn new(p1: P, p2: P) -> Self;
|
fn new(p1: P, p2: P) -> Self;
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ pub trait Aabb<S: BaseNum, V: Vector<S>, P: Point<S, V>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A two-dimensional AABB, aka a rectangle.
|
/// A two-dimensional AABB, aka a rectangle.
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Aabb2<S> {
|
pub struct Aabb2<S> {
|
||||||
pub min: Point2<S>,
|
pub min: Point2<S>,
|
||||||
pub max: Point2<S>,
|
pub max: Point2<S>,
|
||||||
|
@ -129,7 +129,7 @@ impl<S: BaseNum> fmt::Show for Aabb2<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A three-dimensional AABB, aka a rectangular prism.
|
/// A three-dimensional AABB, aka a rectangular prism.
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Aabb3<S> {
|
pub struct Aabb3<S> {
|
||||||
pub min: Point3<S>,
|
pub min: Point3<S>,
|
||||||
pub max: Point3<S>,
|
pub max: Point3<S>,
|
||||||
|
|
|
@ -18,15 +18,16 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::f64;
|
use std::f64;
|
||||||
use std::num::{cast, Float};
|
use std::num::{cast, Float};
|
||||||
|
use std::ops::*;
|
||||||
|
|
||||||
use approx::ApproxEq;
|
use approx::ApproxEq;
|
||||||
use num::{BaseFloat, One, one, Zero, zero};
|
use num::{BaseFloat, One, one, Zero, zero};
|
||||||
|
|
||||||
/// An angle, in radians
|
/// An angle, in radians
|
||||||
#[deriving(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)]
|
#[derive(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)]
|
||||||
pub struct Rad<S> { pub s: S }
|
pub struct Rad<S> { pub s: S }
|
||||||
/// An angle, in degrees
|
/// An angle, in degrees
|
||||||
#[deriving(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)]
|
#[derive(Copy, Clone, PartialEq, PartialOrd, Hash, RustcEncodable, RustcDecodable, Rand)]
|
||||||
pub struct Deg<S> { pub s: S }
|
pub struct Deg<S> { pub s: S }
|
||||||
|
|
||||||
/// Create a new angle, in radians
|
/// Create a new angle, in radians
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
use std::num;
|
use std::num;
|
||||||
use std::num::Float;
|
use std::num::Float;
|
||||||
|
|
||||||
pub trait ApproxEq<T: Float> {
|
pub trait ApproxEq<T: Float>: Sized {
|
||||||
fn approx_epsilon(_hack: Option<Self>) -> T {
|
fn approx_epsilon(_hack: Option<Self>) -> T {
|
||||||
num::cast(1.0e-5f64).unwrap()
|
num::cast(1.0e-5f64).unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use std::ops::*;
|
||||||
|
|
||||||
/// An array containing elements of type `Element`
|
/// An array containing elements of type `Element`
|
||||||
pub trait Array1<Element: Copy>: Index<uint, Element> + IndexMut<uint, Element> {
|
pub trait Array1<Element: Copy>: Index<uint, Element> + IndexMut<uint, Element> {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#![feature(globs)]
|
#![feature(globs)]
|
||||||
#![feature(macro_rules)]
|
#![feature(macro_rules)]
|
||||||
|
#![feature(old_orphan_check)]
|
||||||
|
|
||||||
//! Computer graphics-centric math.
|
//! Computer graphics-centric math.
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
use point::Point3;
|
use point::Point3;
|
||||||
use vector::Vector3;
|
use vector::Vector3;
|
||||||
|
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Cylinder<S> {
|
pub struct Cylinder<S> {
|
||||||
pub center: Point3<S>,
|
pub center: Point3<S>,
|
||||||
pub axis: Vector3<S>,
|
pub axis: Vector3<S>,
|
||||||
|
|
|
@ -22,7 +22,7 @@ use plane::Plane;
|
||||||
use point::Point3;
|
use point::Point3;
|
||||||
use vector::{Vector, EuclideanVector};
|
use vector::{Vector, EuclideanVector};
|
||||||
|
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Frustum<S> {
|
pub struct Frustum<S> {
|
||||||
pub left: Plane<S>,
|
pub left: Plane<S>,
|
||||||
pub right: Plane<S>,
|
pub right: Plane<S>,
|
||||||
|
@ -59,7 +59,7 @@ Frustum<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct FrustumPoints<S> {
|
pub struct FrustumPoints<S> {
|
||||||
pub near_top_left: Point3<S>,
|
pub near_top_left: Point3<S>,
|
||||||
pub near_top_right: Point3<S>,
|
pub near_top_right: Point3<S>,
|
||||||
|
|
|
@ -22,7 +22,7 @@ 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`.
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Line<P> {
|
pub struct Line<P> {
|
||||||
pub origin: P,
|
pub origin: P,
|
||||||
pub dest: P,
|
pub dest: P,
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::num::cast;
|
use std::num::cast;
|
||||||
|
use std::ops::*;
|
||||||
|
|
||||||
use angle::{Rad, sin, cos, sin_cos};
|
use angle::{Rad, sin, cos, sin_cos};
|
||||||
use approx::ApproxEq;
|
use approx::ApproxEq;
|
||||||
|
@ -29,15 +30,15 @@ use vector::{Vector, EuclideanVector};
|
||||||
use vector::{Vector2, Vector3, Vector4};
|
use vector::{Vector2, Vector3, Vector4};
|
||||||
|
|
||||||
/// A 2 x 2, column major matrix
|
/// A 2 x 2, column major matrix
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)]
|
||||||
pub struct Matrix2<S> { pub x: Vector2<S>, pub y: Vector2<S> }
|
pub struct Matrix2<S> { pub x: Vector2<S>, pub y: Vector2<S> }
|
||||||
|
|
||||||
/// A 3 x 3, column major matrix
|
/// A 3 x 3, column major matrix
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)]
|
||||||
pub struct Matrix3<S> { pub x: Vector3<S>, pub y: Vector3<S>, pub z: Vector3<S> }
|
pub struct Matrix3<S> { pub x: Vector3<S>, pub y: Vector3<S>, pub z: Vector3<S> }
|
||||||
|
|
||||||
/// A 4 x 4, column major matrix
|
/// A 4 x 4, column major matrix
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)]
|
||||||
pub struct Matrix4<S> { pub x: Vector4<S>, pub y: Vector4<S>, pub z: Vector4<S>, pub w: Vector4<S> }
|
pub struct Matrix4<S> { pub x: Vector4<S>, pub y: Vector4<S>, pub z: Vector4<S>, pub w: Vector4<S> }
|
||||||
|
|
||||||
|
|
||||||
|
@ -287,7 +288,8 @@ Matrix4<S> {
|
||||||
pub trait Matrix<S: BaseFloat, V: Clone + Vector<S>>: Array2<V, V, S>
|
pub trait Matrix<S: BaseFloat, V: Clone + Vector<S>>: Array2<V, V, S>
|
||||||
+ Neg<Self>
|
+ Neg<Self>
|
||||||
+ Zero + One
|
+ Zero + One
|
||||||
+ ApproxEq<S> {
|
+ ApproxEq<S>
|
||||||
|
+ Sized {
|
||||||
/// Multiply this matrix by a scalar, returning the new matrix.
|
/// Multiply this matrix by a scalar, returning the new matrix.
|
||||||
fn mul_s(&self, s: S) -> Self;
|
fn mul_s(&self, s: S) -> Self;
|
||||||
/// Divide this matrix by a scalar, returning the new matrix.
|
/// Divide this matrix by a scalar, returning the new matrix.
|
||||||
|
@ -393,9 +395,9 @@ impl<S: BaseFloat> One for Matrix2<S> { #[inline] fn one() -> Matrix2<S> { Matri
|
||||||
impl<S: BaseFloat> One for Matrix3<S> { #[inline] fn one() -> Matrix3<S> { Matrix3::identity() } }
|
impl<S: BaseFloat> One for Matrix3<S> { #[inline] fn one() -> Matrix3<S> { Matrix3::identity() } }
|
||||||
impl<S: BaseFloat> One for Matrix4<S> { #[inline] fn one() -> Matrix4<S> { Matrix4::identity() } }
|
impl<S: BaseFloat> One for Matrix4<S> { #[inline] fn one() -> Matrix4<S> { Matrix4::identity() } }
|
||||||
|
|
||||||
impl<S> FixedArray<[[S, ..2], ..2]> for Matrix2<S> {
|
impl<S> FixedArray<[[S; 2]; 2]> for Matrix2<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_fixed(self) -> [[S, ..2], ..2] {
|
fn into_fixed(self) -> [[S; 2]; 2] {
|
||||||
match self {
|
match self {
|
||||||
Matrix2 { x, y } => [
|
Matrix2 { x, y } => [
|
||||||
x.into_fixed(),
|
x.into_fixed(),
|
||||||
|
@ -405,17 +407,17 @@ impl<S> FixedArray<[[S, ..2], ..2]> for Matrix2<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_fixed<'a>(&'a self) -> &'a [[S, ..2], ..2] {
|
fn as_fixed<'a>(&'a self) -> &'a [[S; 2]; 2] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S, ..2], ..2] {
|
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S; 2]; 2] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed(_v: [[S, ..2], ..2]) -> Matrix2<S> {
|
fn from_fixed(_v: [[S; 2]; 2]) -> Matrix2<S> {
|
||||||
// match v {
|
// match v {
|
||||||
// [x, y] => Matrix2 {
|
// [x, y] => Matrix2 {
|
||||||
// x: FixedArray::from_fixed(x),
|
// x: FixedArray::from_fixed(x),
|
||||||
|
@ -426,12 +428,12 @@ impl<S> FixedArray<[[S, ..2], ..2]> for Matrix2<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_ref<'a>(v: &'a [[S, ..2], ..2]) -> &'a Matrix2<S> {
|
fn from_fixed_ref<'a>(v: &'a [[S; 2]; 2]) -> &'a Matrix2<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_mut<'a>(v: &'a mut [[S, ..2], ..2]) -> &'a mut Matrix2<S> {
|
fn from_fixed_mut<'a>(v: &'a mut [[S; 2]; 2]) -> &'a mut Matrix2<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,9 +473,9 @@ impl<S: Copy + 'static> Array2<Vector2<S>, Vector2<S>, S> for Matrix2<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> FixedArray<[[S, ..3], ..3]> for Matrix3<S> {
|
impl<S> FixedArray<[[S; 3]; 3]> for Matrix3<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_fixed(self) -> [[S, ..3], ..3] {
|
fn into_fixed(self) -> [[S; 3]; 3] {
|
||||||
match self {
|
match self {
|
||||||
Matrix3 { x, y, z } => [
|
Matrix3 { x, y, z } => [
|
||||||
x.into_fixed(),
|
x.into_fixed(),
|
||||||
|
@ -484,17 +486,17 @@ impl<S> FixedArray<[[S, ..3], ..3]> for Matrix3<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_fixed<'a>(&'a self) -> &'a [[S, ..3], ..3] {
|
fn as_fixed<'a>(&'a self) -> &'a [[S; 3]; 3] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S, ..3], ..3] {
|
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S; 3]; 3] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed(_v: [[S, ..3], ..3]) -> Matrix3<S> {
|
fn from_fixed(_v: [[S; 3]; 3]) -> Matrix3<S> {
|
||||||
// match v {
|
// match v {
|
||||||
// [x, y, z] => Matrix3 {
|
// [x, y, z] => Matrix3 {
|
||||||
// x: FixedArray::from_fixed(x),
|
// x: FixedArray::from_fixed(x),
|
||||||
|
@ -506,12 +508,12 @@ impl<S> FixedArray<[[S, ..3], ..3]> for Matrix3<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_ref<'a>(v: &'a [[S, ..3], ..3]) -> &'a Matrix3<S> {
|
fn from_fixed_ref<'a>(v: &'a [[S; 3]; 3]) -> &'a Matrix3<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_mut<'a>(v: &'a mut [[S, ..3], ..3]) -> &'a mut Matrix3<S> {
|
fn from_fixed_mut<'a>(v: &'a mut [[S; 3]; 3]) -> &'a mut Matrix3<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -554,9 +556,9 @@ impl<S: Copy + 'static> Array2<Vector3<S>, Vector3<S>, S> for Matrix3<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> FixedArray<[[S, ..4], ..4]> for Matrix4<S> {
|
impl<S> FixedArray<[[S; 4]; 4]> for Matrix4<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_fixed(self) -> [[S, ..4], ..4] {
|
fn into_fixed(self) -> [[S; 4]; 4] {
|
||||||
match self {
|
match self {
|
||||||
Matrix4 { x, y, z, w } => [
|
Matrix4 { x, y, z, w } => [
|
||||||
x.into_fixed(),
|
x.into_fixed(),
|
||||||
|
@ -568,17 +570,17 @@ impl<S> FixedArray<[[S, ..4], ..4]> for Matrix4<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_fixed<'a>(&'a self) -> &'a [[S, ..4], ..4] {
|
fn as_fixed<'a>(&'a self) -> &'a [[S; 4]; 4] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S, ..4], ..4] {
|
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [[S; 4]; 4] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed(_v: [[S, ..4], ..4]) -> Matrix4<S> {
|
fn from_fixed(_v: [[S; 4]; 4]) -> Matrix4<S> {
|
||||||
// match v {
|
// match v {
|
||||||
// [x, y, z, w] => Matrix4 {
|
// [x, y, z, w] => Matrix4 {
|
||||||
// x: FixedArray::from_fixed(x),
|
// x: FixedArray::from_fixed(x),
|
||||||
|
@ -591,12 +593,12 @@ impl<S> FixedArray<[[S, ..4], ..4]> for Matrix4<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_ref<'a>(v: &'a [[S, ..4], ..4]) -> &'a Matrix4<S> {
|
fn from_fixed_ref<'a>(v: &'a [[S; 4]; 4]) -> &'a Matrix4<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_mut<'a>(v: &'a mut [[S, ..4], ..4]) -> &'a mut Matrix4<S> {
|
fn from_fixed_mut<'a>(v: &'a mut [[S; 4]; 4]) -> &'a mut Matrix4<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ use approx::ApproxEq;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::num::{FloatMath, Int, NumCast, Float};
|
use std::num::{FloatMath, Int, NumCast, Float};
|
||||||
|
use std::ops::*;
|
||||||
|
|
||||||
/// A trait providing a [partial ordering](http://mathworld.wolfram.com/PartialOrder.html).
|
/// A trait providing a [partial ordering](http://mathworld.wolfram.com/PartialOrder.html).
|
||||||
pub trait PartialOrd {
|
pub trait PartialOrd {
|
||||||
|
|
|
@ -18,14 +18,14 @@
|
||||||
use point::{Point2, Point3};
|
use point::{Point2, Point3};
|
||||||
use vector::{Vector2, Vector3};
|
use vector::{Vector2, Vector3};
|
||||||
|
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Obb2<S> {
|
pub struct Obb2<S> {
|
||||||
pub center: Point2<S>,
|
pub center: Point2<S>,
|
||||||
pub axis: Vector2<S>,
|
pub axis: Vector2<S>,
|
||||||
pub extents: Vector2<S>,
|
pub extents: Vector2<S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Obb3<S> {
|
pub struct Obb3<S> {
|
||||||
pub center: Point3<S>,
|
pub center: Point3<S>,
|
||||||
pub axis: Vector3<S>,
|
pub axis: Vector3<S>,
|
||||||
|
|
|
@ -39,7 +39,7 @@ use vector::{Vector, EuclideanVector};
|
||||||
/// The `A*x + B*y + C*z - D = 0` form is preferred over the other common
|
/// The `A*x + B*y + C*z - D = 0` form is preferred over the other common
|
||||||
/// alternative, `A*x + B*y + C*z + D = 0`, because it tends to avoid
|
/// alternative, `A*x + B*y + C*z + D = 0`, because it tends to avoid
|
||||||
/// superfluous negations (see _Real Time Collision Detection_, p. 55).
|
/// superfluous negations (see _Real Time Collision Detection_, p. 55).
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Plane<S> {
|
pub struct Plane<S> {
|
||||||
pub n: Vector3<S>,
|
pub n: Vector3<S>,
|
||||||
pub d: S,
|
pub d: S,
|
||||||
|
|
33
src/point.rs
33
src/point.rs
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use std::ops::*;
|
||||||
|
|
||||||
use approx::ApproxEq;
|
use approx::ApproxEq;
|
||||||
use array::{Array1, FixedArray};
|
use array::{Array1, FixedArray};
|
||||||
|
@ -26,11 +27,11 @@ use num::{BaseNum, BaseFloat, one, zero};
|
||||||
use vector::*;
|
use vector::*;
|
||||||
|
|
||||||
/// A point in 2-dimensional space.
|
/// A point in 2-dimensional space.
|
||||||
#[deriving(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
#[derive(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Point2<S> { pub x: S, pub y: S }
|
pub struct Point2<S> { pub x: S, pub y: S }
|
||||||
|
|
||||||
/// A point in 3-dimensional space.
|
/// A point in 3-dimensional space.
|
||||||
#[deriving(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
#[derive(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Point3<S> { pub x: S, pub y: S, pub z: S }
|
pub struct Point3<S> { pub x: S, pub y: S, pub z: S }
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,35 +102,35 @@ pub trait Point<S: BaseNum, V: Vector<S>>: Array1<S> + Clone {
|
||||||
fn max(&self, p: &Self) -> Self;
|
fn max(&self, p: &Self) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> FixedArray<[S, ..2]> for Point2<S> {
|
impl<S> FixedArray<[S; 2]> for Point2<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_fixed(self) -> [S, ..2] {
|
fn into_fixed(self) -> [S; 2] {
|
||||||
match self { Point2 { x, y } => [x, y] }
|
match self { Point2 { x, y } => [x, y] }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_fixed<'a>(&'a self) -> &'a [S, ..2] {
|
fn as_fixed<'a>(&'a self) -> &'a [S; 2] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [S, ..2] {
|
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [S; 2] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed(_v: [S, ..2]) -> Point2<S> {
|
fn from_fixed(_v: [S; 2]) -> Point2<S> {
|
||||||
// match v { [x, y] => Point2 { x: x, y: y } }
|
// match v { [x, y] => Point2 { x: x, y: y } }
|
||||||
panic!("Unimplemented, pending a fix for rust-lang/rust#16418");
|
panic!("Unimplemented, pending a fix for rust-lang/rust#16418");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_ref<'a>(v: &'a [S, ..2]) -> &'a Point2<S> {
|
fn from_fixed_ref<'a>(v: &'a [S; 2]) -> &'a Point2<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_mut<'a>(v: &'a mut [S, ..2]) -> &'a mut Point2<S> {
|
fn from_fixed_mut<'a>(v: &'a mut [S; 2]) -> &'a mut Point2<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,35 +256,35 @@ impl<S: BaseFloat> ApproxEq<S> for Point2<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> FixedArray<[S, ..3]> for Point3<S> {
|
impl<S> FixedArray<[S; 3]> for Point3<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_fixed(self) -> [S, ..3] {
|
fn into_fixed(self) -> [S; 3] {
|
||||||
match self { Point3 { x, y, z } => [x, y, z] }
|
match self { Point3 { x, y, z } => [x, y, z] }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_fixed<'a>(&'a self) -> &'a [S, ..3] {
|
fn as_fixed<'a>(&'a self) -> &'a [S; 3] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [S, ..3] {
|
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [S; 3] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed(_v: [S, ..3]) -> Point3<S> {
|
fn from_fixed(_v: [S; 3]) -> Point3<S> {
|
||||||
// match v { [x, y, z] => Point3 { x: x, y: y, z: z } }
|
// match v { [x, y, z] => Point3 { x: x, y: y, z: z } }
|
||||||
panic!("Unimplemented, pending a fix for rust-lang/rust#16418")
|
panic!("Unimplemented, pending a fix for rust-lang/rust#16418")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_ref<'a>(v: &'a [S, ..3]) -> &'a Point3<S> {
|
fn from_fixed_ref<'a>(v: &'a [S; 3]) -> &'a Point3<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_mut<'a>(v: &'a mut [S, ..3]) -> &'a mut Point3<S> {
|
fn from_fixed_mut<'a>(v: &'a mut [S; 3]) -> &'a mut Point3<S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub trait Projection<S>: ToMatrix4<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A perspective projection based on a vertical field-of-view angle.
|
/// A perspective projection based on a vertical field-of-view angle.
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct PerspectiveFov<S, A> {
|
pub struct PerspectiveFov<S, A> {
|
||||||
pub fovy: A,
|
pub fovy: A,
|
||||||
pub aspect: S,
|
pub aspect: S,
|
||||||
|
@ -143,7 +143,7 @@ impl<S: BaseFloat, A: Angle<S>> ToMatrix4<S> for PerspectiveFov<S, A> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A perspective projection with arbitrary left/right/bottom/top distances
|
/// A perspective projection with arbitrary left/right/bottom/top distances
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Perspective<S> {
|
pub struct Perspective<S> {
|
||||||
pub left: S, right: S,
|
pub left: S, right: S,
|
||||||
pub bottom: S, top: S,
|
pub bottom: S, top: S,
|
||||||
|
@ -193,7 +193,7 @@ impl<S: BaseFloat + 'static> ToMatrix4<S> for Perspective<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An orthographic projection with arbitrary left/right/bottom/top distances
|
/// An orthographic projection with arbitrary left/right/bottom/top distances
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Ortho<S> {
|
pub struct Ortho<S> {
|
||||||
pub left: S, right: S,
|
pub left: S, right: S,
|
||||||
pub bottom: S, top: S,
|
pub bottom: S, top: S,
|
||||||
|
|
|
@ -17,6 +17,7 @@ use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::f64;
|
use std::f64;
|
||||||
use std::num::{cast, Float};
|
use std::num::{cast, Float};
|
||||||
|
use std::ops::*;
|
||||||
|
|
||||||
use angle::{Angle, Rad, acos, sin, sin_cos, rad};
|
use angle::{Angle, Rad, acos, sin, sin_cos, rad};
|
||||||
use approx::ApproxEq;
|
use approx::ApproxEq;
|
||||||
|
@ -29,7 +30,7 @@ use vector::{Vector3, Vector, EuclideanVector};
|
||||||
|
|
||||||
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
|
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
|
||||||
/// form.
|
/// form.
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Rand)]
|
||||||
pub struct Quaternion<S> { pub s: S, pub v: Vector3<S> }
|
pub struct Quaternion<S> { pub s: S, pub v: Vector3<S> }
|
||||||
|
|
||||||
/// Represents types which can be expressed as a quaternion.
|
/// Represents types which can be expressed as a quaternion.
|
||||||
|
@ -52,7 +53,7 @@ impl<S: Copy + BaseFloat> Array1<S> for Quaternion<S> {
|
||||||
impl<S: BaseFloat> Index<uint, S> for Quaternion<S> {
|
impl<S: BaseFloat> Index<uint, S> for Quaternion<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &uint) -> &'a S {
|
fn index<'a>(&'a self, i: &uint) -> &'a S {
|
||||||
let slice: &[S, ..4] = unsafe { mem::transmute(self) };
|
let slice: &[S; 4] = unsafe { mem::transmute(self) };
|
||||||
&slice[*i]
|
&slice[*i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +61,7 @@ impl<S: BaseFloat> Index<uint, S> for Quaternion<S> {
|
||||||
impl<S: BaseFloat> IndexMut<uint, S> for Quaternion<S> {
|
impl<S: BaseFloat> IndexMut<uint, S> for Quaternion<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut S {
|
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut S {
|
||||||
let slice: &'a mut [S, ..4] = unsafe { mem::transmute(self) };
|
let slice: &'a mut [S; 4] = unsafe { mem::transmute(self) };
|
||||||
&mut slice[*i]
|
&mut slice[*i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use vector::{Vector, Vector2, Vector3};
|
||||||
|
|
||||||
/// A generic ray starting at `origin` and extending infinitely in
|
/// A generic ray starting at `origin` and extending infinitely in
|
||||||
/// `direction`.
|
/// `direction`.
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Ray<P,V> {
|
pub struct Ray<P,V> {
|
||||||
pub origin: P,
|
pub origin: P,
|
||||||
pub direction: V,
|
pub direction: V,
|
||||||
|
|
|
@ -26,7 +26,7 @@ use vector::{Vector, Vector2, Vector3};
|
||||||
|
|
||||||
/// A trait for a generic rotation. A rotation is a transformation that
|
/// A trait for a generic rotation. A rotation is a transformation that
|
||||||
/// creates a circular motion, and preserves at least one point in the space.
|
/// creates a circular motion, and preserves at least one point in the space.
|
||||||
pub trait Rotation<S: BaseNum, V: Vector<S>, P: Point<S, V>>: PartialEq + ApproxEq<S> {
|
pub trait Rotation<S: BaseNum, V: Vector<S>, P: Point<S, V>>: PartialEq + ApproxEq<S> + Sized {
|
||||||
/// Create the identity transform (causes no transformation).
|
/// Create the identity transform (causes no transformation).
|
||||||
fn identity() -> Self;
|
fn identity() -> Self;
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ pub trait Rotation3<S: BaseNum>: Rotation<S, Vector3<S>, Point3<S>>
|
||||||
/// let unit_y3 = rot_half.concat(&rot_half).rotate_vector(&unit_x);
|
/// let unit_y3 = rot_half.concat(&rot_half).rotate_vector(&unit_x);
|
||||||
/// assert!(unit_y3.approx_eq(&unit_y2));
|
/// assert!(unit_y3.approx_eq(&unit_y2));
|
||||||
/// ```
|
/// ```
|
||||||
#[deriving(PartialEq, Copy, Clone, RustcEncodable, RustcDecodable)]
|
#[derive(PartialEq, Copy, Clone, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Basis2<S> {
|
pub struct Basis2<S> {
|
||||||
mat: Matrix2<S>
|
mat: Matrix2<S>
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ impl<S: BaseFloat + 'static> Rotation2<S> for Basis2<S> {
|
||||||
/// inversion, can be implemented more efficiently than the implementations for
|
/// inversion, can be implemented more efficiently than the implementations for
|
||||||
/// `math::Matrix3`. To ensure orthogonality is maintained, the operations have
|
/// `math::Matrix3`. To ensure orthogonality is maintained, the operations have
|
||||||
/// been restricted to a subeset of those implemented on `Matrix3`.
|
/// been restricted to a subeset of those implemented on `Matrix3`.
|
||||||
#[deriving(PartialEq, Copy, Clone, RustcEncodable, RustcDecodable)]
|
#[derive(PartialEq, Copy, Clone, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Basis3<S> {
|
pub struct Basis3<S> {
|
||||||
mat: Matrix3<S>
|
mat: Matrix3<S>
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ use point::{Point, Point3};
|
||||||
use ray::Ray3;
|
use ray::Ray3;
|
||||||
use vector::Vector;
|
use vector::Vector;
|
||||||
|
|
||||||
#[deriving(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Sphere<S> {
|
pub struct Sphere<S> {
|
||||||
pub center: Point3<S>,
|
pub center: Point3<S>,
|
||||||
pub radius: S,
|
pub radius: S,
|
||||||
|
|
|
@ -26,7 +26,7 @@ use vector::{Vector, Vector3};
|
||||||
/// A trait representing an [affine
|
/// A trait representing an [affine
|
||||||
/// transformation](https://en.wikipedia.org/wiki/Affine_transformation) that
|
/// transformation](https://en.wikipedia.org/wiki/Affine_transformation) that
|
||||||
/// can be applied to points or vectors. An affine transformation is one which
|
/// can be applied to points or vectors. An affine transformation is one which
|
||||||
pub trait Transform<S: BaseNum, V: Vector<S>, P: Point<S,V>> {
|
pub trait Transform<S: BaseNum, V: Vector<S>, P: Point<S,V>>: Sized {
|
||||||
/// Create an identity transformation. That is, a transformation which
|
/// Create an identity transformation. That is, a transformation which
|
||||||
/// does nothing.
|
/// does nothing.
|
||||||
fn identity() -> Self;
|
fn identity() -> Self;
|
||||||
|
@ -76,7 +76,7 @@ pub trait Transform<S: BaseNum, V: Vector<S>, P: Point<S,V>> {
|
||||||
|
|
||||||
/// A generic transformation consisting of a rotation,
|
/// A generic transformation consisting of a rotation,
|
||||||
/// displacement vector and scale amount.
|
/// displacement vector and scale amount.
|
||||||
#[deriving(Copy, Clone, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
||||||
pub struct Decomposed<S, V, R> {
|
pub struct Decomposed<S, V, R> {
|
||||||
pub scale: S,
|
pub scale: S,
|
||||||
pub rot: R,
|
pub rot: R,
|
||||||
|
@ -159,7 +159,7 @@ impl<S: BaseFloat, R: fmt::Show + Rotation3<S>> fmt::Show for Decomposed<S,Vecto
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A homogeneous transformation matrix.
|
/// A homogeneous transformation matrix.
|
||||||
#[deriving(Copy, Clone, RustcEncodable, RustcDecodable)]
|
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
||||||
pub struct AffineMatrix3<S> {
|
pub struct AffineMatrix3<S> {
|
||||||
pub mat: Matrix4<S>,
|
pub mat: Matrix4<S>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::num::NumCast;
|
use std::num::NumCast;
|
||||||
|
use std::ops::*;
|
||||||
|
|
||||||
use angle::{Rad, atan2, acos};
|
use angle::{Rad, atan2, acos};
|
||||||
use approx::ApproxEq;
|
use approx::ApproxEq;
|
||||||
|
@ -177,7 +178,7 @@ pub trait Vector<S: BaseNum>: Array1<S> + Zero + One + Neg<Self> {
|
||||||
// Utility macro for generating associated functions for the vectors
|
// Utility macro for generating associated functions for the vectors
|
||||||
macro_rules! vec(
|
macro_rules! vec(
|
||||||
($Self:ident <$S:ident> { $($field:ident),+ }, $n:expr) => (
|
($Self:ident <$S:ident> { $($field:ident),+ }, $n:expr) => (
|
||||||
#[deriving(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable, Rand)]
|
#[derive(PartialEq, Eq, Copy, Clone, Hash, RustcEncodable, RustcDecodable, Rand)]
|
||||||
pub struct $Self<S> { $(pub $field: S),+ }
|
pub struct $Self<S> { $(pub $field: S),+ }
|
||||||
|
|
||||||
impl<$S> $Self<$S> {
|
impl<$S> $Self<$S> {
|
||||||
|
@ -217,35 +218,35 @@ macro_rules! vec(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$S> FixedArray<[$S, ..$n]> for $Self<$S> {
|
impl<$S> FixedArray<[$S; $n]> for $Self<$S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_fixed(self) -> [$S, ..$n] {
|
fn into_fixed(self) -> [$S; $n] {
|
||||||
match self { $Self { $($field),+ } => [$($field),+] }
|
match self { $Self { $($field),+ } => [$($field),+] }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_fixed<'a>(&'a self) -> &'a [$S, ..$n] {
|
fn as_fixed<'a>(&'a self) -> &'a [$S; $n] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [$S, ..$n] {
|
fn as_mut_fixed<'a>(&'a mut self) -> &'a mut [$S; $n] {
|
||||||
unsafe { mem::transmute(self) }
|
unsafe { mem::transmute(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed(_v: [$S, ..$n]) -> $Self<$S> {
|
fn from_fixed(_v: [$S; $n]) -> $Self<$S> {
|
||||||
// match v { [$($field),+] => $Self { $($field: $field),+ } }
|
// match v { [$($field),+] => $Self { $($field: $field),+ } }
|
||||||
panic!("Unimplemented, pending a fix for rust-lang/rust#16418");
|
panic!("Unimplemented, pending a fix for rust-lang/rust#16418");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_ref<'a>(v: &'a [$S, ..$n]) -> &'a $Self<$S> {
|
fn from_fixed_ref<'a>(v: &'a [$S; $n]) -> &'a $Self<$S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_fixed_mut<'a>(v: &'a mut [$S, ..$n]) -> &'a mut $Self<$S> {
|
fn from_fixed_mut<'a>(v: &'a mut [$S; $n]) -> &'a mut $Self<$S> {
|
||||||
unsafe { mem::transmute(v) }
|
unsafe { mem::transmute(v) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -442,7 +443,8 @@ impl<S: BaseNum> Vector4<S> {
|
||||||
/// Specifies geometric operations for vectors. This is only implemented for
|
/// Specifies geometric operations for vectors. This is only implemented for
|
||||||
/// 2-dimensional and 3-dimensional vectors.
|
/// 2-dimensional and 3-dimensional vectors.
|
||||||
pub trait EuclideanVector<S: BaseFloat>: Vector<S>
|
pub trait EuclideanVector<S: BaseFloat>: Vector<S>
|
||||||
+ ApproxEq<S> {
|
+ ApproxEq<S>
|
||||||
|
+ Sized {
|
||||||
/// Returns `true` if the vector is perpendicular (at right angles) to the
|
/// Returns `true` if the vector is perpendicular (at right angles) to the
|
||||||
/// other vector.
|
/// other vector.
|
||||||
fn is_perpendicular(&self, other: &Self) -> bool {
|
fn is_perpendicular(&self, other: &Self) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue