Math: remove and replace GP_ASSERT with AX_ASSERT (#2143)

This commit is contained in:
smilediver 2024-09-14 03:52:46 +03:00 committed by GitHub
parent c524c7dc8b
commit 117c4e6886
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 68 additions and 70 deletions

View File

@ -59,8 +59,6 @@ extern bool AX_DLL ax_assert_script_compatible(const char* msg);
# define AXASSERT(cond, msg)
# endif
# define GP_ASSERT(cond) AXASSERT(cond, "")
// FIXME:: Backward compatible
# define CCAssert AXASSERT
#endif // AXASSERT

View File

@ -54,7 +54,7 @@ void Mat4::createLookAt(float eyePositionX,
float upZ,
Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
Vec3 eye(eyePositionX, eyePositionY, eyePositionZ);
Vec3 target(targetPositionX, targetPositionY, targetPositionZ);
@ -96,8 +96,8 @@ void Mat4::createLookAt(float eyePositionX,
void Mat4::createPerspective(float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane, Mat4* dst)
{
GP_ASSERT(dst);
GP_ASSERT(zFarPlane != zNearPlane);
AX_ASSERT(dst);
AX_ASSERT(zFarPlane != zNearPlane);
float f_n = 1.0f / (zFarPlane - zNearPlane);
float theta = MATH_DEG_TO_RAD(fieldOfView) * 0.5f;
@ -108,12 +108,12 @@ void Mat4::createPerspective(float fieldOfView, float aspectRatio, float zNearPl
return;
}
float divisor = std::tan(theta);
GP_ASSERT(divisor);
AX_ASSERT(divisor);
float factor = 1.0f / divisor;
memset(dst->m, 0, sizeof(dst->m));
GP_ASSERT(aspectRatio);
AX_ASSERT(aspectRatio);
dst->m[0] = (1.0f / aspectRatio) * factor;
dst->m[5] = factor;
dst->m[10] = (-(zFarPlane + zNearPlane)) * f_n;
@ -142,10 +142,10 @@ void Mat4::createOrthographicOffCenter(float left,
float zFarPlane,
Mat4* dst)
{
GP_ASSERT(dst);
GP_ASSERT(right != left);
GP_ASSERT(top != bottom);
GP_ASSERT(zFarPlane != zNearPlane);
AX_ASSERT(dst);
AX_ASSERT(right != left);
AX_ASSERT(top != bottom);
AX_ASSERT(zFarPlane != zNearPlane);
memset(dst->m, 0, sizeof(dst->m));
dst->m[0] = 2 / (right - left);
@ -237,7 +237,7 @@ void Mat4::createBillboardHelper(const Vec3& objectPosition,
void Mat4::createScale(const Vec3& scale, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->setIdentity();
@ -248,7 +248,7 @@ void Mat4::createScale(const Vec3& scale, Mat4* dst)
void Mat4::createScale(float xScale, float yScale, float zScale, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->setIdentity();
@ -259,7 +259,7 @@ void Mat4::createScale(float xScale, float yScale, float zScale, Mat4* dst)
void Mat4::createRotation(const Quaternion& q, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
float x2 = q.x + q.x;
float y2 = q.y + q.y;
@ -298,7 +298,7 @@ void Mat4::createRotation(const Quaternion& q, Mat4* dst)
void Mat4::createRotation(const Vec3& axis, float angle, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
float x = axis.x;
float y = axis.y;
@ -357,7 +357,7 @@ void Mat4::createRotation(const Vec3& axis, float angle, Mat4* dst)
void Mat4::createRotationX(float angle, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->setIdentity();
@ -372,7 +372,7 @@ void Mat4::createRotationX(float angle, Mat4* dst)
void Mat4::createRotationY(float angle, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->setIdentity();
@ -387,7 +387,7 @@ void Mat4::createRotationY(float angle, Mat4* dst)
void Mat4::createRotationZ(float angle, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->setIdentity();
@ -402,7 +402,7 @@ void Mat4::createRotationZ(float angle, Mat4* dst)
void Mat4::createTranslation(const Vec3& translation, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->setIdentity();
@ -413,7 +413,7 @@ void Mat4::createTranslation(const Vec3& translation, Mat4* dst)
void Mat4::createTranslation(float xTranslation, float yTranslation, float zTranslation, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->setIdentity();
@ -429,7 +429,7 @@ void Mat4::add(float scalar)
void Mat4::add(float scalar, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::addMatrix(m, scalar, dst->m);
}
@ -440,7 +440,7 @@ void Mat4::add(const Mat4& mat)
void Mat4::add(const Mat4& m1, const Mat4& m2, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::addMatrix(m1.m, m2.m, dst->m);
}
@ -588,7 +588,7 @@ void Mat4::getTranslation(Vec3* translation) const
void Mat4::getUpVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = m[4];
dst->y = m[5];
@ -597,7 +597,7 @@ void Mat4::getUpVector(Vec3* dst) const
void Mat4::getDownVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = -m[4];
dst->y = -m[5];
@ -606,7 +606,7 @@ void Mat4::getDownVector(Vec3* dst) const
void Mat4::getLeftVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = -m[0];
dst->y = -m[1];
@ -615,7 +615,7 @@ void Mat4::getLeftVector(Vec3* dst) const
void Mat4::getRightVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = m[0];
dst->y = m[1];
@ -624,7 +624,7 @@ void Mat4::getRightVector(Vec3* dst) const
void Mat4::getForwardVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = -m[8];
dst->y = -m[9];
@ -633,7 +633,7 @@ void Mat4::getForwardVector(Vec3* dst) const
void Mat4::getBackVector(Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = m[8];
dst->y = m[9];
@ -713,7 +713,7 @@ void Mat4::multiply(float scalar, Mat4* dst) const
void Mat4::multiply(const Mat4& m, float scalar, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::multiplyMatrix(m.m, scalar, dst->m);
}
@ -724,7 +724,7 @@ void Mat4::multiply(const Mat4& mat)
void Mat4::multiply(const Mat4& m1, const Mat4& m2, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::multiplyMatrix(m1.m, m2.m, dst->m);
}
@ -839,13 +839,13 @@ void Mat4::subtract(const Mat4& mat)
void Mat4::subtract(const Mat4& m1, const Mat4& m2, Mat4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::subtractMatrix(m1.m, m2.m, dst->m);
}
void Mat4::transformVector(Vec3* vector) const
{
GP_ASSERT(vector);
AX_ASSERT(vector);
transformVector(vector->x, vector->y, vector->z, 0.0f, vector);
}
@ -856,20 +856,20 @@ void Mat4::transformVector(const Vec3& vector, Vec3* dst) const
void Mat4::transformVector(float x, float y, float z, float w, Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::transformVec4(m, x, y, z, w, reinterpret_cast<float*>(dst));
}
void Mat4::transformVector(Vec4* vector) const
{
GP_ASSERT(vector);
AX_ASSERT(vector);
transformVector(*vector, vector);
}
void Mat4::transformVector(const Vec4& vector, Vec4* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
MathUtil::transformVec4(m, reinterpret_cast<const float*>(&vector), reinterpret_cast<float*>(dst));
}

View File

@ -772,7 +772,7 @@ public:
*/
void set(const float* mat)
{
GP_ASSERT(mat);
AX_ASSERT(mat);
memcpy(m, mat, sizeof(m));
}
@ -821,7 +821,7 @@ public:
*/
inline void transformPoint(Vec3* point) const
{
GP_ASSERT(point);
AX_ASSERT(point);
transformVector(point->x, point->y, point->z, 1.0f, point);
}
@ -834,7 +834,7 @@ public:
*/
inline void transformPoint(const Vec3& point, Vec3* dst) const
{
GP_ASSERT(dst);
AX_ASSERT(dst);
transformVector(point.x, point.y, point.z, 1.0f, dst);
}

View File

@ -40,7 +40,7 @@ NS_AX_MATH_BEGIN
void MathUtil::smooth(float* x, float target, float elapsedTime, float responseTime)
{
GP_ASSERT(x);
AX_ASSERT(x);
if (elapsedTime > 0)
{
@ -50,7 +50,7 @@ void MathUtil::smooth(float* x, float target, float elapsedTime, float responseT
void MathUtil::smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime)
{
GP_ASSERT(x);
AX_ASSERT(x);
if (elapsedTime > 0)
{

View File

@ -106,7 +106,7 @@ void Quaternion::multiply(const Quaternion& q)
void Quaternion::multiply(const Quaternion& q1, const Quaternion& q2, Quaternion* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
float x = q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y;
float y = q1.w * q2.y - q1.x * q2.z + q1.y * q2.w + q1.z * q2.x;
@ -153,7 +153,7 @@ void Quaternion::set(const Mat4& m)
float Quaternion::toAxisAngle(Vec3* axis) const
{
GP_ASSERT(axis);
AX_ASSERT(axis);
Quaternion q(x, y, z, w);
q.normalize();
@ -167,8 +167,8 @@ float Quaternion::toAxisAngle(Vec3* axis) const
void Quaternion::lerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst)
{
GP_ASSERT(dst);
GP_ASSERT(!(t < 0.0f || t > 1.0f));
AX_ASSERT(dst);
AX_ASSERT(!(t < 0.0f || t > 1.0f));
if (t == 0.0f)
{
@ -191,7 +191,7 @@ void Quaternion::lerp(const Quaternion& q1, const Quaternion& q2, float t, Quate
void Quaternion::slerp(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
slerp(q1.x, q1.y, q1.z, q1.w, q2.x, q2.y, q2.z, q2.w, t, &dst->x, &dst->y, &dst->z, &dst->w);
}
@ -202,7 +202,7 @@ void Quaternion::squad(const Quaternion& q1,
float t,
Quaternion* dst)
{
GP_ASSERT(!(t < 0.0f || t > 1.0f));
AX_ASSERT(!(t < 0.0f || t > 1.0f));
Quaternion dstQ(0.0f, 0.0f, 0.0f, 1.0f);
Quaternion dstS(0.0f, 0.0f, 0.0f, 1.0f);
@ -230,8 +230,8 @@ void Quaternion::slerp(float q1x,
// It contains no division operations, no trig, no inverse trig
// and no sqrt. Not only does this code tolerate small constraint
// errors in the input quaternions, it actually corrects for them.
GP_ASSERT(dstx && dsty && dstz && dstw);
GP_ASSERT(!(t < 0.0f || t > 1.0f));
AX_ASSERT(dstx && dsty && dstz && dstw);
AX_ASSERT(!(t < 0.0f || t > 1.0f));
if (t == 0.0f)
{
@ -325,7 +325,7 @@ void Quaternion::slerp(float q1x,
void Quaternion::slerpForSquad(const Quaternion& q1, const Quaternion& q2, float t, Quaternion* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
// cos(omega) = q1 * q2;
// slerp(q1, q2, t) = (q1*sin((1-t)*omega) + q2*sin(t*omega))/sin(omega);

View File

@ -179,7 +179,7 @@ public:
*/
static void createFromAxisAngle(const Vec3& axis, float angle, Quaternion* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
float halfAngle = angle * 0.5f;
float sinHalfAngle = sinf(halfAngle);
@ -281,7 +281,7 @@ public:
*/
constexpr void set(float* array)
{
GP_ASSERT(array);
AX_ASSERT(array);
x = array[0];
y = array[1];

View File

@ -98,7 +98,7 @@ float Vec2::angle(const Vec2& v1, const Vec2& v2)
void Vec2::add(const Vec2& v1, const Vec2& v2, Vec2* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = v1.x + v2.x;
dst->y = v1.y + v2.y;
@ -106,7 +106,7 @@ void Vec2::add(const Vec2& v1, const Vec2& v2, Vec2* dst)
void Vec2::clamp(const Vec2& min, const Vec2& max)
{
GP_ASSERT(!(min.x > max.x || min.y > max.y));
AX_ASSERT(!(min.x > max.x || min.y > max.y));
// Clamp the x value.
if (x < min.x)
@ -123,8 +123,8 @@ void Vec2::clamp(const Vec2& min, const Vec2& max)
void Vec2::clamp(const Vec2& v, const Vec2& min, const Vec2& max, Vec2* dst)
{
GP_ASSERT(dst);
GP_ASSERT(!(min.x > max.x || min.y > max.y));
AX_ASSERT(dst);
AX_ASSERT(!(min.x > max.x || min.y > max.y));
// Clamp the x value.
dst->x = v.x;
@ -206,7 +206,7 @@ void Vec2::rotate(const Vec2& point, float angle)
void Vec2::subtract(const Vec2& v1, const Vec2& v2, Vec2* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = v1.x - v2.x;
dst->y = v1.y - v2.y;

View File

@ -326,7 +326,7 @@ public:
*/
constexpr void set(const float* array)
{
GP_ASSERT(array);
AX_ASSERT(array);
x = array[0];
y = array[1];

View File

@ -60,7 +60,7 @@ float Vec3::angle(const Vec3& v1, const Vec3& v2)
void Vec3::add(const Vec3& v1, const Vec3& v2, Vec3* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = v1.x + v2.x;
dst->y = v1.y + v2.y;
@ -69,7 +69,7 @@ void Vec3::add(const Vec3& v1, const Vec3& v2, Vec3* dst)
void Vec3::clamp(const Vec3& min, const Vec3& max)
{
GP_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z));
AX_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z));
// Clamp the x value.
if (x < min.x)
@ -92,8 +92,8 @@ void Vec3::clamp(const Vec3& min, const Vec3& max)
void Vec3::clamp(const Vec3& v, const Vec3& min, const Vec3& max, Vec3* dst)
{
GP_ASSERT(dst);
GP_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z));
AX_ASSERT(dst);
AX_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z));
// Clamp the x value.
dst->x = v.x;
@ -124,7 +124,7 @@ void Vec3::cross(const Vec3& v)
void Vec3::cross(const Vec3& v1, const Vec3& v2, Vec3* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
// NOTE: This code assumes Vec3 struct members are contiguous floats in memory.
// We might want to revisit this (and other areas of code that make this assumption)
@ -187,7 +187,7 @@ Vec3 Vec3::getNormalized() const
void Vec3::subtract(const Vec3& v1, const Vec3& v2, Vec3* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = v1.x - v2.x;
dst->y = v1.y - v2.y;

View File

@ -329,7 +329,7 @@ public:
*/
constexpr void set(const float* array)
{
GP_ASSERT(array);
AX_ASSERT(array);
x = array[0];
y = array[1];

View File

@ -74,7 +74,7 @@ float Vec4::angle(const Vec4& v1, const Vec4& v2)
void Vec4::add(const Vec4& v1, const Vec4& v2, Vec4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = v1.x + v2.x;
dst->y = v1.y + v2.y;
@ -84,7 +84,7 @@ void Vec4::add(const Vec4& v1, const Vec4& v2, Vec4* dst)
void Vec4::clamp(const Vec4& min, const Vec4& max)
{
GP_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w));
AX_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w));
// Clamp the x value.
if (x < min.x)
@ -113,8 +113,8 @@ void Vec4::clamp(const Vec4& min, const Vec4& max)
void Vec4::clamp(const Vec4& v, const Vec4& min, const Vec4& max, Vec4* dst)
{
GP_ASSERT(dst);
GP_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w));
AX_ASSERT(dst);
AX_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z || min.w > max.w));
// Clamp the x value.
dst->x = v.x;
@ -213,7 +213,7 @@ Vec4 Vec4::getNormalized() const
void Vec4::subtract(const Vec4& v1, const Vec4& v2, Vec4* dst)
{
GP_ASSERT(dst);
AX_ASSERT(dst);
dst->x = v1.x - v2.x;
dst->y = v1.y - v2.y;

View File

@ -135,7 +135,7 @@ public:
*/
void set(const float* array)
{
GP_ASSERT(array);
AX_ASSERT(array);
this->x = array[0];
this->y = array[1];