Rewrote the Vec *= Vec and Vec /= Vec implementations using inline Vec componentMultiply(Vec,Vec) and Vec componentDivide(Vec,Vec) to avoid confusion about the what the operation does.

This commit is contained in:
Robert Osfield 2009-11-24 13:28:07 +00:00
parent 3599be9708
commit 383a5222bd
9 changed files with 111 additions and 140 deletions

View File

@ -94,14 +94,6 @@ class Vec2d
return *this; return *this;
} }
/** Unary multiply by vector. */
inline Vec2d& operator *= (const Vec2d& rhs)
{
_v[0]*=rhs[0];
_v[1]*=rhs[1];
return *this;
}
/** Divide by scalar. */ /** Divide by scalar. */
inline const Vec2d operator / (value_type rhs) const inline const Vec2d operator / (value_type rhs) const
{ {
@ -116,14 +108,6 @@ class Vec2d
return *this; return *this;
} }
/** Unary divide by vector. */
inline Vec2d& operator /= (const Vec2d& rhs)
{
_v[0]/=rhs[0];
_v[1]/=rhs[1];
return *this;
}
/** Binary vector add. */ /** Binary vector add. */
inline const Vec2d operator + (const Vec2d& rhs) const inline const Vec2d operator + (const Vec2d& rhs) const
{ {
@ -189,5 +173,18 @@ class Vec2d
}; // end of class Vec2d }; // end of class Vec2d
/** multiply by vector components. */
inline Vec2d componentMultiply(const Vec2d& lhs, const Vec2d& rhs)
{
return Vec2d(lhs[0]*rhs[0], lhs[1]*rhs[1]);
}
/** divide rhs components by rhs vector components. */
inline Vec2d componentDivide(const Vec2d& lhs, const Vec2d& rhs)
{
return Vec2d(lhs[0]/rhs[0], lhs[1]/rhs[1]);
}
} // end of namespace osg } // end of namespace osg
#endif #endif

View File

@ -91,14 +91,6 @@ class Vec2f
return *this; return *this;
} }
/** Unary multiply by vector. */
inline Vec2f& operator *= (const Vec2f& rhs)
{
_v[0]*=rhs[0];
_v[1]*=rhs[1];
return *this;
}
/** Divide by scalar. */ /** Divide by scalar. */
inline const Vec2f operator / (value_type rhs) const inline const Vec2f operator / (value_type rhs) const
{ {
@ -113,14 +105,6 @@ class Vec2f
return *this; return *this;
} }
/** Unary divide by vector. */
inline Vec2f& operator /= (const Vec2f& rhs)
{
_v[0]/=rhs[0];
_v[1]/=rhs[1];
return *this;
}
/** Binary vector add. */ /** Binary vector add. */
inline const Vec2f operator + (const Vec2f& rhs) const inline const Vec2f operator + (const Vec2f& rhs) const
{ {
@ -186,6 +170,18 @@ class Vec2f
}; // end of class Vec2f }; // end of class Vec2f
/** multiply by vector components. */
inline Vec2f componentMultiply(const Vec2f& lhs, const Vec2f& rhs)
{
return Vec2f(lhs[0]*rhs[0], lhs[1]*rhs[1]);
}
/** divide rhs components by rhs vector components. */
inline Vec2f componentDivide(const Vec2f& lhs, const Vec2f& rhs)
{
return Vec2f(lhs[0]/rhs[0], lhs[1]/rhs[1]);
}
} // end of namespace osg } // end of namespace osg
#endif #endif

View File

@ -98,13 +98,6 @@ class Vec2s
return Vec2s(_v[0]*rhs._v[0], _v[1]*rhs._v[1]); return Vec2s(_v[0]*rhs._v[0], _v[1]*rhs._v[1]);
} }
inline Vec2s& operator *= (const Vec2s& rhs)
{
_v[0] *= rhs._v[0];
_v[1] *= rhs._v[1];
return *this;
}
inline Vec2s operator + (const Vec2s& rhs) const inline Vec2s operator + (const Vec2s& rhs) const
{ {
return Vec2s(_v[0]+rhs._v[0], _v[1]+rhs._v[1]); return Vec2s(_v[0]+rhs._v[0], _v[1]+rhs._v[1]);
@ -138,5 +131,18 @@ class Vec2s
}; // end of class Vec2s }; // end of class Vec2s
/** multiply by vector components. */
inline Vec2s componentMultiply(const Vec2s& lhs, const Vec2s& rhs)
{
return Vec2s(lhs[0]*rhs[0], lhs[1]*rhs[1]);
}
/** divide rhs components by rhs vector components. */
inline Vec2s componentDivide(const Vec2s& lhs, const Vec2s& rhs)
{
return Vec2s(lhs[0]/rhs[0], lhs[1]/rhs[1]);
}
} // end of namespace osg } // end of namespace osg
#endif #endif

View File

@ -121,15 +121,6 @@ class Vec3d
return *this; return *this;
} }
/** Unary multiply by vector. */
inline Vec3d& operator *= (const Vec3d& rhs)
{
_v[0]*=rhs[0];
_v[1]*=rhs[1];
_v[2]*=rhs[2];
return *this;
}
/** Divide by scalar. */ /** Divide by scalar. */
inline const Vec3d operator / (value_type rhs) const inline const Vec3d operator / (value_type rhs) const
{ {
@ -145,15 +136,6 @@ class Vec3d
return *this; return *this;
} }
/** Unary divide by vector. */
inline Vec3d& operator /= (const Vec3d& rhs)
{
_v[0]/=rhs[0];
_v[1]/=rhs[1];
_v[2]/=rhs[2];
return *this;
}
/** Binary vector add. */ /** Binary vector add. */
inline const Vec3d operator + (const Vec3d& rhs) const inline const Vec3d operator + (const Vec3d& rhs) const
{ {
@ -222,6 +204,18 @@ class Vec3d
}; // end of class Vec3d }; // end of class Vec3d
/** multiply by vector components. */
inline Vec3d componentMultiply(const Vec3d& lhs, const Vec3d& rhs)
{
return Vec3d(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
}
/** divide rhs components by rhs vector components. */
inline Vec3d componentDivide(const Vec3d& lhs, const Vec3d& rhs)
{
return Vec3d(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
}
} // end of namespace osg } // end of namespace osg
#endif #endif

View File

@ -116,15 +116,6 @@ class Vec3f
return *this; return *this;
} }
/** Unary multiply by vector. */
inline Vec3f& operator *= (const Vec3f& rhs)
{
_v[0]*=rhs[0];
_v[1]*=rhs[1];
_v[2]*=rhs[2];
return *this;
}
/** Divide by scalar. */ /** Divide by scalar. */
inline const Vec3f operator / (value_type rhs) const inline const Vec3f operator / (value_type rhs) const
{ {
@ -140,15 +131,6 @@ class Vec3f
return *this; return *this;
} }
/** Unary divide by vector. */
inline Vec3f& operator /= (const Vec3f& rhs)
{
_v[0]/=rhs[0];
_v[1]/=rhs[1];
_v[2]/=rhs[2];
return *this;
}
/** Binary vector add. */ /** Binary vector add. */
inline const Vec3f operator + (const Vec3f& rhs) const inline const Vec3f operator + (const Vec3f& rhs) const
{ {
@ -217,6 +199,17 @@ class Vec3f
}; // end of class Vec3f }; // end of class Vec3f
/** multiply by vector components. */
inline Vec3f componentMultiply(const Vec3f& lhs, const Vec3f& rhs)
{
return Vec3f(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
}
/** divide rhs components by rhs vector components. */
inline Vec3f componentDivide(const Vec3f& lhs, const Vec3f& rhs)
{
return Vec3f(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
}
const Vec3f X_AXIS(1.0,0.0,0.0); const Vec3f X_AXIS(1.0,0.0,0.0);
const Vec3f Y_AXIS(0.0,1.0,0.0); const Vec3f Y_AXIS(0.0,1.0,0.0);

View File

@ -111,17 +111,6 @@ class Vec3s
return Vec3s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]); return Vec3s(_v[0]*rhs._v[0], _v[1]*rhs._v[1], _v[2]*rhs._v[2]);
} }
/** Unary vector multiply. Slightly more efficient because no temporary
* intermediate object.
*/
inline Vec3s& operator *= (const Vec3s& rhs)
{
_v[0] *= rhs._v[0];
_v[1] *= rhs._v[1];
_v[2] *= rhs._v[2];
return *this;
}
/** Binary vector add. */ /** Binary vector add. */
inline Vec3s operator + (const Vec3s& rhs) const inline Vec3s operator + (const Vec3s& rhs) const
{ {
@ -162,6 +151,19 @@ class Vec3s
}; // end of class Vec3s }; // end of class Vec3s
/** multiply by vector components. */
inline Vec3s componentMultiply(const Vec3s& lhs, const Vec3s& rhs)
{
return Vec3s(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2]);
}
/** divide rhs components by rhs vector components. */
inline Vec3s componentDivide(const Vec3s& lhs, const Vec3s& rhs)
{
return Vec3s(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2]);
}
} // end of namespace osg } // end of namespace osg
#endif #endif

View File

@ -151,16 +151,6 @@ class Vec4d
return *this; return *this;
} }
/** Unary multiply by vector. */
inline Vec4d& operator *= (const Vec4d& rhs)
{
_v[0]*=rhs[0];
_v[1]*=rhs[1];
_v[2]*=rhs[2];
_v[3]*=rhs[3];
return *this;
}
/** Divide by scalar. */ /** Divide by scalar. */
inline Vec4d operator / (value_type rhs) const inline Vec4d operator / (value_type rhs) const
{ {
@ -177,16 +167,6 @@ class Vec4d
return *this; return *this;
} }
/** Unary divide by vector. */
inline Vec4d& operator /= (const Vec4d& rhs)
{
_v[0]/=rhs[0];
_v[1]/=rhs[1];
_v[2]/=rhs[2];
_v[3]/=rhs[3];
return *this;
}
/** Binary vector add. */ /** Binary vector add. */
inline Vec4d operator + (const Vec4d& rhs) const inline Vec4d operator + (const Vec4d& rhs) const
{ {
@ -299,6 +279,18 @@ inline Vec4d::value_type operator * (const Vec4f& lhs,const Vec3d& rhs)
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3]; return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3];
} }
/** multiply by vector components. */
inline Vec4d componentMultiply(const Vec4d& lhs, const Vec4d& rhs)
{
return Vec4d(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2], lhs[3]*rhs[3]);
}
/** divide rhs components by rhs vector components. */
inline Vec4d componentDivide(const Vec4d& lhs, const Vec4d& rhs)
{
return Vec4d(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2], lhs[3]/rhs[3]);
}
} // end of namespace osg } // end of namespace osg
#endif #endif

View File

@ -147,16 +147,6 @@ class Vec4f
return *this; return *this;
} }
/** Unary multiply by vector. */
inline Vec4f& operator *= (const Vec4f& rhs)
{
_v[0]*=rhs[0];
_v[1]*=rhs[1];
_v[2]*=rhs[2];
_v[3]*=rhs[3];
return *this;
}
/** Divide by scalar. */ /** Divide by scalar. */
inline Vec4f operator / (value_type rhs) const inline Vec4f operator / (value_type rhs) const
{ {
@ -173,16 +163,6 @@ class Vec4f
return *this; return *this;
} }
/** Unary divide by vector. */
inline Vec4f& operator /= (const Vec4f& rhs)
{
_v[0]/=rhs[0];
_v[1]/=rhs[1];
_v[2]/=rhs[2];
_v[3]/=rhs[3];
return *this;
}
/** Binary vector add. */ /** Binary vector add. */
inline Vec4f operator + (const Vec4f& rhs) const inline Vec4f operator + (const Vec4f& rhs) const
{ {
@ -256,8 +236,6 @@ class Vec4f
}; // end of class Vec4f }; // end of class Vec4f
/** Compute the dot product of a (Vec3,1.0) and a Vec4f. */ /** Compute the dot product of a (Vec3,1.0) and a Vec4f. */
inline Vec4f::value_type operator * (const Vec3f& lhs,const Vec4f& rhs) inline Vec4f::value_type operator * (const Vec3f& lhs,const Vec4f& rhs)
{ {
@ -270,6 +248,18 @@ inline Vec4f::value_type operator * (const Vec4f& lhs,const Vec3f& rhs)
return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3]; return lhs[0]*rhs[0]+lhs[1]*rhs[1]+lhs[2]*rhs[2]+lhs[3];
} }
/** multiply by vector components. */
inline Vec4f componentMultiply(const Vec4f& lhs, const Vec4f& rhs)
{
return Vec4f(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2], lhs[3]*rhs[3]);
}
/** divide rhs components by rhs vector components. */
inline Vec4f componentDivide(const Vec4f& lhs, const Vec4f& rhs)
{
return Vec4f(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2], lhs[3]/rhs[3]);
}
} // end of namespace osg } // end of namespace osg
#endif #endif

View File

@ -129,18 +129,6 @@ class Vec4s
_v[2]*rhs._v[2], _v[3]*rhs._v[3]); _v[2]*rhs._v[2], _v[3]*rhs._v[3]);
} }
/** Unary vector multiply. Slightly more efficient because no temporary
* intermediate object.
*/
inline Vec4s& operator *= (const Vec4s& rhs)
{
_v[0] *= rhs._v[0];
_v[1] *= rhs._v[1];
_v[2] *= rhs._v[2];
_v[3] *= rhs._v[3];
return *this;
}
/** Binary vector add. */ /** Binary vector add. */
inline Vec4s operator + (const Vec4s& rhs) const inline Vec4s operator + (const Vec4s& rhs) const
{ {
@ -185,6 +173,19 @@ class Vec4s
}; // end of class Vec4s }; // end of class Vec4s
/** multiply by vector components. */
inline Vec4s componentMultiply(const Vec4s& lhs, const Vec4s& rhs)
{
return Vec4s(lhs[0]*rhs[0], lhs[1]*rhs[1], lhs[2]*rhs[2], lhs[3]*rhs[3]);
}
/** divide rhs components by rhs vector components. */
inline Vec4s componentDivide(const Vec4s& lhs, const Vec4s& rhs)
{
return Vec4s(lhs[0]/rhs[0], lhs[1]/rhs[1], lhs[2]/rhs[2], lhs[3]/rhs[3]);
}
} // end of namespace osg } // end of namespace osg
#endif #endif