lullaby/tests/math_util_test.cc
// This test feeds in random input values, and checks that the result satisfies
// the main invariant -- that the resulting axis-angle rotates v1 onto v2.
//
// This is not a stability or precision test.
This test feeds in random input values, and checks that the result satisfies
the main invariant -- that the resulting axis-angle rotates v1 onto v2.

This is not a stability or precision test.
This test feeds in random input values and checks that the result satisfies the main invariant -- that the resulting axis - angle rotates v1 onto v2 . This is not a stability or precision test .
TEST(GetSignedAngle, RandomInput) {
  RandomNumberGenerator rand(::testing::UnitTest::GetInstance()->random_seed());
  for (int i = 0; i < 100; ++i) {
    const mathfu::vec3 axis = RandomUnitVec3(&rand);
    const mathfu::vec3 v1 = RandomUnitVec3(&rand);
    const mathfu::vec3 v2 = RandomUnitVec3(&rand);
    if (std::fabs(mathfu::vec3::DotProduct(v1, v2)) < .2f ||
        std::fabs(mathfu::vec3::DotProduct(axis, v1)) < .2f ||
        std::fabs(mathfu::vec3::DotProduct(axis, v2)) < .2f) {
      continue;
    }
    const float angle = GetSignedAngle(v1, v2, axis);
    const mathfu::quat q = mathfu::quat::FromAngleAxis(angle, axis);
    const mathfu::vec3 projected_rotated_v1 =
        Project(q * v1, axis).Normalized();
    const mathfu::vec3 projected_v2 = Project(v2, axis).Normalized();
    ExpectVec3NearlyEqual(projected_rotated_v1, projected_v2, 1e-4f);
  }
}
TEST ( GetSignedAngle , RandomInput ) { RandomNumberGenerator rand ( :: testing :: UnitTest :: GetInstance ( ) -> random_seed ( ) ) ; for ( int i = 0 ; i < 100 ; ++ i ) { const mathfu :: vec3 axis = RandomUnitVec3 ( & rand ) ; const mathfu :: vec3 v1 = RandomUnitVec3 ( & rand ) ; const mathfu :: vec3 v2 = RandomUnitVec3 ( & rand ) ; if ( std :: fabs ( mathfu :: vec3 :: DotProduct ( v1 , v2 ) ) < .2f || std :: fabs ( mathfu :: vec3 :: DotProduct ( axis , v1 ) ) < .2f || std :: fabs ( mathfu :: vec3 :: DotProduct ( axis , v2 ) ) < .2f ) { continue ; } const float angle = GetSignedAngle ( v1 , v2 , axis ) ; const mathfu :: quat q = mathfu :: quat :: FromAngleAxis ( angle , axis ) ; const mathfu :: vec3 projected_rotated_v1 = Project ( q * v1 , axis ) . Normalized ( ) ; const mathfu :: vec3 projected_v2 = Project ( v2 , axis ) . Normalized ( ) ; ExpectVec3NearlyEqual ( projected_rotated_v1 , projected_v2 , 1e-4f ) ; } }
This test feeds in random input values, and checks that the result satisfies
the main invariant -- that the resulting axis-angle rotates v1 onto v2.
This test feeds in random input values and checks that the result satisfies the main invariant -- that the resulting axis - angle rotates v1 onto v2 .
// Ignore unstable region to keep this test from being flaky // Invariant: q should rotate the projection of v1 into the projection of v2 // This test isn't checking accuracy, thus the large epsilon.