mint-0.5.5/.gitignore010064400007650000024000000000361364510454400127040ustar0000000000000000target/ **/*.rs.bk Cargo.lock mint-0.5.5/.travis.yml010064400007650000024000000000751364510454400130300ustar0000000000000000language: rust rust: - stable script: - cargo test --all mint-0.5.5/Cargo.toml.orig010064400007650000024000000007431364510626100136060ustar0000000000000000[package] name = "mint" version = "0.5.5" authors = [ "Benjamin Saunders ", "Dzmitry Malyshau ", "Evgenii P. ", "George Burton ", "Ilya Bogdanov ", "Osspial ", ] description = "Math interoperability standard types" license = "MIT" repository = "https://github.com/kvark/mint" documentation = "https://docs.rs/mint" keywords = ["math"] [dependencies] mint-0.5.5/Cargo.toml0000644000000017471364514757000101330ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "mint" version = "0.5.5" authors = ["Benjamin Saunders ", "Dzmitry Malyshau ", "Evgenii P. ", "George Burton ", "Ilya Bogdanov ", "Osspial "] description = "Math interoperability standard types" documentation = "https://docs.rs/mint" keywords = ["math"] license = "MIT" repository = "https://github.com/kvark/mint" [dependencies] mint-0.5.5/CHANGELOG.md010064400007650000024000000013321364510616400125250ustar0000000000000000# Change Log ## v0.5.5 (13-04-2020) - fixed the `Quaternion` memory layout ## v0.5.4 (18-11-2019) - make it `[no_std]` ## v0.5.3 (30-09-2019) - removed executable flag from the crate files ## v0.5.2 (16-09-2019) - even more matrices ## v0.5.1 (23-07-2018) - more asymmetrical matrix types ## v0.5.0 (28-12-2017) - removed `LeftQuaternion` - implement `AsRef` ## v0.4.2 (08-06-2017) - derive traits for rotation types ## v0.4.1 (06-06-2017) - major refactor of Euler angles ## v0.3.0 (01-06-2017) - added strongly-typed Row/Column matrices - added points ## v0.2.0 (29-05-2017) - removed Row/Column matrix separation - added `QuatScalePos` ## v0.1.0 (26-05-2017) - basic matrices, vectors, quaternions, and Euler angles mint-0.5.5/LICENSE010064400007650000024000000020611364510454400117210ustar0000000000000000MIT License Copyright (c) 2017 Dzmitry Malyshau Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. mint-0.5.5/README.md010064400007650000024000000014101364510454400121700ustar0000000000000000# mint [![Build Status](https://travis-ci.org/kvark/mint.svg)](https://travis-ci.org/kvark/mint) [![Docs](https://docs.rs/mint/badge.svg)](https://docs.rs/mint) [![Crates.io](https://img.shields.io/crates/v/mint.svg?maxAge=2592000)](https://crates.io/crates/mint) Math INteroperability Types: ![xkcd standard](https://imgs.xkcd.com/comics/standards.png) This library provides standard mathematical types types used in computer graphics. Its only purpose is to serve as a standard and interoperability language between various components of [rust-gamedev](http://arewegameyet.com/categories/math/) ecosystem that happen to expose math-related types on their API. There are no operations defined for the types other than for the means of conversion from/into external types. mint-0.5.5/src/lib.rs010064400007650000024000000004661364510454400126260ustar0000000000000000/*! Mint - Math interoperability standard types. Defines basic math types useful for computer graphics. Designed to serve as an interoperability standard between libraries. */ #![no_std] #![deny(missing_docs)] mod matrix; mod rotation; mod vector; pub use matrix::*; pub use rotation::*; pub use vector::*; mint-0.5.5/src/matrix.rs010064400007650000024000000142661364510454400133670ustar0000000000000000use vector::{Vector2, Vector3, Vector4}; macro_rules! matrix { ($name:ident : $vec:ident[ $($field:ident[$($sub:ident),*] = $index:expr),* ] = ($inner:expr, $outer:expr)) => { #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] #[repr(C)] #[allow(missing_docs)] //TODO: actually have docs pub struct $name { $( pub $field : $vec, )* } impl From<[[T; $inner]; $outer]> for $name { fn from([$($field),*]: [[T; $inner]; $outer]) -> Self { $name { $( $field: From::from($field), )* } } } impl Into<[[T; $inner]; $outer]> for $name { fn into(self) -> [[T; $inner]; $outer] { [$( self.$field.into() ),*] } } impl AsRef<[[T; $inner]; $outer]> for $name { fn as_ref(&self) -> &[[T; $inner]; $outer] { unsafe { ::core::mem::transmute(self) } } } impl From<[T; $inner * $outer]> for $name { fn from(m: [T; $inner * $outer]) -> Self { $name { $( $field: $vec::from_slice(&m[$index*$inner..($index+1)*$inner]), )* } } } impl Into<[T; $inner * $outer]> for $name { fn into(self) -> [T; $inner * $outer] { let $name { $($field),* } = self; [ $( $( $field.$sub ),* ),* ] } } impl AsRef<[T; $inner * $outer]> for $name { fn as_ref(&self) -> &[T; $inner * $outer] { unsafe { ::core::mem::transmute(self) } } } }; } macro_rules! turn { ($name:ident : $vec:ident[$( $field:ident [ $($sub:ident),* ] ),* ] = $transposed:ident) => { impl From<$transposed> for $name { fn from(m: $transposed) -> Self { $name { $( $field: $vec { $( $sub: m.$sub.$field, )* }, )* } } } } } /// 2x2 row-major matrix. matrix!( RowMatrix2 : Vector2[x[x,y]=0,y[x,y]=1] = (2, 2)); turn!( RowMatrix2 : Vector2[x[x,y],y[x,y]] = ColumnMatrix2 ); /// 2x3 row-major matrix. /// Useful for combining rotation, scale, and translation in 2D space. matrix!( RowMatrix2x3 : Vector3[x[x,y,z]=0,y[x,y,z]=1] = (3, 2)); turn!( RowMatrix2x3 : Vector3[x[x,y,z],y[x,y,z]] = ColumnMatrix2x3 ); /// 2x4 row-major matrix. matrix!( RowMatrix2x4 : Vector4[x[x,y,z,w]=0,y[x,y,z,w]=1] = (4, 2)); turn!( RowMatrix2x4 : Vector4[x[x,y,z,w],y[x,y,z,w]] = ColumnMatrix2x4 ); /// 3x2 row-major matrix. /// Useful for combining rotation, scale, and translation in 2D space. matrix!( RowMatrix3x2 : Vector2[x[x,y]=0,y[x,y]=1,z[x,y]=2] = (2, 3)); turn!( RowMatrix3x2 : Vector2[x[x,y],y[x,y],z[x,y]] = ColumnMatrix3x2 ); /// 3x3 row-major matrix. /// Useful for representing rotation and scale in 3D space. matrix!( RowMatrix3 : Vector3[x[x,y,z]=0,y[x,y,z]=1,z[x,y,z]=2] = (3, 3)); turn!( RowMatrix3 : Vector3[x[x,y,z],y[x,y,z],z[x,y,z]] = ColumnMatrix3 ); /// 3x4 row-major matrix. /// Useful for combining rotation, scale, and translation in 3D space. matrix!( RowMatrix3x4 : Vector4[x[x,y,z,w]=0,y[x,y,z,w]=1,z[x,y,z,w]=2] = (4, 3)); turn!( RowMatrix3x4 : Vector4[x[x,y,z,w],y[x,y,z,w],z[x,y,z,w]] = ColumnMatrix3x4 ); /// 4x3 row-major matrix. /// Useful for combining rotation, scale, and translation in 3D space. matrix!( RowMatrix4x3 : Vector3[x[x,y,z]=0,y[x,y,z]=1,z[x,y,z]=2,w[x,y,z]=3] = (3, 4)); turn!( RowMatrix4x3 : Vector3[x[x,y,z],y[x,y,z],z[x,y,z],w[x,y,z]] = ColumnMatrix4x3 ); // 4x2 row-major matrix. matrix!( RowMatrix4x2 : Vector2[x[x,y]=0,y[x,y]=1,z[x,y]=2,w[x,y]=3] = (2, 4)); turn!( RowMatrix4x2 : Vector2[x[x,y],y[x,y],z[x,y],w[x,y]] = ColumnMatrix4x2 ); /// 4x4 row-major matrix. matrix!( RowMatrix4 : Vector4[x[x,y,z,w]=0,y[x,y,z,w]=1,z[x,y,z,w]=2,w[x,y,z,w]=3] = (4, 4)); turn!( RowMatrix4 : Vector4[x[x,y,z,w],y[x,y,z,w],z[x,y,z,w],w[x,y,z,w]] = ColumnMatrix4 ); /// 2x2 column-major matrix. matrix!( ColumnMatrix2 : Vector2[x[x,y]=0,y[x,y]=1] = (2, 2)); turn!( ColumnMatrix2 : Vector2[x[x,y],y[x,y]] = RowMatrix2 ); /// 2x3 column-major matrix. /// Useful for combining rotation, scale, and translation in 2D space. matrix!( ColumnMatrix2x3 : Vector2[x[x,y]=0,y[x,y]=1,z[x,y]=2] = (2, 3)); turn!( ColumnMatrix2x3 : Vector2[x[x,y],y[x,y],z[x,y]] = RowMatrix2x3 ); // 2x4 column-major matrix. matrix!( ColumnMatrix2x4 : Vector2[x[x,y]=0,y[x,y]=1,z[x,y]=2,w[x,y]=3] = (2, 4)); turn!( ColumnMatrix2x4 : Vector2[x[x,y],y[x,y],z[x,y],w[x,y]] = RowMatrix2x4 ); /// 3x2 column-major matrix. /// Useful for combining rotation, scale, and translation in 2D space. matrix!( ColumnMatrix3x2 : Vector3[x[x,y,z]=0,y[x,y,z]=1] = (3, 2)); turn!( ColumnMatrix3x2 : Vector3[x[x,y,z],y[x,y,z]] = RowMatrix3x2 ); /// 3x3 column-major matrix. /// Useful for representing rotation and scale in 3D space. matrix!( ColumnMatrix3 : Vector3[x[x,y,z]=0,y[x,y,z]=1,z[x,y,z]=2] = (3, 3)); turn!( ColumnMatrix3 : Vector3[x[x,y,z],y[x,y,z],z[x,y,z]] = RowMatrix3 ); /// 3x4 column-major matrix. /// Useful for combining rotation, scale, and translation in 3D space. matrix!( ColumnMatrix3x4 : Vector3[x[x,y,z]=0,y[x,y,z]=1,z[x,y,z]=2,w[x,y,z]=3] = (3, 4)); turn!( ColumnMatrix3x4 : Vector3[x[x,y,z],y[x,y,z],z[x,y,z],w[x,y,z]] = RowMatrix3x4 ); /// 4x2 column-major matrix. matrix!( ColumnMatrix4x2 : Vector4[x[x,y,z,w]=0,y[x,y,z,w]=1] = (4, 2)); turn!( ColumnMatrix4x2 : Vector4[x[x,y,z,w],y[x,y,z,w]] = RowMatrix4x2 ); /// 4x3 column-major matrix. /// Useful for combining rotation, scale, and translation in 3D space. matrix!( ColumnMatrix4x3 : Vector4[x[x,y,z,w]=0,y[x,y,z,w]=1,z[x,y,z,w]=2] = (4, 3)); turn!( ColumnMatrix4x3 : Vector4[x[x,y,z,w],y[x,y,z,w],z[x,y,z,w]] = RowMatrix4x3 ); /// 4x4 column-major matrix. matrix!( ColumnMatrix4 : Vector4[x[x,y,z,w]=0,y[x,y,z,w]=1,z[x,y,z,w]=2,w[x,y,z,w]=3] = (4, 4)); turn!( ColumnMatrix4 : Vector4[x[x,y,z,w],y[x,y,z,w],z[x,y,z,w],w[x,y,z,w]] = RowMatrix4 ); mint-0.5.5/src/rotation.rs010064400007650000024000000067241364510454400137220ustar0000000000000000use core::marker::PhantomData; use vector::Vector3; /// Standard quaternion represented by the scalar and vector parts. /// Useful for representing rotation in 3D space. /// Corresponds to a right-handed rotation matrix. #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] #[repr(C)] pub struct Quaternion { /// Vector part of a quaternion. pub v: Vector3, /// Scalar part of a quaternion. pub s: T, } impl From<[T; 4]> for Quaternion { fn from([x, y, z, s]: [T; 4]) -> Self { Quaternion { s, v: Vector3::from([x, y, z]), } } } impl Into<[T; 4]> for Quaternion { fn into(self) -> [T; 4] { [self.v.x, self.v.y, self.v.z, self.s] } } impl AsRef<[T; 4]> for Quaternion { fn as_ref(&self) -> &[T; 4] { unsafe { ::core::mem::transmute(self) } } } /// Abstract set of Euler angles in 3D space. The basis of angles /// is defined by the generic parameter `B`. /// /// Note: there are multiple notations of Euler angles. They are /// split in two groups: /// - intrinsic (also known as "Tait-Bryan angles"): rotate around local axis /// - extrinsic (also known as "Proper Euler angles"): rotate around world axis /// For each interpretation, different axis may be chosen in different order. #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] #[repr(C)] pub struct EulerAngles { /// First angle of rotation in range [-pi, pi] (_pitch_). pub a: T, /// Second angle of rotation around in range [-pi/2, pi/2] (_yaw_). pub b: T, /// Third angle of rotation in range [-pi, pi] (_roll_). pub c: T, /// Marker for the phantom basis. pub marker: PhantomData, } /// Intrinsic rotation around X, then Y, then Z axis. #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] pub enum IntraXYZ {} /// Intrinsic rotation around Z, then X, then Z axis. #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] pub enum IntraZXZ {} /// Intrinsic rotation around Z, then Y, then X axis. #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] pub enum IntraZYX {} /// Extrinsic rotation around X, then Y, then Z axis. #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] pub enum ExtraXYZ {} /// Extrinsic rotation around Z, then X, then Z axis. #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] pub enum ExtraZXZ {} /// Extrinsic rotation around Z, then Y, then X axis. #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] pub enum ExtraZYX {} impl From<[T; 3]> for EulerAngles { fn from([a, b, c]: [T; 3]) -> Self { EulerAngles { a, b, c, marker: PhantomData, } } } impl Into<[T; 3]> for EulerAngles { fn into(self) -> [T; 3] { [self.a, self.b, self.c] } } macro_rules! reverse { ($from:ident -> $to:ident) => { impl From> for EulerAngles { fn from(other: EulerAngles) -> Self { EulerAngles { a: other.c, b: other.b, c: other.a, marker: PhantomData, } } } }; ($from:ident <-> $to:ident) => { reverse!($from -> $to); reverse!($to -> $from); }; } reverse!(IntraXYZ <-> ExtraZYX); reverse!(IntraZXZ <-> ExtraZXZ); reverse!(IntraZYX <-> ExtraXYZ); mint-0.5.5/src/vector.rs010064400007650000024000000036721364510454400133640ustar0000000000000000macro_rules! vec { ($name:ident [ $($field:ident),* ] = $fixed:ty) => { #[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Eq, Ord)] #[repr(C)] #[allow(missing_docs)] //TODO: actually have docs pub struct $name { $( pub $field : T, )* } impl From<$fixed> for $name { fn from([$($field),*]: $fixed) -> Self { $name { $( $field, )* } } } impl Into<$fixed> for $name { fn into(self) -> $fixed { [$( self.$field.into() ),*] } } impl AsRef<$fixed> for $name { fn as_ref(&self) -> &$fixed { unsafe { ::core::mem::transmute(self) } } } impl $name { #[allow(missing_docs)] pub fn from_slice(slice: &[T]) -> Self { let mut iter = slice.iter(); $name { $( $field: iter .next() .expect(&concat!("Missing ", stringify!($field), "-axis in slice.")) .clone() ),* } } } } } macro_rules! from { ($name:ident [ $($field:ident),* ] = $other:ident) => { impl From<$other> for $name { fn from(v: $other) -> Self { $name { $( $field: v.$field, )* } } } } } vec!( Vector2 [x, y] = [T; 2] ); from!( Vector2 [x,y] = Point2 ); vec!( Vector3 [x, y, z] = [T; 3] ); from!( Vector3 [x,y,z] = Point3 ); vec!( Vector4 [x, y, z, w] = [T; 4] ); vec!( Point2 [x, y] = [T; 2] ); from!( Point2 [x,y] = Vector2 ); vec!( Point3 [x, y, z] = [T; 3] ); from!( Point3 [x,y,z] = Vector3 ); mint-0.5.5/tests/tests.rs010064400007650000024000000153131364510454400135720ustar0000000000000000extern crate mint; use mint::{ Vector2, Point2, Vector3, Point3, Vector4, Quaternion, EulerAngles, }; use mint::{ RowMatrix2, RowMatrix2x3, RowMatrix2x4, RowMatrix3x2, RowMatrix3, RowMatrix3x4, RowMatrix4x2, RowMatrix4x3, RowMatrix4, }; use mint::{ ColumnMatrix2, ColumnMatrix2x3, ColumnMatrix2x4, ColumnMatrix3x2, ColumnMatrix3, ColumnMatrix3x4, ColumnMatrix4x2, ColumnMatrix4x3, ColumnMatrix4, }; macro_rules! transitive { ($name:ident [ $($field:ident = $value:expr),* ] = $fixed:ty) => ( let v1 = $name { $($field : $value,)* }; let a: $fixed = v1.into(); let v2 = $name::from(a); assert_eq!(v1, v2); ); ($name:ident [ $($field:ident = $value:expr),* ] = ref $fixed:ty) => ( transitive!($name [ $($field = $value),* ] = $fixed); let v1 = $name { $($field : $value,)* }; let a: $fixed = v1.into(); assert_eq!(AsRef::<$fixed>::as_ref(&v1), &a); ); } macro_rules! matrix_transitive { ($name:ident $vecType:ident[ $($field:ident = $value:expr),* ] = ($inner:expr, $outer:expr) : $elt:ty) => ( transitive!($name [ $($field = $vecType::from($value)),*] = ref [[$elt; $inner]; $outer]); transitive!($name [ $($field = $vecType::from($value)),*] = ref [$elt; $inner * $outer]); ) } macro_rules! turn { ($name1:ident [$($value1:expr),*] = $name2:ident [$($value2:expr),*]) => ( let transposed = [$($value2),*]; let m1 = $name1::from([$($value1),*]); let m2: $name2<_> = m1.into(); assert_eq!(m1, $name1::from(m2)); assert_eq!(m2, $name2::from(transposed)); ) } #[test] fn vector() { transitive!(Vector2 [x=1, y=3] = ref [i32; 2]); transitive!(Vector3 [x=1, y=3, z=5] = ref [i32; 3]); transitive!(Vector4 [x=1, y=3, z=5, w=7] = ref [i32; 4]); transitive!(Point2 [x=1, y=3] = ref [i32; 2]); transitive!(Point3 [x=1, y=3, z=5] = ref [i32; 3]); // Translation Vector <-> Point transitive!(Point2 [x=1, y=3] = Vector2); transitive!(Point3 [x=1, y=3, z=5] = Vector3); } #[test] fn rotation() { transitive!(Quaternion [s=1, v=Vector3{x: 1, y: 3, z: 5}] = [i32; 4]); // EulerAngles let a1: [i32; 3] = [1, 3, 5]; let e: EulerAngles<_, mint::ExtraXYZ> = EulerAngles::from(a1); let a2: [i32; 3] = e.into(); assert_eq!(a1, a2); } #[test] fn row_matrix() { matrix_transitive!(RowMatrix2 Vector2[ x=[1,2], y=[3,4]] = (2, 2): i32); matrix_transitive!(RowMatrix2x3 Vector3[ x=[1,2,3], y=[4,5,6]] = (3, 2): i32); matrix_transitive!(RowMatrix2x4 Vector4[ x=[1,2,3,4], y=[5,6,7,8]] = (4, 2): i32); matrix_transitive!(RowMatrix3x2 Vector2[ x=[1,2], y=[3,4], z=[5,6]] = (2, 3): i32); matrix_transitive!(RowMatrix3 Vector3[ x=[1,2,3], y=[4,5,6], z=[7,8,9]] = (3, 3): i32); matrix_transitive!(RowMatrix3x4 Vector4[ x=[1,2,3,4], y=[5,6,7,8], z=[9,10,11,12]] = (4, 3): i32); matrix_transitive!(RowMatrix4x2 Vector2[ x=[1,2], y=[3,4], z=[5,6], w=[7,8]] = (2, 4): i32); matrix_transitive!(RowMatrix4x3 Vector3[ x=[1,2,3], y=[4,5,6], z=[7,8,9], w=[10,11,12]] = (3, 4): i32); matrix_transitive!(RowMatrix4 Vector4[ x=[1,2,3,4], y=[5,6,7,8], z=[9,10,11,12], w=[13,14,15,16]] = (4, 4): i32); } #[test] fn column_matrix() { matrix_transitive!(ColumnMatrix2 Vector2[ x=[1,2], y=[3,4]] = (2, 2): i32); matrix_transitive!(ColumnMatrix2x3 Vector2[ x=[1,2], y=[3,4], z=[5,6]] = (2, 3): i32); matrix_transitive!(ColumnMatrix2x4 Vector2[ x=[1,2], y=[3,4], z=[5,6], w=[7,8]] = (2, 4): i32); matrix_transitive!(ColumnMatrix3x2 Vector3[ x=[1,2,3], y=[4,5,6]] = (3, 2): i32); matrix_transitive!(ColumnMatrix3 Vector3[ x=[1,2,3], y=[4,5,6], z=[7,8,9]] = (3, 3): i32); matrix_transitive!(ColumnMatrix3x4 Vector3[ x=[1,2,3], y=[4,5,6], z=[7,8,9], w=[10,11,12]] = (3, 4): i32); matrix_transitive!(ColumnMatrix4x2 Vector4[ x=[1,2,3,4], y=[5,6,7,8]] = (4, 2): i32); matrix_transitive!(ColumnMatrix4x3 Vector4[ x=[1,2,3,4], y=[5,6,7,8], z=[9,10,11,12]] = (4, 3): i32); matrix_transitive!(ColumnMatrix4 Vector4[ x=[1,2,3,4], y=[5,6,7,8], z=[9,10,11,12], w=[13,14,15,16]] = (4, 4): i32); } #[test] fn turn() { turn!(RowMatrix2 [ [1,2], [3,4]] = ColumnMatrix2 [ [1,3], [2,4]]); turn!(RowMatrix2x3 [ [1,3,5], [2,4,6]] = ColumnMatrix2x3 [ [1,2], [3,4], [5,6]]); turn!(RowMatrix2x4 [ [1,3,5,7], [2,4,6,8]] = ColumnMatrix2x4 [ [1,2], [3,4], [5,6], [7,8]]); turn!(RowMatrix3x2 [ [1,2], [3,4], [5,6]] = ColumnMatrix3x2 [ [1,3,5], [2,4,6]]); turn!(RowMatrix3 [ [1,2,3], [4,5,6], [7,8,9]] = ColumnMatrix3 [ [1,4,7], [2,5,8], [3,6,9]]); turn!(RowMatrix3x4 [ [1,4,7,10], [2,5,8,11], [3,6,9,12]] = ColumnMatrix3x4 [ [1,2,3], [4,5,6], [7,8,9], [10,11,12]]); turn!(RowMatrix4x2 [ [1,2], [3,4], [5,6], [7,8]] = ColumnMatrix4x2 [ [1,3,5,7], [2,4,6,8]]); turn!(RowMatrix4x3 [ [1,2,3], [4,5,6], [7,8,9], [10,11,12]] = ColumnMatrix4x3 [ [1,4,7,10], [2,5,8,11], [3,6,9,12]]); turn!(RowMatrix4 [ [1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]] = ColumnMatrix4 [ [1,5,9,13], [2,6,10,14], [3,7,11,15], [4,8,12,16]]); } #[test] fn vector_from_slice_success() { let v = Vector3::from_slice(&[0.0f32, 1.0, 2.0, 3.0]); assert_eq!(v, Vector3 { x: 0.0, y: 1.0, z: 2.0} ); } #[test] #[should_panic(expected = "Missing y-axis in slice.")] fn vector_from_slice_fail() { let _ = Vector4::from_slice(&[0.0]); } #[test] fn quaternion_layout() { let q = Quaternion { v: Vector3::from([0, 1, 2]), s: 3, }; let expected = [0, 1, 2, 3]; let a: [i32; 4] = q.into(); assert_eq!(a, expected); let b: &[i32; 4] = q.as_ref(); assert_eq!(b, &expected); let c: [i32; 4] = unsafe { core::mem::transmute(q) }; assert_eq!(c, expected); }mint-0.5.5/.cargo_vcs_info.json0000644000000001121364514757000121160ustar00{ "git": { "sha1": "b9048007a002de3a0a1e9ebb36daa52c090d5f46" } }