Skip to content

Instantly share code, notes, and snippets.

@Klaim
Created January 26, 2014 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Klaim/8633917 to your computer and use it in GitHub Desktop.
Save Klaim/8633917 to your computer and use it in GitHub Desktop.
SphereVector tests (using GTest) - to review (not everything pass)
#include <gtest/gtest.h>
#include <iostream>
#include <netrush/zoneview/spherical.hpp>
using namespace netrush::zoneview;
TEST( Test_SphereVector, assignation_comparison )
{
SphereVector svec = SphereVector::ZERO;
ASSERT_EQ( svec, SphereVector::ZERO );
svec = SphereVector::NEGATIVE_UNIT_X;
ASSERT_EQ( svec, SphereVector::NEGATIVE_UNIT_X );
ASSERT_NE( svec, SphereVector::ZERO );
svec = SphereVector::ZERO;
ASSERT_EQ( svec, SphereVector::ZERO );
ASSERT_NE( svec, SphereVector::NEGATIVE_UNIT_X );
}
inline bool check_to_cartesian( SphereVector svec, Ogre::Vector3 vec )
{
const auto cart_vec = svec.to_cartesian();
std::cout << "----"
<< "\nChecking to_cartesian with SphereVector: " << svec
<< "\n Induced cartesian Vector: " << cart_vec
<< "\n Comparing against Vector: " << vec
<< std::endl;
return vec.positionEquals( cart_vec );
}
inline bool check_from_cartesian( Ogre::Vector3 vec, SphereVector svec )
{
const auto from_cart_svec = SphereVector::from_cartesian( vec );
std::cout << "----"
<< "\nChecking from_cartesian with Vector " << vec
<< "\n Induced SphereVector: " << from_cart_svec
<< "\n Comparing against Vector: SphereVector: " << svec
<< std::endl;
return real_equals( svec, from_cart_svec );
}
inline bool check_compare( SphereVector left, SphereVector right )
{
std::cout << "----"
<< "\nComparing "
<< "\n Left: " << left
<< "\n Right: " << right
<< std::endl;
return real_equals( left, right );
}
inline bool check_compare( Ogre::Vector3 left, Ogre::Vector3 right )
{
std::cout << "----"
<< "\nComparing "
<< "\n Left: " << left
<< "\n Right: " << right
<< std::endl;
return left.positionEquals( right );
}
TEST( Test_SphereVector, axes_to_cartesian )
{
SphereVector svec;
svec.radius = 1.f;
svec.theta = 0.f;
svec.phi = 0.f;
check_to_cartesian( svec, Ogre::Vector3::UNIT_Y );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 90.f );
svec.phi = 0.f;
check_to_cartesian( svec, Ogre::Vector3::UNIT_Z );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 90.f );
svec.phi = Ogre::Degree( 90.f );
check_to_cartesian( svec, Ogre::Vector3::UNIT_X );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 180.f );
svec.phi = 0.f;
check_to_cartesian( svec, Ogre::Vector3::NEGATIVE_UNIT_Y );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 90.f );
svec.phi = Ogre::Degree( 180.f );
check_to_cartesian( svec, Ogre::Vector3::NEGATIVE_UNIT_Z );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 90.f );
svec.phi = Ogre::Degree( 270.f );
check_to_cartesian( svec, Ogre::Vector3::NEGATIVE_UNIT_X );
}
TEST( Test_SphereVector, axes_from_cartesian )
{
SphereVector svec;
svec.radius = 1.f;
svec.theta = 0.f;
svec.phi = 0.f;
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::UNIT_Y, svec ) );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 90.f );
svec.phi = 0.f;
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::UNIT_Z, svec ) );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 90.f );
svec.phi = Ogre::Degree( 90.f );
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::UNIT_X, svec ) );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 180.f );
svec.phi = 0.f;
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::NEGATIVE_UNIT_Y, svec ) );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 90.f );
svec.phi = Ogre::Degree( 180.f );
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::NEGATIVE_UNIT_Z, svec ) );
svec.radius = 1.f;
svec.theta = Ogre::Degree( 90.f );
svec.phi = Ogre::Degree( 270.f );
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::NEGATIVE_UNIT_X, svec ) );
}
TEST( Test_SphereVector, default_axes_to_cartesian )
{
EXPECT_TRUE( check_to_cartesian( SphereVector::UNIT_X , Ogre::Vector3::UNIT_X ) );
EXPECT_TRUE( check_to_cartesian( SphereVector::UNIT_Y , Ogre::Vector3::UNIT_Y ) );
EXPECT_TRUE( check_to_cartesian( SphereVector::UNIT_Z , Ogre::Vector3::UNIT_Z ) );
EXPECT_TRUE( check_to_cartesian( SphereVector::NEGATIVE_UNIT_X , Ogre::Vector3::NEGATIVE_UNIT_X ) );
EXPECT_TRUE( check_to_cartesian( SphereVector::NEGATIVE_UNIT_Y , Ogre::Vector3::NEGATIVE_UNIT_Y ) );
EXPECT_TRUE( check_to_cartesian( SphereVector::NEGATIVE_UNIT_Z , Ogre::Vector3::NEGATIVE_UNIT_Z ) );
}
TEST( Test_SphereVector, default_axes_from_cartesian )
{
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::UNIT_X , SphereVector::UNIT_X ) );
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::UNIT_Y , SphereVector::UNIT_Y ) );
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::UNIT_Z , SphereVector::UNIT_Z ) );
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::NEGATIVE_UNIT_X, SphereVector::NEGATIVE_UNIT_X ) );
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::NEGATIVE_UNIT_Y, SphereVector::NEGATIVE_UNIT_Y ) );
EXPECT_TRUE( check_from_cartesian( Ogre::Vector3::NEGATIVE_UNIT_Z, SphereVector::NEGATIVE_UNIT_Z ) );
}
TEST( Test_SphereVector, symetric_cartesian_funcs )
{
auto cartesian_to_cartesian = []( Ogre::Vector3 vec ) {
const auto svec = SphereVector::from_cartesian( vec );
const auto cvec = svec.to_cartesian();
return check_compare( vec, cvec );
};
EXPECT_TRUE( cartesian_to_cartesian( Ogre::Vector3::UNIT_X ) );
EXPECT_TRUE( cartesian_to_cartesian( Ogre::Vector3::UNIT_Y ) );
EXPECT_TRUE( cartesian_to_cartesian( Ogre::Vector3::UNIT_Z ) );
EXPECT_TRUE( cartesian_to_cartesian( Ogre::Vector3::NEGATIVE_UNIT_X ) );
EXPECT_TRUE( cartesian_to_cartesian( Ogre::Vector3::NEGATIVE_UNIT_Y ) );
EXPECT_TRUE( cartesian_to_cartesian( Ogre::Vector3::NEGATIVE_UNIT_Z ) );
}
TEST( Test_SphereVector, axe_rotation_quaternion )
{
using namespace Ogre;
const auto init_svec = SphereVector::NEGATIVE_UNIT_Z;
static const auto ROTATION_TO_X = Vector3::NEGATIVE_UNIT_Z.getRotationTo( Vector3::UNIT_X );
static const auto ROTATION_TO_Y = Vector3::NEGATIVE_UNIT_Z.getRotationTo( Vector3::UNIT_Y );
static const auto ROTATION_TO_Z = Vector3::NEGATIVE_UNIT_Z.getRotationTo( Vector3::UNIT_Z );
static const auto ROTATION_TO_NEGATIVE_X = Vector3::NEGATIVE_UNIT_Z.getRotationTo( Vector3::NEGATIVE_UNIT_X );
static const auto ROTATION_TO_NEGATIVE_Y = Vector3::NEGATIVE_UNIT_Z.getRotationTo( Vector3::NEGATIVE_UNIT_Y );
static const auto ROTATION_TO_NEGATIVE_Z = Vector3::NEGATIVE_UNIT_Z.getRotationTo( Vector3::NEGATIVE_UNIT_Z );
static const auto ROTATION_360 = ROTATION_TO_Z * 2;
const auto svec_x = init_svec * ROTATION_TO_X;
const auto svec_y = init_svec * ROTATION_TO_Y;
const auto svec_z = init_svec * ROTATION_TO_Z;
const auto svec_nx = init_svec * ROTATION_TO_NEGATIVE_X;
const auto svec_ny = init_svec * ROTATION_TO_NEGATIVE_Y;
const auto svec_nz = init_svec * ROTATION_TO_NEGATIVE_Z;
const auto svec_360 = init_svec * ROTATION_360;
EXPECT_TRUE( check_compare( svec_x.to_cartesian() , Vector3::UNIT_X ) );
EXPECT_TRUE( check_compare( svec_y.to_cartesian() , Vector3::UNIT_Y ) );
EXPECT_TRUE( check_compare( svec_z.to_cartesian() , Vector3::UNIT_Z ) );
EXPECT_TRUE( check_compare( svec_nx.to_cartesian() , Vector3::NEGATIVE_UNIT_X ) );
EXPECT_TRUE( check_compare( svec_ny.to_cartesian() , Vector3::NEGATIVE_UNIT_Y ) );
EXPECT_TRUE( check_compare( svec_nz.to_cartesian() , Vector3::NEGATIVE_UNIT_Z ) );
EXPECT_TRUE( check_compare( svec_360.to_cartesian(), Vector3::NEGATIVE_UNIT_Z ) );
EXPECT_TRUE( check_compare( svec_x , SphereVector::UNIT_X ) );
EXPECT_TRUE( check_compare( svec_y , SphereVector::UNIT_Y ) );
EXPECT_TRUE( check_compare( svec_z , SphereVector::UNIT_Z ) );
EXPECT_TRUE( check_compare( svec_nx , SphereVector::NEGATIVE_UNIT_X ) );
EXPECT_TRUE( check_compare( svec_ny , SphereVector::NEGATIVE_UNIT_Y ) );
EXPECT_TRUE( check_compare( svec_nz , SphereVector::NEGATIVE_UNIT_Z ) );
EXPECT_TRUE( check_compare( svec_360, SphereVector::NEGATIVE_UNIT_Z ) );
}
TEST( Test_SphereVector, axe_rotation_theta_phi )
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment