Merge #475
475: Declare vector constructors to be const r=kvark a=nstoddard This makes it easier to create vectors in constants. Co-authored-by: Nathan Stoddard <nstoddard@users.noreply.github.com>
This commit is contained in:
commit
649fef941b
5 changed files with 27 additions and 19 deletions
|
@ -78,7 +78,7 @@ use num::BaseFloat;
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub struct Euler<A: Angle> {
|
pub struct Euler<A> {
|
||||||
/// The angle to apply around the _x_ axis. Also known at the _pitch_.
|
/// The angle to apply around the _x_ axis. Also known at the _pitch_.
|
||||||
pub x: A,
|
pub x: A,
|
||||||
/// The angle to apply around the _y_ axis. Also known at the _yaw_.
|
/// The angle to apply around the _y_ axis. Also known at the _yaw_.
|
||||||
|
@ -87,7 +87,7 @@ pub struct Euler<A: Angle> {
|
||||||
pub z: A,
|
pub z: A,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Angle> Euler<A> {
|
impl<A> Euler<A> {
|
||||||
/// Construct a set of euler angles.
|
/// Construct a set of euler angles.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -95,7 +95,7 @@ impl<A: Angle> Euler<A> {
|
||||||
/// * `x` - The angle to apply around the _x_ axis. Also known at the _pitch_.
|
/// * `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_.
|
/// * `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_.
|
/// * `z` - The angle to apply around the _z_ axis. Also known at the _roll_.
|
||||||
pub fn new(x: A, y: A, z: A) -> Euler<A> {
|
pub const fn new(x: A, y: A, z: A) -> Euler<A> {
|
||||||
Euler { x: x, y: y, z: z }
|
Euler { x: x, y: y, z: z }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,19 +81,21 @@ pub struct Matrix4<S> {
|
||||||
pub w: Vector4<S>,
|
pub w: Vector4<S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> Matrix2<S> {
|
impl<S> Matrix2<S> {
|
||||||
/// Create a new matrix, providing values for each index.
|
/// Create a new matrix, providing values for each index.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(c0r0: S, c0r1: S, c1r0: S, c1r1: S) -> Matrix2<S> {
|
pub const fn new(c0r0: S, c0r1: S, c1r0: S, c1r1: S) -> Matrix2<S> {
|
||||||
Matrix2::from_cols(Vector2::new(c0r0, c0r1), Vector2::new(c1r0, c1r1))
|
Matrix2::from_cols(Vector2::new(c0r0, c0r1), Vector2::new(c1r0, c1r1))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new matrix, providing columns.
|
/// Create a new matrix, providing columns.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_cols(c0: Vector2<S>, c1: Vector2<S>) -> Matrix2<S> {
|
pub const fn from_cols(c0: Vector2<S>, c1: Vector2<S>) -> Matrix2<S> {
|
||||||
Matrix2 { x: c0, y: c1 }
|
Matrix2 { x: c0, y: c1 }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: BaseFloat> Matrix2<S> {
|
||||||
/// Create a transformation matrix that will cause a vector to point at
|
/// Create a transformation matrix that will cause a vector to point at
|
||||||
/// `dir`, using `up` for orientation.
|
/// `dir`, using `up` for orientation.
|
||||||
pub fn look_at(dir: Vector2<S>, up: Vector2<S>) -> Matrix2<S> {
|
pub fn look_at(dir: Vector2<S>, up: Vector2<S>) -> Matrix2<S> {
|
||||||
|
@ -114,11 +116,11 @@ impl<S: BaseFloat> Matrix2<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> Matrix3<S> {
|
impl<S> Matrix3<S> {
|
||||||
/// Create a new matrix, providing values for each index.
|
/// Create a new matrix, providing values for each index.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
pub fn new(
|
pub const fn new(
|
||||||
c0r0:S, c0r1:S, c0r2:S,
|
c0r0:S, c0r1:S, c0r2:S,
|
||||||
c1r0:S, c1r1:S, c1r2:S,
|
c1r0:S, c1r1:S, c1r2:S,
|
||||||
c2r0:S, c2r1:S, c2r2:S,
|
c2r0:S, c2r1:S, c2r2:S,
|
||||||
|
@ -132,14 +134,16 @@ impl<S: BaseFloat> Matrix3<S> {
|
||||||
|
|
||||||
/// Create a new matrix, providing columns.
|
/// Create a new matrix, providing columns.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_cols(c0: Vector3<S>, c1: Vector3<S>, c2: Vector3<S>) -> Matrix3<S> {
|
pub const fn from_cols(c0: Vector3<S>, c1: Vector3<S>, c2: Vector3<S>) -> Matrix3<S> {
|
||||||
Matrix3 {
|
Matrix3 {
|
||||||
x: c0,
|
x: c0,
|
||||||
y: c1,
|
y: c1,
|
||||||
z: c2,
|
z: c2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: BaseFloat> Matrix3<S> {
|
||||||
/// Create a rotation matrix that will cause a vector to point at
|
/// Create a rotation matrix that will cause a vector to point at
|
||||||
/// `dir`, using `up` for orientation.
|
/// `dir`, using `up` for orientation.
|
||||||
pub fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
|
pub fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Matrix3<S> {
|
||||||
|
@ -218,11 +222,11 @@ impl<S: BaseFloat> Matrix3<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> Matrix4<S> {
|
impl<S> Matrix4<S> {
|
||||||
/// Create a new matrix, providing values for each index.
|
/// Create a new matrix, providing values for each index.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
pub fn new(
|
pub const fn new(
|
||||||
c0r0: S, c0r1: S, c0r2: S, c0r3: S,
|
c0r0: S, c0r1: S, c0r2: S, c0r3: S,
|
||||||
c1r0: S, c1r1: S, c1r2: S, c1r3: S,
|
c1r0: S, c1r1: S, c1r2: S, c1r3: S,
|
||||||
c2r0: S, c2r1: S, c2r2: S, c2r3: S,
|
c2r0: S, c2r1: S, c2r2: S, c2r3: S,
|
||||||
|
@ -238,7 +242,7 @@ impl<S: BaseFloat> Matrix4<S> {
|
||||||
|
|
||||||
/// Create a new matrix, providing columns.
|
/// Create a new matrix, providing columns.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_cols(c0: Vector4<S>, c1: Vector4<S>, c2: Vector4<S>, c3: Vector4<S>) -> Matrix4<S> {
|
pub const fn from_cols(c0: Vector4<S>, c1: Vector4<S>, c2: Vector4<S>, c3: Vector4<S>) -> Matrix4<S> {
|
||||||
Matrix4 {
|
Matrix4 {
|
||||||
x: c0,
|
x: c0,
|
||||||
y: c1,
|
y: c1,
|
||||||
|
@ -246,7 +250,9 @@ impl<S: BaseFloat> Matrix4<S> {
|
||||||
w: c3,
|
w: c3,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: BaseFloat> Matrix4<S> {
|
||||||
/// Create a homogeneous transformation matrix from a translation vector.
|
/// Create a homogeneous transformation matrix from a translation vector.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_translation(v: Vector3<S>) -> Matrix4<S> {
|
pub fn from_translation(v: Vector3<S>) -> Matrix4<S> {
|
||||||
|
|
|
@ -82,7 +82,7 @@ macro_rules! impl_point {
|
||||||
impl<S> $PointN<S> {
|
impl<S> $PointN<S> {
|
||||||
/// Construct a new point, using the provided values.
|
/// Construct a new point, using the provided values.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new($($field: S),+) -> $PointN<S> {
|
pub const fn new($($field: S),+) -> $PointN<S> {
|
||||||
$PointN { $($field: $field),+ }
|
$PointN { $($field: $field),+ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,20 +76,22 @@ impl Into<Simdf32x4> for Quaternion<f32> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> Quaternion<S> {
|
impl<S> Quaternion<S> {
|
||||||
/// Construct a new quaternion from one scalar component and three
|
/// Construct a new quaternion from one scalar component and three
|
||||||
/// imaginary components.
|
/// imaginary components.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(w: S, xi: S, yj: S, zk: S) -> Quaternion<S> {
|
pub const fn new(w: S, xi: S, yj: S, zk: S) -> Quaternion<S> {
|
||||||
Quaternion::from_sv(w, Vector3::new(xi, yj, zk))
|
Quaternion::from_sv(w, Vector3::new(xi, yj, zk))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a new quaternion from a scalar and a vector.
|
/// Construct a new quaternion from a scalar and a vector.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_sv(s: S, v: Vector3<S>) -> Quaternion<S> {
|
pub const fn from_sv(s: S, v: Vector3<S>) -> Quaternion<S> {
|
||||||
Quaternion { s: s, v: v }
|
Quaternion { s: s, v: v }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: BaseFloat> Quaternion<S> {
|
||||||
/// Construct a new quaternion as a closest arc between two vectors
|
/// Construct a new quaternion as a closest arc between two vectors
|
||||||
///
|
///
|
||||||
/// Return the closest rotation that turns `src` vector into `dst`.
|
/// Return the closest rotation that turns `src` vector into `dst`.
|
||||||
|
|
|
@ -99,7 +99,7 @@ macro_rules! impl_vector {
|
||||||
impl<S> $VectorN<S> {
|
impl<S> $VectorN<S> {
|
||||||
/// Construct a new vector, using the provided values.
|
/// Construct a new vector, using the provided values.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new($($field: S),+) -> $VectorN<S> {
|
pub const fn new($($field: S),+) -> $VectorN<S> {
|
||||||
$VectorN { $($field: $field),+ }
|
$VectorN { $($field: $field),+ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ macro_rules! impl_vector {
|
||||||
|
|
||||||
/// The short constructor.
|
/// The short constructor.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn $constructor<S>($($field: S),+) -> $VectorN<S> {
|
pub const fn $constructor<S>($($field: S),+) -> $VectorN<S> {
|
||||||
$VectorN::new($($field),+)
|
$VectorN::new($($field),+)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +358,7 @@ macro_rules! impl_vector_default {
|
||||||
impl<S> $VectorN<S> {
|
impl<S> $VectorN<S> {
|
||||||
/// Construct a new vector, using the provided values.
|
/// Construct a new vector, using the provided values.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new($($field: S),+) -> $VectorN<S> {
|
pub const fn new($($field: S),+) -> $VectorN<S> {
|
||||||
$VectorN { $($field: $field),+ }
|
$VectorN { $($field: $field),+ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue