Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/bivec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,21 @@ macro_rules! bivec3s {
#[repr(C)]
pub struct $bn {
pub xy: $t,
pub xz: $t,
pub zx: $t,
pub yz: $t,
}

impl EqualsEps for $bn {
fn eq_eps(self, other: Self) -> bool {
self.xy.eq_eps(other.xy) && self.xz.eq_eps(other.xz) && self.yz.eq_eps(other.yz)
self.xy.eq_eps(other.xy) && self.zx.eq_eps(other.zx) && self.yz.eq_eps(other.yz)
}
}

impl $bn {
#[inline]
pub const fn new(xy: $t, xz: $t, yz: $t) -> Self {
pub const fn new(xy: $t, zx: $t, yz: $t) -> Self {
Self {
xy, xz, yz
xy, zx, yz
}
}

Expand All @@ -334,7 +334,7 @@ macro_rules! bivec3s {
/// normalized 'axis vector'
#[inline]
pub fn from_normalized_axis(v: $vt) -> Self {
Self::new(v.z, -v.y, v.x)
Self::new(v.z, v.y, v.x)
}

#[inline]
Expand All @@ -343,7 +343,7 @@ macro_rules! bivec3s {
}

#[inline]
pub fn unit_xz() -> Self {
pub fn unit_zx() -> Self {
Self::new($t::splat(0.0), $t::splat(1.0), $t::splat(0.0))
}

Expand All @@ -354,7 +354,7 @@ macro_rules! bivec3s {

#[inline]
pub fn mag_sq(&self) -> $t {
(self.xy * self.xy) + (self.xz * self.xz) + (self.yz * self.yz)
(self.xy * self.xy) + (self.zx * self.zx) + (self.yz * self.yz)
}

#[inline]
Expand All @@ -366,7 +366,7 @@ macro_rules! bivec3s {
pub fn normalize(&mut self) {
let mag = self.mag();
self.xy /= mag;
self.xz /= mag;
self.zx /= mag;
self.yz /= mag;
}

Expand All @@ -380,7 +380,7 @@ macro_rules! bivec3s {

#[inline]
pub fn dot(&self, rhs: Self) -> $t {
(self.xy * rhs.xy) + (self.xz * rhs.xz) + (self.yz * rhs.yz)
(self.xy * rhs.xy) + (self.zx * rhs.zx) + (self.yz * rhs.yz)
}

#[inline]
Expand Down Expand Up @@ -463,7 +463,7 @@ macro_rules! bivec3s {
#[inline]
fn add_assign(&mut self, rhs: $bn) {
self.xy += rhs.xy;
self.xz += rhs.xz;
self.zx += rhs.zx;
self.yz += rhs.yz;
}
}
Expand All @@ -481,7 +481,7 @@ macro_rules! bivec3s {
#[inline]
fn sub_assign(&mut self, rhs: $bn) {
self.xy -= rhs.xy;
self.xz -= rhs.xz;
self.zx -= rhs.zx;
self.yz -= rhs.yz;
}
}
Expand Down Expand Up @@ -517,7 +517,7 @@ macro_rules! bivec3s {
#[inline]
fn mul_assign(&mut self, rhs: Self) {
self.xy *= rhs.xy;
self.xz *= rhs.xz;
self.zx *= rhs.zx;
self.yz *= rhs.yz;
}
}
Expand All @@ -526,7 +526,7 @@ macro_rules! bivec3s {
#[inline]
fn mul_assign(&mut self, rhs: $t) {
self.xy *= rhs;
self.xz *= rhs;
self.zx *= rhs;
self.yz *= rhs;
}
}
Expand All @@ -553,7 +553,7 @@ macro_rules! bivec3s {
#[inline]
fn div_assign(&mut self, rhs: $bn) {
self.xy /= rhs.xy;
self.xz /= rhs.xz;
self.zx /= rhs.zx;
self.yz /= rhs.yz;
}
}
Expand All @@ -562,7 +562,7 @@ macro_rules! bivec3s {
#[inline]
fn div_assign(&mut self, rhs: $t) {
self.xy /= rhs;
self.xz /= rhs;
self.zx /= rhs;
self.yz /= rhs;
}
}
Expand All @@ -572,7 +572,7 @@ macro_rules! bivec3s {
#[inline]
fn neg(mut self) -> Self {
self.xy = -self.xy;
self.xz = -self.xz;
self.zx = -self.zx;
self.yz = -self.yz;
self
}
Expand Down
2 changes: 1 addition & 1 deletion src/impl_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ impl Serialize for Bivec3 {
{
let mut state = serializer.serialize_struct("Bivec3", 3)?;
state.serialize_field("xy", &self.xy)?;
state.serialize_field("xz", &self.xz)?;
state.serialize_field("zx", &self.zx)?;
state.serialize_field("yz", &self.yz)?;
state.end()
}
Expand Down
34 changes: 32 additions & 2 deletions src/interp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ macro_rules! impl_slerp_rotor3 {

n.s = (c * self.s) + (s * v2.s);
n.bv.xy = (c * self.bv.xy) + (s * v2.bv.xy);
n.bv.xz = (c * self.bv.xz) + (s * v2.bv.xz);
n.bv.zx = (c * self.bv.zx) + (s * v2.bv.zx);
n.bv.yz = (c * self.bv.yz) + (s * v2.bv.yz);

n
Expand Down Expand Up @@ -151,7 +151,7 @@ macro_rules! impl_slerp_rotor3_wide {

n.s = (c * self.s) + (s * v2.s);
n.bv.xy = (c * self.bv.xy) + (s * v2.bv.xy);
n.bv.xz = (c * self.bv.xz) + (s * v2.bv.xz);
n.bv.zx = (c * self.bv.zx) + (s * v2.bv.zx);
n.bv.yz = (c * self.bv.yz) + (s * v2.bv.yz);

n
Expand Down Expand Up @@ -218,3 +218,33 @@ impl_slerp_gen!(
f64x2 => (DVec2x2, DVec3x2, DVec4x2, DBivec2x2, DBivec3x2, DRotor2x2),
f64x4 => (DVec2x4, DVec3x4, DVec4x4, DBivec2x4, DBivec3x4, DRotor2x4)
);

#[cfg(test)]
mod test {
use super::*;
use crate::util::EqualsEps;
use std::f32::consts::*;
#[test]
pub fn slerp_in_xy_plane() {
let rotation = Rotor3::from_rotation_xy(2. * FRAC_PI_3);

// Expected to be a rotation by angle PI/6
let interpolated = Rotor3::identity().slerp(rotation, 1. / 4.);

let rotated = Vec3::unit_x().rotated_by(interpolated);
let expected = Vec3::new(3f32.sqrt() / 2., 0.5, 0.);
assert!(rotated.eq_eps(expected))
}

#[test]
pub fn slerp_in_zx_plane() {
let rotation = Rotor3::from_rotation_zx(2. * FRAC_PI_3);

// Expected to be a rotation by angle PI/6
let interpolated = Rotor3::identity().slerp(rotation, 1. / 4.);

let rotated = Vec3::unit_z().rotated_by(interpolated);
let expected = Vec3::new(0.5, 0., 3f32.sqrt() / 2.);
assert!(rotated.eq_eps(expected))
}
}
86 changes: 79 additions & 7 deletions src/mat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,17 +963,17 @@ macro_rules! impl_mat3 {
s.copysign(self[2][1] - self[1][2])
};

let xz = {
let zx = {
let s = ($t::splat(1.0) - self[0][0] + self[1][1] - self[2][2]).max($t::splat(0.0)).sqrt() * $t::splat(0.5);
s.copysign(self[2][0] - self[0][2])
s.copysign(self[0][2] - self[2][0])
};

let xy = {
let s = ($t::splat(1.0) - self[0][0] - self[1][1] + self[2][2]).max($t::splat(0.0)).sqrt() * $t::splat(0.5);
s.copysign(self[1][0] - self[0][1])
};

$rt::new(w, $bt::new(xy, xz, yz))
$rt::new(w, $bt::new(xy, zx, yz))
}
})+
}
Expand Down Expand Up @@ -1001,17 +1001,17 @@ macro_rules! impl_mat3_wide {
s.flip_signs(self[2][1] - self[1][2])
};

let xz = {
let zx = {
let s = ($t::splat(1.0) - self[0][0] + self[1][1] - self[2][2]).max($t::splat(0.0)).sqrt() * $t::splat(0.5);
s.flip_signs(self[2][0] - self[0][2])
s.flip_signs(self[0][2] - self[2][0])
};

let xy = {
let s = ($t::splat(1.0) - self[0][0] - self[1][1] + self[2][2]).max($t::splat(0.0)).sqrt() * $t::splat(0.5);
s.flip_signs(self[1][0] - self[0][1])
};

$rt::new(w, $bt::new(xy, xz, yz))
$rt::new(w, $bt::new(xy, zx, yz))
}
})+
}
Expand Down Expand Up @@ -1890,7 +1890,79 @@ mod test {
let iso = Isometry3::new(c, r_ab);
let iso_mat4 = iso.into_homogeneous_matrix();
let iso_ = iso_mat4.into_isometry();
println!("{:#?}, {:#?}", r_ab.into_matrix(), iso_mat4);
println!("{:#?}, {:#?}", r_ab, iso_.rotation);
assert!(iso_.translation.eq_eps(c));
assert!(iso_.rotation.eq_eps(r_ab));
assert!(a.rotated_by(iso_.rotation).eq_eps(b));
}

#[test]
pub fn matrix_to_rotor_roundtrip() {
let a = Vec3::new(1.0, 2.0, -5.0).normalized();
let b = Vec3::new(1.0, 1.0, 1.0).normalized();
let r_ab = Rotor3::from_rotation_between(a, b);
assert!(a.rotated_by(r_ab).eq_eps(b));
let mat_ab = r_ab.into_matrix();
assert!((mat_ab * a).eq_eps(b));

let r_ab_2 = mat_ab.into_rotor3();
assert!(a.rotated_by(r_ab_2).eq_eps(b));
}

#[test]
pub fn rotation_plane_xy() {
use std::f32::consts::*;
let matrix = Mat3::from_rotation_z(FRAC_PI_3);
let rotated = matrix * Vec3::unit_x();
let expected = Vec3::new(0.5, 3f32.sqrt() / 2., 0.);
assert!(rotated.eq_eps(expected))
}

#[test]
pub fn rotation_plane_zx() {
use std::f32::consts::*;
let matrix = Mat3::from_rotation_y(FRAC_PI_3);
let rotated = matrix * Vec3::unit_z();
let expected = Vec3::new(3f32.sqrt() / 2., 0., 0.5);
assert!(rotated.eq_eps(expected))
}

#[test]
pub fn rotation_plane_yz() {
use std::f32::consts::*;
let matrix = Mat3::from_rotation_x(FRAC_PI_3);
let rotated = matrix * Vec3::unit_y();
let expected = Vec3::new(0., 0.5, 3f32.sqrt() / 2.);
assert!(rotated.eq_eps(expected))
}

#[test]
pub fn rotation_plane_xy_by_rotor() {
use std::f32::consts::*;
let matrix = Mat3::from_rotation_z(FRAC_PI_3);
let rotor = matrix.into_rotor3();
let rotated = Vec3::unit_x().rotated_by(rotor);
let expected = Vec3::new(0.5, 3f32.sqrt() / 2., 0.);
assert!(rotated.eq_eps(expected))
}

#[test]
pub fn rotation_plane_zx_by_rotor() {
use std::f32::consts::*;
let matrix = Mat3::from_rotation_y(FRAC_PI_3);
let rotor = matrix.into_rotor3();
let rotated = Vec3::unit_z().rotated_by(rotor);
let expected = Vec3::new(3f32.sqrt() / 2., 0., 0.5);
assert!(rotated.eq_eps(expected))
}

#[test]
pub fn rotation_plane_yz_by_rotor() {
use std::f32::consts::*;
let matrix = Mat3::from_rotation_x(FRAC_PI_3);
let rotor = matrix.into_rotor3();
let rotated = Vec3::unit_y().rotated_by(rotor);
let expected = Vec3::new(0., 0.5, 3f32.sqrt() / 2.);
assert!(rotated.eq_eps(expected))
}
}
Loading