Mint flavour
This commit is contained in:
parent
7a21125c55
commit
d72fc08826
10 changed files with 126 additions and 5 deletions
|
@ -9,7 +9,7 @@ cache: cargo
|
|||
|
||||
env:
|
||||
- CARGO_FEATURES=""
|
||||
- CARGO_FEATURES="serde"
|
||||
- CARGO_FEATURES="mint serde"
|
||||
|
||||
matrix:
|
||||
include:
|
||||
|
|
|
@ -6,21 +6,22 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
- Refactored `simd` and `serde` dependencies to match feature names
|
||||
- Refactor `simd` and `serde` dependencies to match feature names
|
||||
- Integrate `mint` conversions behind a feature
|
||||
|
||||
## [v0.14.1] - 2017-05-02
|
||||
|
||||
### Fixed
|
||||
|
||||
- Added a workaround for rust-lang/rust#41478, and in the process cleaned up
|
||||
- Add a workaround for rust-lang/rust#41478, and in the process cleaned up
|
||||
some type projections for angles
|
||||
|
||||
## [v0.14.0] - 2017-04-26
|
||||
|
||||
## Changed
|
||||
|
||||
- Constrained `VectorSpace`, `Rotation`, and `Angle` by `iter::Sum`
|
||||
- Constrained `SquareMatrix` by `iter::Product`
|
||||
- Constrain `VectorSpace`, `Rotation`, and `Angle` by `iter::Sum`
|
||||
- Constrain `SquareMatrix` by `iter::Product`
|
||||
|
||||
## [v0.13.1] - 2017-04-22
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ unstable = []
|
|||
|
||||
[dependencies]
|
||||
approx = "0.1"
|
||||
mint = { version = "0.4.1", optional = true }
|
||||
num-traits = "0.1"
|
||||
rand = "0.3"
|
||||
serde = { version = "1.0", features = ["serde_derive"], optional = true }
|
||||
|
|
23
src/euler.rs
23
src/euler.rs
|
@ -21,6 +21,8 @@ use structure::*;
|
|||
use angle::Rad;
|
||||
use approx::ApproxEq;
|
||||
use quaternion::Quaternion;
|
||||
#[cfg(feature = "mint")]
|
||||
use mint;
|
||||
use num::BaseFloat;
|
||||
|
||||
/// A set of [Euler angles] representing a rotation in three-dimensional space.
|
||||
|
@ -179,3 +181,24 @@ impl<A: Angle + Rand> Rand for Euler<A> {
|
|||
Euler { x: rng.gen(), y: rng.gen(), z: rng.gen() }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
type MintEuler<S> = mint::EulerAngles<S, mint::IntraXYZ>;
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl<S, A: Angle + From<S>> From<MintEuler<S>> for Euler<A> {
|
||||
fn from(mint: MintEuler<S>) -> Self {
|
||||
Euler {
|
||||
x: mint.a.into(),
|
||||
y: mint.b.into(),
|
||||
z: mint.c.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl<S: Clone, A: Angle + Into<S>> Into<MintEuler<S>> for Euler<A> {
|
||||
fn into(self) -> MintEuler<S> {
|
||||
MintEuler::from([self.x.into(), self.y.into(), self.z.into()])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,10 @@
|
|||
|
||||
#[macro_use]
|
||||
extern crate approx;
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
pub extern crate mint;
|
||||
|
||||
pub extern crate num_traits;
|
||||
extern crate rand;
|
||||
|
||||
|
|
|
@ -456,3 +456,23 @@ macro_rules! impl_operator_simd {
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Generate `mint` types conversion implementations
|
||||
#[cfg(feature = "mint")]
|
||||
macro_rules! impl_mint_conversions {
|
||||
($ArrayN:ident { $($field:ident),+ }, $Mint:ident) => {
|
||||
impl<S: Clone> Into<mint::$Mint<S>> for $ArrayN<S> {
|
||||
#[inline]
|
||||
fn into(self) -> mint::$Mint<S> {
|
||||
mint::$Mint::from([$(self.$field),+])
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> From<mint::$Mint<S>> for $ArrayN<S> {
|
||||
#[inline]
|
||||
fn from(v: mint::$Mint<S>) -> Self {
|
||||
$ArrayN { $( $field: v.$field, )+ }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,9 @@ use quaternion::Quaternion;
|
|||
use transform::{Transform, Transform2, Transform3};
|
||||
use vector::{Vector2, Vector3, Vector4};
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
use mint;
|
||||
|
||||
/// A 2 x 2, column major matrix
|
||||
///
|
||||
/// This type is marked as `#[repr(C)]`.
|
||||
|
@ -1268,6 +1271,33 @@ fixed_array_conversions!(Matrix2<S> { x:0, y:1 }, 2);
|
|||
fixed_array_conversions!(Matrix3<S> { x:0, y:1, z:2 }, 3);
|
||||
fixed_array_conversions!(Matrix4<S> { x:0, y:1, z:2, w:3 }, 4);
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
macro_rules! mint_conversions {
|
||||
($MatrixN:ident { $($field:ident),+ }, $MintN:ident) => {
|
||||
impl<S: Clone> Into<mint::$MintN<S>> for $MatrixN<S> {
|
||||
#[inline]
|
||||
fn into(self) -> mint::$MintN<S> {
|
||||
mint::$MintN { $($field: self.$field.into()),+ }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> From<mint::$MintN<S>> for $MatrixN<S> {
|
||||
#[inline]
|
||||
fn from(m: mint::$MintN<S>) -> Self {
|
||||
$MatrixN { $($field: m.$field.into()),+ }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
mint_conversions!(Matrix2 { x, y }, ColumnMatrix2);
|
||||
#[cfg(feature = "mint")]
|
||||
mint_conversions!(Matrix3 { x, y, z }, ColumnMatrix3);
|
||||
#[cfg(feature = "mint")]
|
||||
mint_conversions!(Matrix4 { x, y, z, w }, ColumnMatrix4);
|
||||
|
||||
impl<S: BaseFloat> From<Matrix2<S>> for Matrix3<S> {
|
||||
/// Clone the elements of a 2-dimensional matrix into the top-left corner
|
||||
/// of a 3-dimensional identity matrix.
|
||||
|
|
|
@ -28,6 +28,9 @@ use approx::ApproxEq;
|
|||
use num::{BaseNum, BaseFloat};
|
||||
use vector::{Vector1, Vector2, Vector3, Vector4};
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
use mint;
|
||||
|
||||
/// A point in 1-dimensional space.
|
||||
///
|
||||
/// This type is marked as `#[repr(C)]`.
|
||||
|
@ -264,6 +267,11 @@ impl_tuple_conversions!(Point1<S> { x }, (S,));
|
|||
impl_tuple_conversions!(Point2<S> { x, y }, (S, S));
|
||||
impl_tuple_conversions!(Point3<S> { x, y, z }, (S, S, S));
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl_mint_conversions!(Point2 { x, y }, Point2);
|
||||
#[cfg(feature = "mint")]
|
||||
impl_mint_conversions!(Point3 { x, y, z }, Point3);
|
||||
|
||||
impl<S: fmt::Debug> fmt::Debug for Point1<S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(f, "Point1 "));
|
||||
|
|
|
@ -34,6 +34,9 @@ use vector::Vector3;
|
|||
#[cfg(feature = "simd")]
|
||||
use simd::f32x4 as Simdf32x4;
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
use mint;
|
||||
|
||||
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
|
||||
/// form.
|
||||
///
|
||||
|
@ -808,6 +811,27 @@ impl<S: BaseFloat + Rand> Rand for Quaternion<S> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl<S> From<mint::Quaternion<S>> for Quaternion<S> {
|
||||
fn from(q: mint::Quaternion<S>) -> Self {
|
||||
Quaternion {
|
||||
s: q.s,
|
||||
v: q.v.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl<S: Clone> Into<mint::Quaternion<S>> for Quaternion<S> {
|
||||
fn into(self) -> mint::Quaternion<S> {
|
||||
mint::Quaternion {
|
||||
s: self.s,
|
||||
v: self.v.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use quaternion::*;
|
||||
|
|
|
@ -33,6 +33,9 @@ use simd::i32x4 as Simdi32x4;
|
|||
#[cfg(feature = "simd")]
|
||||
use simd::u32x4 as Simdu32x4;
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
use mint;
|
||||
|
||||
/// A 1-dimensional vector.
|
||||
///
|
||||
/// This type is marked as `#[repr(C)]`.
|
||||
|
@ -1119,6 +1122,13 @@ impl MulAssign<u32> for Vector4<u32> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl_mint_conversions!(Vector2 { x, y }, Vector2);
|
||||
#[cfg(feature = "mint")]
|
||||
impl_mint_conversions!(Vector3 { x, y, z }, Vector3);
|
||||
#[cfg(feature = "mint")]
|
||||
impl_mint_conversions!(Vector4 { x, y, z, w }, Vector4);
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
Loading…
Reference in a new issue