Skip to content

Commit

Permalink
Cleanup and remove some duplicated rotations tests (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGorisse authored Feb 24, 2022
1 parent e8c4f20 commit fa553fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 92 deletions.
26 changes: 0 additions & 26 deletions src/commonTest/kotlin/dev/romainguy/kotlin/math/MatrixTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -339,32 +339,6 @@ class MatrixTest {
)
}

@Test
fun rotationEulerXYZ() {
assertArrayEquals(
Mat4(
Float4(0.9980f, 0.0529f, -0.0339f, 0f),
Float4(-0.0523f, 0.9984f, 0.0192f, 0f),
Float4(0.0349f, -0.0174f, 0.9992f, 0f),
Float4(0f, 0f, 0f, 1f)
).toFloatArray(),
rotation(Float3(1f, 2f, 3f), RotationsOrder.XYZ).toFloatArray()
)
}

@Test
fun rotationEulerZYX() {
assertArrayEquals(
Mat4(
Float4(0.9980f, 0.0523f, -0.0349f, 0f),
Float4(-0.0518f, 0.9985f, 0.0174f, 0f),
Float4(0.0358f, -0.0156f, 0.9992f, 0f),
Float4(0f, 0f, 0f, 1f)
).toFloatArray(),
rotation(Float3(1f, 2f, 3f), RotationsOrder.ZYX).toFloatArray()
)
}

@Test
fun eulerXYZRotation() {
assertArrayEquals(
Expand Down
92 changes: 26 additions & 66 deletions src/commonTest/kotlin/dev/romainguy/kotlin/math/QuaternionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,144 +23,104 @@ class QuaternionTest {
@Test
fun fromAxisAngle() {
MatrixTest.assertArrayEquals(
Quaternion(0.0093f, 0.0186f, 0.0280f, 0.9994f).toFloatArray(),
Quaternion.fromAxisAngle(Float3(1.0f, 2.0f, 3.0f), 4.0f).toFloatArray()
Quaternion(0.0093f, 0.0186f, 0.0280f, 0.9994f).toFloatArray(),
Quaternion.fromAxisAngle(Float3(1.0f, 2.0f, 3.0f), 4.0f).toFloatArray()
)
}

@Test
fun fromEulerXYZ() {
MatrixTest.assertArrayEquals(
Quaternion(0.009179f, 0.0172174f, 0.0263242f, 0.999463f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.XYZ).toFloatArray()
Quaternion(0.009179f, 0.0172174f, 0.0263242f, 0.999463f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.XYZ).toFloatArray()
)
}

@Test
fun fromEulerXZY() {
MatrixTest.assertArrayEquals(
Quaternion(0.0082654f, 0.0172174f, 0.0263242f, 0.999471f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.XZY).toFloatArray()
Quaternion(0.0082654f, 0.0172174f, 0.0263242f, 0.999471f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.XZY).toFloatArray()
)
}

@Test
fun fromEulerYXZ() {
MatrixTest.assertArrayEquals(
Quaternion(0.009179f, 0.0172174f, 0.0260197f, 0.999471f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.YXZ).toFloatArray()
Quaternion(0.009179f, 0.0172174f, 0.0260197f, 0.999471f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.YXZ).toFloatArray()
)
}

@Test
fun fromEulerYZX() {
MatrixTest.assertArrayEquals(
Quaternion(0.009179f, 0.0176742f, 0.0260197f, 0.999463f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.YZX).toFloatArray()
Quaternion(0.009179f, 0.0176742f, 0.0260197f, 0.999463f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.YZX).toFloatArray()
)
}

@Test
fun fromEulerZXY() {
MatrixTest.assertArrayEquals(
Quaternion(0.0082654f, 0.0176742f, 0.0263242f, 0.999463f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.ZXY).toFloatArray()
Quaternion(0.0082654f, 0.0176742f, 0.0263242f, 0.999463f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.ZXY).toFloatArray()
)
}

@Test
fun fromEulerZYX() {
MatrixTest.assertArrayEquals(
Quaternion(0.0082654f, 0.0176742f, 0.0260197f, 0.999471f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.ZYX).toFloatArray()
)
}

@Test
fun fromEulerXZY() {
MatrixTest.assertArrayEquals(
Quaternion(0.0082654f, 0.0172174f, 0.0263242f, 0.999471f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.XZY).toFloatArray()
)
}

@Test
fun fromEulerYXZ() {
MatrixTest.assertArrayEquals(
Quaternion(0.009179f, 0.0172174f, 0.0260197f, 0.999471f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.YXZ).toFloatArray()
)
}

@Test
fun fromEulerYZX() {
MatrixTest.assertArrayEquals(
Quaternion(0.009179f, 0.0176742f, 0.0260197f, 0.999463f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.YZX).toFloatArray()
)
}

@Test
fun fromEulerZXY() {
MatrixTest.assertArrayEquals(
Quaternion(0.0082654f, 0.0176742f, 0.0263242f, 0.999463f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.ZXY).toFloatArray()
)
}

@Test
fun fromEulerZYX() {
MatrixTest.assertArrayEquals(
Quaternion(0.0082654f, 0.0176742f, 0.0260197f, 0.999471f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.ZYX).toFloatArray()
Quaternion(0.0082654f, 0.0176742f, 0.0260197f, 0.999471f).toFloatArray(),
Quaternion.fromEuler(Float3(1.0f, 2.0f, 3.0f), RotationsOrder.ZYX).toFloatArray()
)
}

@Test
fun toEulerXYZ() {
MatrixTest.assertArrayEquals(
Float3(-63.4349488f, 41.8103164f, 169.6951532f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.XYZ).toFloatArray()
Float3(-63.4349488f, 41.8103164f, 169.6951532f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.XYZ).toFloatArray()
)
}

@Test
fun toEulerXZY() {
MatrixTest.assertArrayEquals(
Float3(109.6538245f, 137.7263108f, 7.6622561f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.XZY).toFloatArray()
Float3(109.6538245f, 137.7263108f, 7.6622561f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.XZY).toFloatArray()
)
}

@Test
fun toEulerYXZ() {
MatrixTest.assertArrayEquals(
Float3(-41.8103164f, 63.4349488f, 116.5650512f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.YXZ).toFloatArray()
Float3(-41.8103164f, 63.4349488f, 116.5650512f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.YXZ).toFloatArray()
)
}

@Test
fun toEulerYZX() {
MatrixTest.assertArrayEquals(
Float3(-116.5650512f, -169.6951532f, 41.8103164f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.YZX).toFloatArray()
Float3(-116.5650512f, -169.6951532f, 41.8103164f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.YZX).toFloatArray()
)
}

@Test
fun toEulerZXY() {
MatrixTest.assertArrayEquals(
Float3(68.9605309f, -21.8014099f, 158.1985901f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.ZXY).toFloatArray()
Float3(68.9605309f, -21.8014099f, 158.1985901f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.ZXY).toFloatArray()
)
}

@Test
fun toEulerZYX() {
MatrixTest.assertArrayEquals(
Float3(70.3461755f, -7.6622561f, 137.7263108f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.ZYX).toFloatArray()
Float3(70.3461755f, -7.6622561f, 137.7263108f).toFloatArray(),
eulerAngles(Quaternion(1.0f, 2.0f, 3.0f, 1.0f), RotationsOrder.ZYX).toFloatArray()
)
}
}

0 comments on commit fa553fa

Please sign in to comment.