credit to @MusicMonkey5555 for spotting. asserts for Div/NULLs with mutli-element classes

Also includes his magnitude and normalize safe alts
This commit is contained in:
Azaezel 2015-08-12 03:41:49 -05:00
parent c9bf6b1ae5
commit 4d3db61e94
3 changed files with 39 additions and 1 deletions

View file

@ -503,6 +503,7 @@ inline ColorI& ColorI::operator*=(const S32 in_mul)
inline ColorI& ColorI::operator/=(const S32 in_mul)
{
AssertFatal(in_mul != 0.0f, "Error, div by zero...");
red = red / in_mul;
green = green / in_mul;
blue = blue / in_mul;

View file

@ -438,6 +438,7 @@ inline Point2I Point2I::operator/(const Point2I &_vec) const
inline Point2I& Point2I::operator/=(const Point2I &_vec)
{
AssertFatal(_vec.x != 0 && _vec.y != 0, "Error, div by zero attempted");
x /= _vec.x;
y /= _vec.y;
return *this;
@ -645,6 +646,7 @@ inline Point2F Point2F::operator/(const Point2F &_vec) const
inline Point2F& Point2F::operator/=(const Point2F &_vec)
{
AssertFatal(_vec.x != 0 && _vec.y != 0, "Error, div by zero attempted");
x /= _vec.x;
y /= _vec.y;
return *this;
@ -908,6 +910,14 @@ inline bool mIsNaN( const Point2F &p )
return mIsNaN_F( p.x ) || mIsNaN_F( p.y );
}
/// Return 0 if points are colinear
/// Return positive if p0p1p2 are counter-clockwise
/// Return negative if p0p1p2 are clockwise
inline F64 mCross(const Point2F &p0, const Point2F &p1, const Point2F &pt2)
{
return (p1.x - p0.x) * (pt2.y - p0.y) - (p1.y - p0.y) * (pt2.x - p0.x);
}
namespace DictHash
{

View file

@ -233,11 +233,13 @@ class Point3D
bool isZero() const;
F64 len() const;
F64 lenSquared() const;
F64 magnitudeSafe() const;
//-------------------------------------- Mathematical mutators
public:
void neg();
void normalize();
void normalizeSafe();
void normalize(F64 val);
void convolve(const Point3D&);
void convolveInverse(const Point3D&);
@ -728,11 +730,13 @@ inline Point3F& Point3F::operator*=(const Point3F &_vec)
inline Point3F Point3F::operator/(const Point3F &_vec) const
{
AssertFatal(_vec.x != 0.0f && _vec.y != 0.0f && _vec.z != 0.0f, "Error, div by zero attempted");
return Point3F(x / _vec.x, y / _vec.y, z / _vec.z);
}
inline Point3F& Point3F::operator/=(const Point3F &_vec)
{
AssertFatal(_vec.x != 0.0f && _vec.y != 0.0f && _vec.z != 0.0f, "Error, div by zero attempted");
x /= _vec.x;
y /= _vec.y;
z /= _vec.z;
@ -855,7 +859,8 @@ inline F64 Point3D::lenSquared() const
inline F64 Point3D::len() const
{
return mSqrtD(x*x + y*y + z*z);
F64 temp = x*x + y*y + z*z;
return (temp > 0.0) ? mSqrtD(temp) : 0.0;
}
inline void Point3D::normalize()
@ -863,6 +868,28 @@ inline void Point3D::normalize()
m_point3D_normalize(*this);
}
inline F64 Point3D::magnitudeSafe() const
{
if( isZero() )
{
return 0.0;
}
else
{
return len();
}
}
inline void Point3D::normalizeSafe()
{
F64 vmag = magnitudeSafe();
if( vmag > POINT_EPSILON )
{
*this *= F64(1.0 / vmag);
}
}
inline void Point3D::normalize(F64 val)
{
m_point3D_normalize_f(*this, val);