summaryrefslogtreecommitdiffstats
path: root/src/Vector3.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-05-05 17:19:55 +0200
committerMattes D <github@xoft.cz>2014-05-05 17:19:55 +0200
commit3c4054433648b3940d24f36b6c624242cc52536c (patch)
tree22de2280687b04a148f534df040f2f27b727a67e /src/Vector3.h
parentFixed crash on creating a world during plugin initialisation (diff)
parentRemoved convert-assign operator. (diff)
downloadcuberite-3c4054433648b3940d24f36b6c624242cc52536c.tar
cuberite-3c4054433648b3940d24f36b6c624242cc52536c.tar.gz
cuberite-3c4054433648b3940d24f36b6c624242cc52536c.tar.bz2
cuberite-3c4054433648b3940d24f36b6c624242cc52536c.tar.lz
cuberite-3c4054433648b3940d24f36b6c624242cc52536c.tar.xz
cuberite-3c4054433648b3940d24f36b6c624242cc52536c.tar.zst
cuberite-3c4054433648b3940d24f36b6c624242cc52536c.zip
Diffstat (limited to 'src/Vector3.h')
-rw-r--r--src/Vector3.h44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/Vector3.h b/src/Vector3.h
index 2c79f9ff1..276bf67c9 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -40,7 +40,6 @@ public:
Vector3(const Vector3<_T> * a_Rhs) : x(a_Rhs->x), y(a_Rhs->y), z(a_Rhs->z) {}
// tolua_begin
-
inline void Set(T a_x, T a_y, T a_z)
{
x = a_x;
@@ -105,18 +104,23 @@ public:
inline bool Equals(const Vector3<T> & a_Rhs) const
{
- return x == a_Rhs.x && y == a_Rhs.y && z == a_Rhs.z;
+ // Perform a bitwise comparison of the contents - we want to know whether this object is exactly equal
+ // To perform EPS-based comparison, use the EqualsEps() function
+ return (
+ (memcmp(&x, &a_Rhs.x, sizeof(x)) == 0) &&
+ (memcmp(&y, &a_Rhs.y, sizeof(y)) == 0) &&
+ (memcmp(&z, &a_Rhs.z, sizeof(z)) == 0)
+ );
}
-
- inline bool operator == (const Vector3<T> & a_Rhs) const
+
+ inline bool EqualsEps(const Vector3<T> & a_Rhs, T a_Eps) const
{
- return Equals(a_Rhs);
+ return (Abs(x - a_Rhs.x) < a_Eps) && (Abs(y - a_Rhs.y) < a_Eps) && (Abs(z - a_Rhs.z) < a_Eps);
}
- inline bool operator < (const Vector3<T> & a_Rhs)
+ inline bool operator == (const Vector3<T> & a_Rhs) const
{
- // return (x < a_Rhs.x) && (y < a_Rhs.y) && (z < a_Rhs.z); ?
- return (x < a_Rhs.x) || (x == a_Rhs.x && y < a_Rhs.y) || (x == a_Rhs.x && y == a_Rhs.y && z < a_Rhs.z);
+ return Equals(a_Rhs);
}
inline void Move(T a_X, T a_Y, T a_Z)
@@ -163,8 +167,16 @@ public:
z *= a_v;
}
- // tolua_begin
+ inline Vector3<T> & operator = (const Vector3<T> & a_Rhs)
+ {
+ x = a_Rhs.x;
+ y = a_Rhs.y;
+ z = a_Rhs.z;
+ return *this;
+ }
+ // tolua_begin
+
inline Vector3<T> operator + (const Vector3<T>& a_Rhs) const
{
return Vector3<T>(
@@ -217,7 +229,7 @@ public:
*/
inline double LineCoeffToXYPlane(const Vector3<T> & a_OtherEnd, T a_Z) const
{
- if (abs(z - a_OtherEnd.z) < EPS)
+ if (Abs(z - a_OtherEnd.z) < EPS)
{
return NO_INTERSECTION;
}
@@ -232,7 +244,7 @@ public:
*/
inline double LineCoeffToXZPlane(const Vector3<T> & a_OtherEnd, T a_Y) const
{
- if (abs(y - a_OtherEnd.y) < EPS)
+ if (Abs(y - a_OtherEnd.y) < EPS)
{
return NO_INTERSECTION;
}
@@ -247,7 +259,7 @@ public:
*/
inline double LineCoeffToYZPlane(const Vector3<T> & a_OtherEnd, T a_X) const
{
- if (abs(x - a_OtherEnd.x) < EPS)
+ if (Abs(x - a_OtherEnd.x) < EPS)
{
return NO_INTERSECTION;
}
@@ -260,7 +272,15 @@ public:
/** Return value of LineCoeffToPlane() if the line is parallel to the plane. */
static const double NO_INTERSECTION;
+
+protected:
+ /** Returns the absolute value of the given argument.
+ Templatized because the standard library differentiates between abs() and fabs(). */
+ static T Abs(T a_Value)
+ {
+ return (a_Value < 0) ? -a_Value : a_Value;
+ }
};
// tolua_end