This source file includes following definitions.
- normalizeOrThrow
- normalizeOrThrow
- normalizeOrThrow
- length
- normalize
- normalizeExc
- normalizeNonNull
- normalized
- normalizedExc
- normalizedNonNull
- length
- normalize
- normalizeExc
- normalizeNonNull
- normalized
- normalizedExc
- normalizedNonNull
- length
- normalize
- normalizeExc
- normalizeNonNull
- normalized
- normalizedExc
- normalizedNonNull
- length
- normalize
- normalizeExc
- normalizeNonNull
- normalized
- normalizedExc
- normalizedNonNull
- length
- normalize
- normalizeExc
- normalizeNonNull
- normalized
- normalizedExc
- normalizedNonNull
- length
- normalize
- normalizeExc
- normalizeNonNull
- normalized
- normalizedExc
- normalizedNonNull
#include "ImathVec.h"
#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
#pragma warning(disable:4290)
#endif
namespace Imath {
namespace
{
template<class T>
bool
normalizeOrThrow(Vec2<T> &v)
{
int axis = -1;
for (int i = 0; i < 2; i ++)
{
if (v[i] != 0)
{
if (axis != -1)
{
throw IntVecNormalizeExc ("Cannot normalize an integer "
"vector unless it is parallel "
"to a principal axis");
}
axis = i;
}
}
v[axis] = (v[axis] > 0) ? 1 : -1;
return true;
}
template<class T>
bool
normalizeOrThrow(Vec3<T> &v)
{
int axis = -1;
for (int i = 0; i < 3; i ++)
{
if (v[i] != 0)
{
if (axis != -1)
{
throw IntVecNormalizeExc ("Cannot normalize an integer "
"vector unless it is parallel "
"to a principal axis");
}
axis = i;
}
}
v[axis] = (v[axis] > 0) ? 1 : -1;
return true;
}
template<class T>
bool
normalizeOrThrow(Vec4<T> &v)
{
int axis = -1;
for (int i = 0; i < 4; i ++)
{
if (v[i] != 0)
{
if (axis != -1)
{
throw IntVecNormalizeExc ("Cannot normalize an integer "
"vector unless it is parallel "
"to a principal axis");
}
axis = i;
}
}
v[axis] = (v[axis] > 0) ? 1 : -1;
return true;
}
}
template <>
short
Vec2<short>::length () const
{
float lenF = Math<float>::sqrt ((float)dot (*this));
short lenS = (short) (lenF + 0.5f);
return lenS;
}
template <>
const Vec2<short> &
Vec2<short>::normalize ()
{
normalizeOrThrow<short>(*this);
return *this;
}
template <>
const Vec2<short> &
Vec2<short>::normalizeExc () throw (Iex::MathExc)
{
if ((x == 0) && (y == 0))
throw NullVecExc ("Cannot normalize null vector.");
normalizeOrThrow<short>(*this);
return *this;
}
template <>
const Vec2<short> &
Vec2<short>::normalizeNonNull ()
{
normalizeOrThrow<short>(*this);
return *this;
}
template <>
Vec2<short>
Vec2<short>::normalized () const
{
Vec2<short> v(*this);
normalizeOrThrow<short>(v);
return v;
}
template <>
Vec2<short>
Vec2<short>::normalizedExc () const throw (Iex::MathExc)
{
if ((x == 0) && (y == 0))
throw NullVecExc ("Cannot normalize null vector.");
Vec2<short> v(*this);
normalizeOrThrow<short>(v);
return v;
}
template <>
Vec2<short>
Vec2<short>::normalizedNonNull () const
{
Vec2<short> v(*this);
normalizeOrThrow<short>(v);
return v;
}
template <>
int
Vec2<int>::length () const
{
float lenF = Math<float>::sqrt ((float)dot (*this));
int lenI = (int) (lenF + 0.5f);
return lenI;
}
template <>
const Vec2<int> &
Vec2<int>::normalize ()
{
normalizeOrThrow<int>(*this);
return *this;
}
template <>
const Vec2<int> &
Vec2<int>::normalizeExc () throw (Iex::MathExc)
{
if ((x == 0) && (y == 0))
throw NullVecExc ("Cannot normalize null vector.");
normalizeOrThrow<int>(*this);
return *this;
}
template <>
const Vec2<int> &
Vec2<int>::normalizeNonNull ()
{
normalizeOrThrow<int>(*this);
return *this;
}
template <>
Vec2<int>
Vec2<int>::normalized () const
{
Vec2<int> v(*this);
normalizeOrThrow<int>(v);
return v;
}
template <>
Vec2<int>
Vec2<int>::normalizedExc () const throw (Iex::MathExc)
{
if ((x == 0) && (y == 0))
throw NullVecExc ("Cannot normalize null vector.");
Vec2<int> v(*this);
normalizeOrThrow<int>(v);
return v;
}
template <>
Vec2<int>
Vec2<int>::normalizedNonNull () const
{
Vec2<int> v(*this);
normalizeOrThrow<int>(v);
return v;
}
template <>
short
Vec3<short>::length () const
{
float lenF = Math<float>::sqrt ((float)dot (*this));
short lenS = (short) (lenF + 0.5f);
return lenS;
}
template <>
const Vec3<short> &
Vec3<short>::normalize ()
{
normalizeOrThrow<short>(*this);
return *this;
}
template <>
const Vec3<short> &
Vec3<short>::normalizeExc () throw (Iex::MathExc)
{
if ((x == 0) && (y == 0) && (z == 0))
throw NullVecExc ("Cannot normalize null vector.");
normalizeOrThrow<short>(*this);
return *this;
}
template <>
const Vec3<short> &
Vec3<short>::normalizeNonNull ()
{
normalizeOrThrow<short>(*this);
return *this;
}
template <>
Vec3<short>
Vec3<short>::normalized () const
{
Vec3<short> v(*this);
normalizeOrThrow<short>(v);
return v;
}
template <>
Vec3<short>
Vec3<short>::normalizedExc () const throw (Iex::MathExc)
{
if ((x == 0) && (y == 0) && (z == 0))
throw NullVecExc ("Cannot normalize null vector.");
Vec3<short> v(*this);
normalizeOrThrow<short>(v);
return v;
}
template <>
Vec3<short>
Vec3<short>::normalizedNonNull () const
{
Vec3<short> v(*this);
normalizeOrThrow<short>(v);
return v;
}
template <>
int
Vec3<int>::length () const
{
float lenF = Math<float>::sqrt ((float)dot (*this));
int lenI = (int) (lenF + 0.5f);
return lenI;
}
template <>
const Vec3<int> &
Vec3<int>::normalize ()
{
normalizeOrThrow<int>(*this);
return *this;
}
template <>
const Vec3<int> &
Vec3<int>::normalizeExc () throw (Iex::MathExc)
{
if ((x == 0) && (y == 0) && (z == 0))
throw NullVecExc ("Cannot normalize null vector.");
normalizeOrThrow<int>(*this);
return *this;
}
template <>
const Vec3<int> &
Vec3<int>::normalizeNonNull ()
{
normalizeOrThrow<int>(*this);
return *this;
}
template <>
Vec3<int>
Vec3<int>::normalized () const
{
Vec3<int> v(*this);
normalizeOrThrow<int>(v);
return v;
}
template <>
Vec3<int>
Vec3<int>::normalizedExc () const throw (Iex::MathExc)
{
if ((x == 0) && (y == 0) && (z == 0))
throw NullVecExc ("Cannot normalize null vector.");
Vec3<int> v(*this);
normalizeOrThrow<int>(v);
return v;
}
template <>
Vec3<int>
Vec3<int>::normalizedNonNull () const
{
Vec3<int> v(*this);
normalizeOrThrow<int>(v);
return v;
}
template <>
short
Vec4<short>::length () const
{
float lenF = Math<float>::sqrt ((float)dot (*this));
short lenS = (short) (lenF + 0.5f);
return lenS;
}
template <>
const Vec4<short> &
Vec4<short>::normalize ()
{
normalizeOrThrow<short>(*this);
return *this;
}
template <>
const Vec4<short> &
Vec4<short>::normalizeExc () throw (Iex::MathExc)
{
if ((x == 0) && (y == 0) && (z == 0) && (w == 0))
throw NullVecExc ("Cannot normalize null vector.");
normalizeOrThrow<short>(*this);
return *this;
}
template <>
const Vec4<short> &
Vec4<short>::normalizeNonNull ()
{
normalizeOrThrow<short>(*this);
return *this;
}
template <>
Vec4<short>
Vec4<short>::normalized () const
{
Vec4<short> v(*this);
normalizeOrThrow<short>(v);
return v;
}
template <>
Vec4<short>
Vec4<short>::normalizedExc () const throw (Iex::MathExc)
{
if ((x == 0) && (y == 0) && (z == 0) && (w == 0))
throw NullVecExc ("Cannot normalize null vector.");
Vec4<short> v(*this);
normalizeOrThrow<short>(v);
return v;
}
template <>
Vec4<short>
Vec4<short>::normalizedNonNull () const
{
Vec4<short> v(*this);
normalizeOrThrow<short>(v);
return v;
}
template <>
int
Vec4<int>::length () const
{
float lenF = Math<float>::sqrt ((float)dot (*this));
int lenI = (int) (lenF + 0.5f);
return lenI;
}
template <>
const Vec4<int> &
Vec4<int>::normalize ()
{
normalizeOrThrow<int>(*this);
return *this;
}
template <>
const Vec4<int> &
Vec4<int>::normalizeExc () throw (Iex::MathExc)
{
if ((x == 0) && (y == 0) && (z == 0) && (w == 0))
throw NullVecExc ("Cannot normalize null vector.");
normalizeOrThrow<int>(*this);
return *this;
}
template <>
const Vec4<int> &
Vec4<int>::normalizeNonNull ()
{
normalizeOrThrow<int>(*this);
return *this;
}
template <>
Vec4<int>
Vec4<int>::normalized () const
{
Vec4<int> v(*this);
normalizeOrThrow<int>(v);
return v;
}
template <>
Vec4<int>
Vec4<int>::normalizedExc () const throw (Iex::MathExc)
{
if ((x == 0) && (y == 0) && (z == 0) && (w == 0))
throw NullVecExc ("Cannot normalize null vector.");
Vec4<int> v(*this);
normalizeOrThrow<int>(v);
return v;
}
template <>
Vec4<int>
Vec4<int>::normalizedNonNull () const
{
Vec4<int> v(*this);
normalizeOrThrow<int>(v);
return v;
}
}