fix misalignment in vector2 [] operator, the non-const one.
parent
151d71bc69
commit
e0649b6822
|
@ -60,24 +60,28 @@ aiVector2t<TReal>::operator aiVector2t<TOther> () const {
|
|||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
void aiVector2t<TReal>::Set( TReal pX, TReal pY) {
|
||||
x = pX; y = pY;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
TReal aiVector2t<TReal>::SquareLength() const {
|
||||
return x*x + y*y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
TReal aiVector2t<TReal>::Length() const {
|
||||
return std::sqrt( SquareLength());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
aiVector2t<TReal>& aiVector2t<TReal>::Normalize() {
|
||||
*this /= Length();
|
||||
return *this;
|
||||
|
@ -85,6 +89,7 @@ aiVector2t<TReal>& aiVector2t<TReal>::Normalize() {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
const aiVector2t<TReal>& aiVector2t<TReal>::operator += (const aiVector2t& o) {
|
||||
x += o.x; y += o.y;
|
||||
return *this;
|
||||
|
@ -92,6 +97,7 @@ const aiVector2t<TReal>& aiVector2t<TReal>::operator += (const aiVector2t& o) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
const aiVector2t<TReal>& aiVector2t<TReal>::operator -= (const aiVector2t& o) {
|
||||
x -= o.x; y -= o.y;
|
||||
return *this;
|
||||
|
@ -99,6 +105,7 @@ const aiVector2t<TReal>& aiVector2t<TReal>::operator -= (const aiVector2t& o) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
const aiVector2t<TReal>& aiVector2t<TReal>::operator *= (TReal f) {
|
||||
x *= f; y *= f;
|
||||
return *this;
|
||||
|
@ -106,6 +113,7 @@ const aiVector2t<TReal>& aiVector2t<TReal>::operator *= (TReal f) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
const aiVector2t<TReal>& aiVector2t<TReal>::operator /= (TReal f) {
|
||||
x /= f; y /= f;
|
||||
return *this;
|
||||
|
@ -113,6 +121,7 @@ const aiVector2t<TReal>& aiVector2t<TReal>::operator /= (TReal f) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
TReal aiVector2t<TReal>::operator[](unsigned int i) const {
|
||||
switch (i) {
|
||||
case 0:
|
||||
|
@ -127,24 +136,36 @@ TReal aiVector2t<TReal>::operator[](unsigned int i) const {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
TReal& aiVector2t<TReal>::operator[](unsigned int i) {
|
||||
return *(&x + i);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
bool aiVector2t<TReal>::operator== (const aiVector2t& other) const {
|
||||
return x == other.x && y == other.y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
bool aiVector2t<TReal>::operator!= (const aiVector2t& other) const {
|
||||
return x != other.x || y != other.y;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
template<typename TReal>
|
||||
inline
|
||||
bool aiVector2t<TReal>::Equal(const aiVector2t& other, TReal epsilon) const {
|
||||
return
|
||||
std::abs(x - other.x) <= epsilon &&
|
||||
|
@ -153,6 +174,7 @@ bool aiVector2t<TReal>::Equal(const aiVector2t& other, TReal epsilon) const {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
aiVector2t<TReal>& aiVector2t<TReal>::operator= (TReal f) {
|
||||
x = y = f;
|
||||
return *this;
|
||||
|
@ -160,6 +182,7 @@ aiVector2t<TReal>& aiVector2t<TReal>::operator= (TReal f) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <typename TReal>
|
||||
inline
|
||||
const aiVector2t<TReal> aiVector2t<TReal>::SymMul(const aiVector2t& o) {
|
||||
return aiVector2t(x*o.x,y*o.y);
|
||||
}
|
||||
|
@ -168,65 +191,64 @@ const aiVector2t<TReal> aiVector2t<TReal>::SymMul(const aiVector2t& o) {
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
// symmetric addition
|
||||
template <typename TReal>
|
||||
inline aiVector2t<TReal> operator + (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2)
|
||||
{
|
||||
inline
|
||||
inline aiVector2t<TReal> operator + (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
|
||||
return aiVector2t<TReal>( v1.x + v2.x, v1.y + v2.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// symmetric subtraction
|
||||
template <typename TReal>
|
||||
inline aiVector2t<TReal> operator - (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2)
|
||||
{
|
||||
inline
|
||||
aiVector2t<TReal> operator - (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
|
||||
return aiVector2t<TReal>( v1.x - v2.x, v1.y - v2.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// scalar product
|
||||
template <typename TReal>
|
||||
inline TReal operator * (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2)
|
||||
{
|
||||
inline
|
||||
TReal operator * (const aiVector2t<TReal>& v1, const aiVector2t<TReal>& v2) {
|
||||
return v1.x*v2.x + v1.y*v2.y;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// scalar multiplication
|
||||
template <typename TReal>
|
||||
inline aiVector2t<TReal> operator * ( TReal f, const aiVector2t<TReal>& v)
|
||||
{
|
||||
inline
|
||||
aiVector2t<TReal> operator * ( TReal f, const aiVector2t<TReal>& v) {
|
||||
return aiVector2t<TReal>( f*v.x, f*v.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// and the other way around
|
||||
template <typename TReal>
|
||||
inline aiVector2t<TReal> operator * ( const aiVector2t<TReal>& v, TReal f)
|
||||
{
|
||||
inline
|
||||
aiVector2t<TReal> operator * ( const aiVector2t<TReal>& v, TReal f) {
|
||||
return aiVector2t<TReal>( f*v.x, f*v.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// scalar division
|
||||
template <typename TReal>
|
||||
inline aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, TReal f)
|
||||
{
|
||||
|
||||
inline
|
||||
aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, TReal f) {
|
||||
return v * (1/f);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// vector division
|
||||
template <typename TReal>
|
||||
inline aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, const aiVector2t<TReal>& v2)
|
||||
{
|
||||
inline
|
||||
aiVector2t<TReal> operator / ( const aiVector2t<TReal>& v, const aiVector2t<TReal>& v2) {
|
||||
return aiVector2t<TReal>(v.x / v2.x,v.y / v2.y);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// vector negation
|
||||
template <typename TReal>
|
||||
inline aiVector2t<TReal> operator - ( const aiVector2t<TReal>& v)
|
||||
{
|
||||
inline
|
||||
aiVector2t<TReal> operator - ( const aiVector2t<TReal>& v) {
|
||||
return aiVector2t<TReal>( -v.x, -v.y);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue