Skip to content

Commit 164808e

Browse files
authored
Quaternion memory layout changed to [x, y, z, w] (#500)
The `From` and `Into` impls for `[S; 4]` and `(S, S, S, S)` have been changed accordingly. This is consistent with other libraries like glm, nalgebra, and glam, as well as the glTF spec. Note that the `Quaternion::new` constructor has **not** yet been updated.
1 parent a691de8 commit 164808e

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1212
default_fn! macro to reduce code duplication and complexity. Currently
1313
only needed for non-functional SIMD feature.
1414
- Refactored SIMD code into separate source files. See README.md for details.
15+
- **Breaking**: Quaternion memory layout changed to `[x, y, z, w]`. The
16+
`From` and `Into` impls for `[S; 4]` and `(S, S, S, S)` have been changed
17+
accordingly.
18+
1519

1620
### Added
1721

src/quaternion.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ use mint;
4646
#[derive(Copy, Clone, Debug, PartialEq)]
4747
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4848
pub struct Quaternion<S> {
49-
/// The scalar part of the quaternion.
50-
pub s: S,
5149
/// The vector part of the quaternion.
5250
pub v: Vector3<S>,
51+
/// The scalar part of the quaternion.
52+
pub s: S,
5353
}
5454

5555
impl<S> Quaternion<S> {
@@ -542,7 +542,7 @@ impl<S: BaseFloat> Into<[S; 4]> for Quaternion<S> {
542542
#[inline]
543543
fn into(self) -> [S; 4] {
544544
match self.into() {
545-
(w, xi, yj, zk) => [w, xi, yj, zk],
545+
(xi, yj, zk, w) => [xi, yj, zk, w],
546546
}
547547
}
548548
}
@@ -564,7 +564,7 @@ impl<S: BaseFloat> AsMut<[S; 4]> for Quaternion<S> {
564564
impl<S: BaseFloat> From<[S; 4]> for Quaternion<S> {
565565
#[inline]
566566
fn from(v: [S; 4]) -> Quaternion<S> {
567-
Quaternion::new(v[0], v[1], v[2], v[3])
567+
Quaternion::new(v[3], v[0], v[1], v[2])
568568
}
569569
}
570570

@@ -589,7 +589,7 @@ impl<S: BaseFloat> Into<(S, S, S, S)> for Quaternion<S> {
589589
Quaternion {
590590
s,
591591
v: Vector3 { x, y, z },
592-
} => (s, x, y, z),
592+
} => (x, y, z, s),
593593
}
594594
}
595595
}
@@ -612,7 +612,7 @@ impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S> {
612612
#[inline]
613613
fn from(v: (S, S, S, S)) -> Quaternion<S> {
614614
match v {
615-
(w, xi, yj, zk) => Quaternion::new(w, xi, yj, zk),
615+
(xi, yj, zk, w) => Quaternion::new(w, xi, yj, zk),
616616
}
617617
}
618618
}
@@ -698,12 +698,12 @@ mod tests {
698698
use vector::*;
699699

700700
const QUATERNION: Quaternion<f32> = Quaternion {
701-
s: 1.0,
702701
v: Vector3 {
703-
x: 2.0,
704-
y: 3.0,
705-
z: 4.0,
702+
x: 1.0,
703+
y: 2.0,
704+
z: 3.0,
706705
},
706+
s: 4.0,
707707
};
708708

709709
#[test]

0 commit comments

Comments
 (0)