From e0649b68220ff41c24be5a8faf3e03de3b4ebf5b Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 14 Dec 2017 17:42:59 +0100 Subject: [PATCH] fix misalignment in vector2 [] operator, the non-const one. --- include/assimp/vector2.inl | 58 ++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/include/assimp/vector2.inl b/include/assimp/vector2.inl index ee6c4d2d4..97db2820c 100644 --- a/include/assimp/vector2.inl +++ b/include/assimp/vector2.inl @@ -60,24 +60,28 @@ aiVector2t::operator aiVector2t () const { } // ------------------------------------------------------------------------------------------------ template +inline void aiVector2t::Set( TReal pX, TReal pY) { x = pX; y = pY; } // ------------------------------------------------------------------------------------------------ template +inline TReal aiVector2t::SquareLength() const { return x*x + y*y; } // ------------------------------------------------------------------------------------------------ template +inline TReal aiVector2t::Length() const { return std::sqrt( SquareLength()); } // ------------------------------------------------------------------------------------------------ template +inline aiVector2t& aiVector2t::Normalize() { *this /= Length(); return *this; @@ -85,6 +89,7 @@ aiVector2t& aiVector2t::Normalize() { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator += (const aiVector2t& o) { x += o.x; y += o.y; return *this; @@ -92,6 +97,7 @@ const aiVector2t& aiVector2t::operator += (const aiVector2t& o) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator -= (const aiVector2t& o) { x -= o.x; y -= o.y; return *this; @@ -99,6 +105,7 @@ const aiVector2t& aiVector2t::operator -= (const aiVector2t& o) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator *= (TReal f) { x *= f; y *= f; return *this; @@ -106,6 +113,7 @@ const aiVector2t& aiVector2t::operator *= (TReal f) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t& aiVector2t::operator /= (TReal f) { x /= f; y /= f; return *this; @@ -113,6 +121,7 @@ const aiVector2t& aiVector2t::operator /= (TReal f) { // ------------------------------------------------------------------------------------------------ template +inline TReal aiVector2t::operator[](unsigned int i) const { switch (i) { case 0: @@ -127,24 +136,36 @@ TReal aiVector2t::operator[](unsigned int i) const { // ------------------------------------------------------------------------------------------------ template +inline TReal& aiVector2t::operator[](unsigned int i) { - return *(&x + i); + switch (i) { + case 0: + return x; + case 1: + return y; + default: + break; + } + return x; } // ------------------------------------------------------------------------------------------------ template +inline bool aiVector2t::operator== (const aiVector2t& other) const { return x == other.x && y == other.y; } // ------------------------------------------------------------------------------------------------ template +inline bool aiVector2t::operator!= (const aiVector2t& other) const { return x != other.x || y != other.y; } // --------------------------------------------------------------------------- template +inline bool aiVector2t::Equal(const aiVector2t& other, TReal epsilon) const { return std::abs(x - other.x) <= epsilon && @@ -153,6 +174,7 @@ bool aiVector2t::Equal(const aiVector2t& other, TReal epsilon) const { // ------------------------------------------------------------------------------------------------ template +inline aiVector2t& aiVector2t::operator= (TReal f) { x = y = f; return *this; @@ -160,6 +182,7 @@ aiVector2t& aiVector2t::operator= (TReal f) { // ------------------------------------------------------------------------------------------------ template +inline const aiVector2t aiVector2t::SymMul(const aiVector2t& o) { return aiVector2t(x*o.x,y*o.y); } @@ -168,65 +191,64 @@ const aiVector2t aiVector2t::SymMul(const aiVector2t& o) { // ------------------------------------------------------------------------------------------------ // symmetric addition template -inline aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) -{ +inline +inline aiVector2t operator + (const aiVector2t& v1, const aiVector2t& v2) { return aiVector2t( v1.x + v2.x, v1.y + v2.y); } // ------------------------------------------------------------------------------------------------ // symmetric subtraction template -inline aiVector2t operator - (const aiVector2t& v1, const aiVector2t& v2) -{ +inline +aiVector2t operator - (const aiVector2t& v1, const aiVector2t& v2) { return aiVector2t( v1.x - v2.x, v1.y - v2.y); } // ------------------------------------------------------------------------------------------------ // scalar product template -inline TReal operator * (const aiVector2t& v1, const aiVector2t& v2) -{ +inline +TReal operator * (const aiVector2t& v1, const aiVector2t& v2) { return v1.x*v2.x + v1.y*v2.y; } // ------------------------------------------------------------------------------------------------ // scalar multiplication template -inline aiVector2t operator * ( TReal f, const aiVector2t& v) -{ +inline +aiVector2t operator * ( TReal f, const aiVector2t& v) { return aiVector2t( f*v.x, f*v.y); } // ------------------------------------------------------------------------------------------------ // and the other way around template -inline aiVector2t operator * ( const aiVector2t& v, TReal f) -{ +inline +aiVector2t operator * ( const aiVector2t& v, TReal f) { return aiVector2t( f*v.x, f*v.y); } // ------------------------------------------------------------------------------------------------ // scalar division template -inline aiVector2t operator / ( const aiVector2t& v, TReal f) -{ - +inline +aiVector2t operator / ( const aiVector2t& v, TReal f) { return v * (1/f); } // ------------------------------------------------------------------------------------------------ // vector division template -inline aiVector2t operator / ( const aiVector2t& v, const aiVector2t& v2) -{ +inline +aiVector2t operator / ( const aiVector2t& v, const aiVector2t& v2) { return aiVector2t(v.x / v2.x,v.y / v2.y); } // ------------------------------------------------------------------------------------------------ // vector negation template -inline aiVector2t operator - ( const aiVector2t& v) -{ +inline +aiVector2t operator - ( const aiVector2t& v) { return aiVector2t( -v.x, -v.y); }