Skip to content

Instantly share code, notes, and snippets.

@pavel-perina
Last active November 22, 2017 16:39
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 pavel-perina/0e7e6716385485d9a4fee7c296300eb7 to your computer and use it in GitHub Desktop.
Save pavel-perina/0e7e6716385485d9a4fee7c296300eb7 to your computer and use it in GitHub Desktop.
C/C++ code snippets
// -----------------------------------------------------------------------------------
/// @brief Difference between two angles in radians, difference is inside -PI..PI
/// @todo: verify sign
/// NOTE: same function in Collision\col_math.cpp
__inline double AngleDiffRad (double a, double b)
{
double r = fmod (b - a, M_PI+M_PI);
if (r < 0.0)
r += M_PI+M_PI;
if (r > M_PI)
r -= M_PI+M_PI;
return -r;
}
// -----------------------------------------------------------------------------------
/// Difference between two angles in degrees, difference is inside -180..180
__inline double AngleDiffDeg (double a, double b)
{
double r = fmod (b - a, 360.0);
if (r < 0.0)
r += 360.0;
if (r > 180.0)
r -= 360.0;
return -r;
}
// -----------------------------------------------------------------------------------
#ifdef PROFILE_COLLISION_TEST_TIME
std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
#endif
colResult = pCollTest->checkCollision(trajectory, abortCheckFunc);
#ifdef PROFILE_COLLISION_TEST_TIME
std::chrono::duration<double, std::ratio<1, 1000>> durationMili = std::chrono::system_clock::now() - start;
qDebug() << "Checked " << QString::number(trajectory.size()) << " trajectory points took " << QString::number(durationMili.count()) << " ms";
#endif
// -----------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment