diff --git a/src/euler.rs b/src/euler.rs index f175218..f281e3d 100644 --- a/src/euler.rs +++ b/src/euler.rs @@ -78,7 +78,7 @@ use num::BaseFloat; #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct Euler { +pub struct Euler { /// The angle to apply around the _x_ axis. Also known at the _pitch_. pub x: A, /// The angle to apply around the _y_ axis. Also known at the _yaw_. @@ -87,7 +87,7 @@ pub struct Euler { pub z: A, } -impl Euler { +impl Euler { /// Construct a set of euler angles. /// /// # Arguments @@ -95,7 +95,7 @@ impl Euler { /// * `x` - The angle to apply around the _x_ axis. Also known at the _pitch_. /// * `y` - The angle to apply around the _y_ axis. Also known at the _yaw_. /// * `z` - The angle to apply around the _z_ axis. Also known at the _roll_. - pub fn new(x: A, y: A, z: A) -> Euler { + pub const fn new(x: A, y: A, z: A) -> Euler { Euler { x: x, y: y, z: z } } } diff --git a/src/matrix.rs b/src/matrix.rs index 8236d81..3219b1b 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -81,19 +81,21 @@ pub struct Matrix4 { pub w: Vector4, } -impl Matrix2 { +impl Matrix2 { /// Create a new matrix, providing values for each index. #[inline] - pub fn new(c0r0: S, c0r1: S, c1r0: S, c1r1: S) -> Matrix2 { + pub const fn new(c0r0: S, c0r1: S, c1r0: S, c1r1: S) -> Matrix2 { Matrix2::from_cols(Vector2::new(c0r0, c0r1), Vector2::new(c1r0, c1r1)) } /// Create a new matrix, providing columns. #[inline] - pub fn from_cols(c0: Vector2, c1: Vector2) -> Matrix2 { + pub const fn from_cols(c0: Vector2, c1: Vector2) -> Matrix2 { Matrix2 { x: c0, y: c1 } } +} +impl Matrix2 { /// Create a transformation matrix that will cause a vector to point at /// `dir`, using `up` for orientation. pub fn look_at(dir: Vector2, up: Vector2) -> Matrix2 { @@ -114,11 +116,11 @@ impl Matrix2 { } } -impl Matrix3 { +impl Matrix3 { /// Create a new matrix, providing values for each index. #[inline] #[cfg_attr(rustfmt, rustfmt_skip)] - pub fn new( + pub const fn new( c0r0:S, c0r1:S, c0r2:S, c1r0:S, c1r1:S, c1r2:S, c2r0:S, c2r1:S, c2r2:S, @@ -132,14 +134,16 @@ impl Matrix3 { /// Create a new matrix, providing columns. #[inline] - pub fn from_cols(c0: Vector3, c1: Vector3, c2: Vector3) -> Matrix3 { + pub const fn from_cols(c0: Vector3, c1: Vector3, c2: Vector3) -> Matrix3 { Matrix3 { x: c0, y: c1, z: c2, } } +} +impl Matrix3 { /// Create a rotation matrix that will cause a vector to point at /// `dir`, using `up` for orientation. pub fn look_at(dir: Vector3, up: Vector3) -> Matrix3 { @@ -218,11 +222,11 @@ impl Matrix3 { } } -impl Matrix4 { +impl Matrix4 { /// Create a new matrix, providing values for each index. #[inline] #[cfg_attr(rustfmt, rustfmt_skip)] - pub fn new( + pub const fn new( c0r0: S, c0r1: S, c0r2: S, c0r3: S, c1r0: S, c1r1: S, c1r2: S, c1r3: S, c2r0: S, c2r1: S, c2r2: S, c2r3: S, @@ -238,7 +242,7 @@ impl Matrix4 { /// Create a new matrix, providing columns. #[inline] - pub fn from_cols(c0: Vector4, c1: Vector4, c2: Vector4, c3: Vector4) -> Matrix4 { + pub const fn from_cols(c0: Vector4, c1: Vector4, c2: Vector4, c3: Vector4) -> Matrix4 { Matrix4 { x: c0, y: c1, @@ -246,7 +250,9 @@ impl Matrix4 { w: c3, } } +} +impl Matrix4 { /// Create a homogeneous transformation matrix from a translation vector. #[inline] pub fn from_translation(v: Vector3) -> Matrix4 { diff --git a/src/point.rs b/src/point.rs index aef5e0c..a50c92f 100644 --- a/src/point.rs +++ b/src/point.rs @@ -82,7 +82,7 @@ macro_rules! impl_point { impl $PointN { /// Construct a new point, using the provided values. #[inline] - pub fn new($($field: S),+) -> $PointN { + pub const fn new($($field: S),+) -> $PointN { $PointN { $($field: $field),+ } } diff --git a/src/quaternion.rs b/src/quaternion.rs index e5a1315..ff4ba4d 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -76,20 +76,22 @@ impl Into for Quaternion { } } -impl Quaternion { +impl Quaternion { /// Construct a new quaternion from one scalar component and three /// imaginary components. #[inline] - pub fn new(w: S, xi: S, yj: S, zk: S) -> Quaternion { + pub const fn new(w: S, xi: S, yj: S, zk: S) -> Quaternion { Quaternion::from_sv(w, Vector3::new(xi, yj, zk)) } /// Construct a new quaternion from a scalar and a vector. #[inline] - pub fn from_sv(s: S, v: Vector3) -> Quaternion { + pub const fn from_sv(s: S, v: Vector3) -> Quaternion { Quaternion { s: s, v: v } } +} +impl Quaternion { /// Construct a new quaternion as a closest arc between two vectors /// /// Return the closest rotation that turns `src` vector into `dst`. diff --git a/src/vector.rs b/src/vector.rs index 9acc7b3..16b31d1 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -99,7 +99,7 @@ macro_rules! impl_vector { impl $VectorN { /// Construct a new vector, using the provided values. #[inline] - pub fn new($($field: S),+) -> $VectorN { + pub const fn new($($field: S),+) -> $VectorN { $VectorN { $($field: $field),+ } } @@ -115,7 +115,7 @@ macro_rules! impl_vector { /// The short constructor. #[inline] - pub fn $constructor($($field: S),+) -> $VectorN { + pub const fn $constructor($($field: S),+) -> $VectorN { $VectorN::new($($field),+) } @@ -358,7 +358,7 @@ macro_rules! impl_vector_default { impl $VectorN { /// Construct a new vector, using the provided values. #[inline] - pub fn new($($field: S),+) -> $VectorN { + pub const fn new($($field: S),+) -> $VectorN { $VectorN { $($field: $field),+ } } }