Skip to content

Instantly share code, notes, and snippets.

@slembcke
Created March 5, 2013 15:32
Show Gist options
  • Save slembcke/5091122 to your computer and use it in GitHub Desktop.
Save slembcke/5091122 to your computer and use it in GitHub Desktop.
cpvslerp tests
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = cpvmult(cpvforangle(1.0), 1.0);
cpVect c = a;
cpVect v = cpvslerp(a, b, 0.0);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = cpvmult(cpvforangle(1.0), 1.0);
cpVect c = b;
cpVect v = cpvslerp(a, b, 1.0);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = cpvmult(cpvforangle(1.0), 1.0);
cpVect c = cpvmult(cpvforangle(0.5), 1.0);
cpVect v = cpvslerp(a, b, 0.5);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
{
cpVect a = cpvmult(cpvforangle(-1.0), 1.0);
cpVect b = cpvmult(cpvforangle( 1.0), 1.0);
cpVect c = cpvmult(cpvforangle( 0.0), 1.0);
cpVect v = cpvslerp(a, b, 0.5);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = cpvmult(cpvforangle(M_PI/2.0), 2.0);
cpVect c = cpvadd(cpvmult(a, cpfcos(M_PI/4.0)), cpvmult(b, cpfsin(M_PI/4.0)));
cpVect v = cpvslerp(a, b, 0.5);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = a;
cpVect c = a;
cpVect v = cpvslerp(a, b, 0.5);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
// TODO should it handle this?
// {
// cpVect a = cpv( 1.0, 0.01);
// cpVect b = cpv(-1.0, 0.0);
// cpVect v = cpvslerp(a, b, 0.5);
// GHAssertLessThan(cpvdot(a, v), (cpFloat)1e-5, nil);
// GHAssertLessThan(cpvdot(b, v), (cpFloat)1e-5, nil);
// GHAssertLessThan(cpvlength(v) - 1.0, (cpFloat)1e-5, nil);
// }
// Slerp const
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = cpvmult(cpvforangle(M_PI/2.0), 1.0);
cpVect c = cpvadd(cpvmult(a, cpfcos(M_PI/4.0)), cpvmult(b, cpfsin(M_PI/4.0)));
cpVect v = cpvslerpconst(a, b, M_PI/4.0);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = cpvmult(cpvforangle(M_PI/2.0), 1.0);
cpVect c = b;
cpVect v = cpvslerpconst(a, b, M_PI/2.0);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = cpvmult(cpvforangle(M_PI/2.0), 1.0);
cpVect c = b;
cpVect v = cpvslerpconst(a, b, INFINITY);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
{
cpVect a = cpvmult(cpvforangle(0.0), 1.0);
cpVect b = cpvmult(cpvforangle(M_PI/2.0), 1.0);
cpVect c = a;
cpVect v = cpvslerpconst(a, b, 0);
GHAssertLessThan(cpvdist(v, c), (cpFloat)1e-5, nil);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment