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