37 #ifndef INCLUDED_IMATHVEC_H 38 #define INCLUDED_IMATHVEC_H 52 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER 55 #pragma warning(disable:4290) 61 template <
class T>
class Vec2;
62 template <
class T>
class Vec3;
63 template <
class T>
class Vec4;
68 template <
class T>
class Vec2
262 T lengthTiny ()
const;
266 template <
class T>
class Vec3 286 Vec3 (T a, T b, T c);
310 template <
class S>
explicit Vec3 (
const Vec4<S> &v);
325 void getValue (S &a, S &b, S &c)
const;
474 T lengthTiny ()
const;
479 template <
class T>
class Vec4 499 Vec4 (T a, T b, T c, T d);
516 template <
class S>
explicit Vec4 (
const Vec3<S> &v);
656 T lengthTiny ()
const;
665 std::ostream & operator << (std::ostream &s, const Vec2<T> &v);
668 std::ostream & operator << (std::ostream &s, const Vec3<T> &v);
671 std::ostream & operator << (std::ostream &s, const Vec4<T> &v);
715 template <> const
Vec2<
short> &
716 Vec2<
short>::normalizeNonNull ();
718 template <>
Vec2<
short>
719 Vec2<
short>::normalized () const;
721 template <>
Vec2<
short>
722 Vec2<
short>::normalizedExc () const throw (Iex::MathExc);
724 template <>
Vec2<
short>
725 Vec2<
short>::normalizedNonNull () const;
731 Vec2<
int>::length () const;
733 template <> const
Vec2<
int> &
734 Vec2<
int>::normalize ();
736 template <> const
Vec2<
int> &
737 Vec2<
int>::normalizeExc () throw (Iex::MathExc);
739 template <> const
Vec2<
int> &
740 Vec2<
int>::normalizeNonNull ();
742 template <>
Vec2<
int>
743 Vec2<
int>::normalized () const;
745 template <>
Vec2<
int>
746 Vec2<
int>::normalizedExc () const throw (Iex::MathExc);
748 template <>
Vec2<
int>
749 Vec2<
int>::normalizedNonNull () const;
755 Vec3<
short>::length () const;
757 template <> const
Vec3<
short> &
758 Vec3<
short>::normalize ();
760 template <> const
Vec3<
short> &
761 Vec3<
short>::normalizeExc () throw (Iex::MathExc);
763 template <> const
Vec3<
short> &
764 Vec3<
short>::normalizeNonNull ();
766 template <>
Vec3<
short>
767 Vec3<
short>::normalized () const;
769 template <>
Vec3<
short>
770 Vec3<
short>::normalizedExc () const throw (Iex::MathExc);
772 template <>
Vec3<
short>
773 Vec3<
short>::normalizedNonNull () const;
779 Vec3<
int>::length () const;
781 template <> const
Vec3<
int> &
782 Vec3<
int>::normalize ();
784 template <> const
Vec3<
int> &
785 Vec3<
int>::normalizeExc () throw (Iex::MathExc);
787 template <> const
Vec3<
int> &
788 Vec3<
int>::normalizeNonNull ();
790 template <>
Vec3<
int>
791 Vec3<
int>::normalized () const;
793 template <>
Vec3<
int>
794 Vec3<
int>::normalizedExc () const throw (Iex::MathExc);
796 template <>
Vec3<
int>
797 Vec3<
int>::normalizedNonNull () const;
802 Vec4<
short>::length () const;
804 template <> const
Vec4<
short> &
805 Vec4<
short>::normalize ();
807 template <> const
Vec4<
short> &
808 Vec4<
short>::normalizeExc () throw (Iex::MathExc);
810 template <> const
Vec4<
short> &
811 Vec4<
short>::normalizeNonNull ();
813 template <>
Vec4<
short>
814 Vec4<
short>::normalized () const;
816 template <>
Vec4<
short>
817 Vec4<
short>::normalizedExc () const throw (Iex::MathExc);
819 template <>
Vec4<
short>
820 Vec4<
short>::normalizedNonNull () const;
826 Vec4<
int>::length () const;
828 template <> const
Vec4<
int> &
829 Vec4<
int>::normalize ();
831 template <> const
Vec4<
int> &
832 Vec4<
int>::normalizeExc () throw (Iex::MathExc);
834 template <> const
Vec4<
int> &
835 Vec4<
int>::normalizeNonNull ();
837 template <>
Vec4<
int>
838 Vec4<
int>::normalized () const;
840 template <>
Vec4<
int>
841 Vec4<
int>::normalizedExc () const throw (Iex::MathExc);
843 template <>
Vec4<
int>
844 Vec4<
int>::normalizedNonNull () const;
960 return (
const T *) &x;
968 return x == v.x && y == v.y;
976 return x != v.x || y != v.y;
983 for (
int i = 0; i < 2; i++)
994 for (
int i = 0; i < 2; i++)
1005 return x * v.x + y * v.y;
1019 return x * v.y - y * v.x;
1027 return x * v.y - y * v.x;
1043 return Vec2 (x + v.x, y + v.y);
1059 return Vec2 (x - v.x, y - v.y);
1066 return Vec2 (-x, -y);
1100 return Vec2 (x * v.x, y * v.y);
1107 return Vec2 (x * a, y * a);
1132 return Vec2 (x / v.x, y / v.y);
1139 return Vec2 (x / a, y / a);
1146 T absX = (x >= 0)? x: -x;
1147 T absY = (y >= 0)? y: -y;
1173 T length2 = dot (*
this);
1176 return lengthTiny();
1216 throw NullVecExc (
"Cannot normalize null vector.");
1241 return Vec2 (T (0));
1243 return Vec2 (x / l, y / l);
1253 throw NullVecExc (
"Cannot normalize null vector.");
1255 return Vec2 (x / l, y / l);
1264 return Vec2 (x / l, y / l);
1357 T absW = (vw >= 0)? vw: -vw;
1361 T m = baseTypeMax() * absW;
1363 if (vx <= -m || vx >= m || vy <= -m || vy >= m || vz <= -m || vz >= m)
1364 throw InfPointExc (
"Cannot normalize point at infinity.");
1423 return (
const T *) &x;
1431 return x == v.
x && y == v.
y && z == v.
z;
1439 return x != v.
x || y != v.
y || z != v.
z;
1446 for (
int i = 0; i < 3; i++)
1457 for (
int i = 0; i < 3; i++)
1468 return x * v.
x + y * v.
y + z * v.
z;
1482 return Vec3 (y * v.
z - z * v.
y,
1491 T a = y * v.
z - z * v.
y;
1492 T b = z * v.
x - x * v.
z;
1493 T c = x * v.
y - y * v.
x;
1504 return Vec3 (y * v.
z - z * v.
y,
1523 return Vec3 (x + v.
x, y + v.
y, z + v.
z);
1540 return Vec3 (x - v.
x, y - v.
y, z - v.
z);
1547 return Vec3 (-x, -y, -z);
1584 return Vec3 (x * v.
x, y * v.
y, z * v.
z);
1591 return Vec3 (x * a, y * a, z * a);
1618 return Vec3 (x / v.
x, y / v.
y, z / v.
z);
1625 return Vec3 (x / a, y / a, z / a);
1632 T absX = (x >= 0)? x: -x;
1633 T absY = (y >= 0)? y: -y;
1634 T absZ = (z >= 0)? z: -z;
1657 return max *
Math<T>::sqrt (absX * absX + absY * absY + absZ * absZ);
1664 T length2 = dot (*
this);
1667 return lengthTiny();
1708 throw NullVecExc (
"Cannot normalize null vector.");
1735 return Vec3 (T (0));
1737 return Vec3 (x / l, y / l, z / l);
1747 throw NullVecExc (
"Cannot normalize null vector.");
1749 return Vec3 (x / l, y / l, z / l);
1758 return Vec3 (x / l, y / l, z / l);
1852 return x == v.
x && y == v.
y && z == v.
z && w == v.
w;
1860 return x != v.
x || y != v.
y || z != v.
z || w != v.
w;
1867 for (
int i = 0; i < 4; i++)
1878 for (
int i = 0; i < 4; i++)
1889 return x * v.
x + y * v.
y + z * v.
z + w * v.
w;
1915 return Vec4 (x + v.
x, y + v.
y, z + v.
z, w + v.
w);
1933 return Vec4 (x - v.
x, y - v.
y, z - v.
z, w - v.
w);
1940 return Vec4 (-x, -y, -z, -w);
1980 return Vec4 (x * v.
x, y * v.
y, z * v.
z, w * v.
w);
1987 return Vec4 (x * a, y * a, z * a, w * a);
2016 return Vec4 (x / v.
x, y / v.
y, z / v.
z, w / v.
w);
2023 return Vec4 (x / a, y / a, z / a, w / a);
2030 T absX = (x >= 0)? x: -x;
2031 T absY = (y >= 0)? y: -y;
2032 T absZ = (z >= 0)? z: -z;
2033 T absW = (w >= 0)? w: -w;
2061 Math<T>::sqrt (absX * absX + absY * absY + absZ * absZ + absW * absW);
2068 T length2 = dot (*
this);
2071 return lengthTiny();
2113 throw NullVecExc (
"Cannot normalize null vector.");
2142 return Vec4 (T (0));
2144 return Vec4 (x / l, y / l, z / l, w / l);
2154 throw NullVecExc (
"Cannot normalize null vector.");
2156 return Vec4 (x / l, y / l, z / l, w / l);
2165 return Vec4 (x / l, y / l, z / l, w / l);
2174 operator << (std::ostream &s, const Vec2<T> &v)
2176 return s <<
'(' << v.x <<
' ' << v.y <<
')';
2181 operator << (std::ostream &s, const Vec3<T> &v)
2183 return s <<
'(' << v.x <<
' ' << v.y <<
' ' << v.z <<
')';
2188 operator << (std::ostream &s, const Vec4<T> &v)
2190 return s <<
'(' << v.x <<
' ' << v.y <<
' ' << v.z <<
' ' << v.w <<
')';
2202 return Vec2<T> (a * v.x, a * v.y);
2216 return Vec4<T> (a * v.
x, a * v.
y, a * v.
z, a * v.
w);
2220 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER 2221 #pragma warning(pop) const Vec4 & operator-=(const Vec4 &v)
Definition: ImathVec.h:1920
const Vec3 & normalizeNonNull()
Definition: ImathVec.h:1719
bool equalWithAbsError(const Vec4< T > &v, T e) const
Definition: ImathVec.h:1865
Vec3()
Definition: ImathVec.h:1288
T x
Definition: ImathVec.h:76
static unsigned int dimensions()
Definition: ImathVec.h:239
static T baseTypeEpsilon()
Definition: ImathVec.h:461
const Vec2 & operator-=(const Vec2 &v)
Definition: ImathVec.h:1048
static T baseTypeSmallest()
Definition: ImathVec.h:460
T dot(const Vec3 &v) const
Definition: ImathVec.h:1466
const Vec2 & negate()
Definition: ImathVec.h:1071
const Vec3 & operator=(const Vec3 &v)
Definition: ImathVec.h:1330
const Vec3 & operator+=(const Vec3 &v)
Definition: ImathVec.h:1511
bool equalWithAbsError(const Vec2< T > &v, T e) const
Definition: ImathVec.h:981
T y
Definition: ImathVec.h:76
const Vec3 & operator-=(const Vec3 &v)
Definition: ImathVec.h:1528
T length2() const
Definition: ImathVec.h:2078
Vec4< double > V4d
Definition: ImathVec.h:697
InfException
Definition: ImathVec.h:65
Definition: ImathFrame.h:42
void setValue(S a, S b)
Definition: ImathVec.h:916
Vec2 operator*(const Vec2 &v) const
Definition: ImathVec.h:1098
const Vec4 & operator/=(const Vec4 &v)
Definition: ImathVec.h:1992
T & operator[](int i)
Definition: ImathVec.h:1768
T dot(const Vec4 &v) const
Definition: ImathVec.h:1887
Vec3< int > V3i
Definition: ImathVec.h:691
T length() const
Definition: ImathVec.h:1662
T operator^(const Vec3 &v) const
Definition: ImathVec.h:1473
const Vec4 & normalize()
Definition: ImathVec.h:2085
const Vec4 & operator+=(const Vec4 &v)
Definition: ImathVec.h:1902
const Vec3 & operator/=(const Vec3 &v)
Definition: ImathVec.h:1596
T BaseType
Definition: ImathVec.h:258
T dot(const Vec2 &v) const
Definition: ImathVec.h:1003
Definition: ImathVec.h:63
Vec3 operator%(const Vec3 &v) const
Definition: ImathVec.h:1502
const Vec4 & normalizeNonNull()
Definition: ImathVec.h:2125
T cross(const Vec2 &v) const
Definition: ImathVec.h:1017
Vec3 operator-() const
Definition: ImathVec.h:1545
const Vec4 & negate()
Definition: ImathVec.h:1945
bool equalWithRelError(const Vec2< T > &v, T e) const
Definition: ImathVec.h:992
void setValue(S a, S b, S c)
Definition: ImathVec.h:1375
Vec3< T > normalizedExc() const
Definition: ImathVec.h:1742
bool operator==(const Vec2< S > &v) const
Definition: ImathVec.h:966
T & operator[](int i)
Definition: ImathVec.h:1274
static T baseTypeMax()
Definition: ImathVec.h:641
Definition: ImathLimits.h:117
bool operator!=(const Vec3< S > &v) const
Definition: ImathVec.h:1437
bool equalWithRelError(const Vec4< T > &v, T e) const
Definition: ImathVec.h:1876
Vec3 operator*(const Vec3 &v) const
Definition: ImathVec.h:1582
Vec2< double > V2d
Definition: ImathVec.h:689
T BaseType
Definition: ImathVec.h:470
T x
Definition: ImathVec.h:274
Vec3 operator/(const Vec3 &v) const
Definition: ImathVec.h:1616
bool equalWithAbsError(T x1, T x2, T e)
Definition: ImathMath.h:191
Vec4< T > normalizedNonNull() const
Definition: ImathVec.h:2162
const Vec4 & normalizeExc()
Definition: ImathVec.h:2108
T y
Definition: ImathVec.h:274
Vec4()
Definition: ImathVec.h:1782
static T baseTypeSmallest()
Definition: ImathVec.h:248
const Vec3 & normalize()
Definition: ImathVec.h:1681
Vec3 cross(const Vec3 &v) const
Definition: ImathVec.h:1480
Vec4< T > normalized() const
Definition: ImathVec.h:2137
T length() const
Definition: ImathVec.h:1171
Vec4 operator-() const
Definition: ImathVec.h:1938
bool equalWithAbsError(const Vec3< T > &v, T e) const
Definition: ImathVec.h:1444
static T baseTypeMin()
Definition: ImathVec.h:640
T length2() const
Definition: ImathVec.h:1183
T * getValue()
Definition: ImathVec.h:1414
Vec4< float > V4f
Definition: ImathVec.h:696
Vec2< int > V2i
Definition: ImathVec.h:687
T operator%(const Vec2 &v) const
Definition: ImathVec.h:1025
T z
Definition: ImathVec.h:274
Vec4< short > V4s
Definition: ImathVec.h:694
Vec2 operator-() const
Definition: ImathVec.h:1064
Vec3< T > normalized() const
Definition: ImathVec.h:1730
static T baseTypeMin()
Definition: ImathVec.h:458
Vec3< T > normalizedNonNull() const
Definition: ImathVec.h:1755
bool equalWithRelError(T x1, T x2, T e)
Definition: ImathMath.h:199
Definition: ImathVec.h:65
Definition: ImathVec.h:61
Vec4 operator+(const Vec4 &v) const
Definition: ImathVec.h:1913
T x
Definition: ImathVec.h:487
static unsigned int dimensions()
Definition: ImathVec.h:451
Vec2 operator/(const Vec2 &v) const
Definition: ImathVec.h:1130
static T baseTypeMax()
Definition: ImathVec.h:247
Vec3< short > V3s
Definition: ImathVec.h:690
T & operator[](int i)
Definition: ImathVec.h:853
static T baseTypeEpsilon()
Definition: ImathVec.h:249
T length() const
Definition: ImathVec.h:2066
Vec4< int > V4i
Definition: ImathVec.h:695
Vec3< float > V3f
Definition: ImathVec.h:692
Vec4 operator/(const Vec4 &v) const
Definition: ImathVec.h:2014
Vec4 operator*(const Vec4 &v) const
Definition: ImathVec.h:1978
Vec2< T > normalizedNonNull() const
Definition: ImathVec.h:1261
T length2() const
Definition: ImathVec.h:1674
const Vec2 & normalizeNonNull()
Definition: ImathVec.h:1226
T operator^(const Vec4 &v) const
Definition: ImathVec.h:1894
const Vec2 & operator/=(const Vec2 &v)
Definition: ImathVec.h:1112
T * getValue()
Definition: ImathVec.h:951
Vec2 operator+(const Vec2 &v) const
Definition: ImathVec.h:1041
Vec2()
Definition: ImathVec.h:867
const Vec2 & operator+=(const Vec2 &v)
Definition: ImathVec.h:1032
static T baseTypeEpsilon()
Definition: ImathVec.h:643
const Vec3 & negate()
Definition: ImathVec.h:1552
Definition: ImathBox.h:67
T operator^(const Vec2 &v) const
Definition: ImathVec.h:1010
Vec3< double > V3d
Definition: ImathVec.h:693
T y
Definition: ImathVec.h:487
const Vec3 & normalizeExc()
Definition: ImathVec.h:1703
bool operator==(const Vec4< S > &v) const
Definition: ImathVec.h:1850
const Vec2 & normalizeExc()
Definition: ImathVec.h:1211
T z
Definition: ImathVec.h:487
Vec4< T > normalizedExc() const
Definition: ImathVec.h:2149
Vec2< T > normalized() const
Definition: ImathVec.h:1236
T w
Definition: ImathVec.h:487
Color4< T > operator*(S a, const Color4< T > &v)
Definition: ImathColor.h:727
Vec2< float > V2f
Definition: ImathVec.h:688
bool equalWithRelError(const Vec3< T > &v, T e) const
Definition: ImathVec.h:1455
const Vec3 & operator%=(const Vec3 &v)
Definition: ImathVec.h:1489
static T sqrt(T x)
Definition: ImathMath.h:114
const Vec4 & operator=(const Vec4 &v)
Definition: ImathVec.h:1827
static unsigned int dimensions()
Definition: ImathVec.h:633
Vec2< T > normalizedExc() const
Definition: ImathVec.h:1248
const Vec2 & operator=(const Vec2 &v)
Definition: ImathVec.h:906
const Vec2 & operator*=(const Vec2 &v)
Definition: ImathVec.h:1080
const Vec4 & operator*=(const Vec4 &v)
Definition: ImathVec.h:1956
static T baseTypeSmallest()
Definition: ImathVec.h:642
bool operator==(const Vec3< S > &v) const
Definition: ImathVec.h:1429
bool operator!=(const Vec2< S > &v) const
Definition: ImathVec.h:974
bool operator!=(const Vec4< S > &v) const
Definition: ImathVec.h:1858
static T baseTypeMax()
Definition: ImathVec.h:459
Vec3 operator+(const Vec3 &v) const
Definition: ImathVec.h:1521
T BaseType
Definition: ImathVec.h:652
static T baseTypeMin()
Definition: ImathVec.h:246
const Vec3 & operator*=(const Vec3 &v)
Definition: ImathVec.h:1562
Vec2< short > V2s
Definition: ImathVec.h:686
const Vec2 & normalize()
Definition: ImathVec.h:1190