37 #ifndef INCLUDED_IMATHVEC_H
38 #define INCLUDED_IMATHVEC_H
53 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
56 #pragma warning(disable:4290)
62 template <
class T>
class Vec2;
63 template <
class T>
class Vec3;
64 template <
class T>
class Vec4;
69 template <
class T>
class Vec2
263 T lengthTiny ()
const;
267 template <
class T>
class Vec3
475 T lengthTiny ()
const;
480 template <
class T>
class Vec4
657 T lengthTiny ()
const;
666 std::ostream & operator << (std::ostream &s, const Vec2<T> &
v);
669 std::ostream & operator << (std::ostream &s, const Vec3<T> &
v);
672 std::ostream & operator << (std::ostream &s, const Vec4<T> &
v);
961 return (
const T *) &
x;
969 return x == v.
x &&
y == v.
y;
977 return x != v.
x ||
y != v.
y;
984 for (
int i = 0; i < 2; i++)
995 for (
int i = 0; i < 2; i++)
1006 return x * v.
x +
y * v.
y;
1020 return x * v.
y -
y * v.
x;
1028 return x * v.
y -
y * v.
x;
1108 return Vec2 (
x * a,
y * a);
1140 return Vec2 (
x / a,
y / a);
1147 T absX = (
x >=
T (0))?
x: -
x;
1148 T absY = (
y >=
T (0))?
y: -
y;
1174 T length2 =
dot (*
this);
1177 return lengthTiny();
1217 throw NullVecExc (
"Cannot normalize null vector.");
1242 return Vec2 (
T (0));
1244 return Vec2 (
x / l,
y / l);
1254 throw NullVecExc (
"Cannot normalize null vector.");
1256 return Vec2 (
x / l,
y / l);
1265 return Vec2 (
x / l,
y / l);
1358 T absW = (vw >=
T (0))? vw: -vw;
1362 T m = baseTypeMax() * absW;
1364 if (vx <= -m || vx >= m || vy <= -m || vy >= m || vz <= -m || vz >= m)
1365 throw InfPointExc (
"Cannot normalize point at infinity.");
1424 return (
const T *) &
x;
1432 return x == v.
x &&
y == v.
y &&
z == v.
z;
1440 return x != v.
x ||
y != v.
y ||
z != v.
z;
1447 for (
int i = 0; i < 3; i++)
1458 for (
int i = 0; i < 3; i++)
1469 return x * v.
x +
y * v.
y +
z * v.
z;
1592 return Vec3 (
x * a,
y * a,
z * a);
1626 return Vec3 (
x / a,
y / a,
z / a);
1633 T absX = (
x >=
T (0))?
x: -
x;
1634 T absY = (
y >=
T (0))?
y: -
y;
1635 T absZ = (
z >=
T (0))?
z: -
z;
1658 return max *
Math<T>::sqrt (absX * absX + absY * absY + absZ * absZ);
1665 T length2 =
dot (*
this);
1668 return lengthTiny();
1709 throw NullVecExc (
"Cannot normalize null vector.");
1736 return Vec3 (
T (0));
1738 return Vec3 (
x / l,
y / l,
z / l);
1748 throw NullVecExc (
"Cannot normalize null vector.");
1750 return Vec3 (
x / l,
y / l,
z / l);
1759 return Vec3 (
x / l,
y / l,
z / l);
1853 return x == v.
x &&
y == v.
y &&
z == v.
z &&
w == v.
w;
1861 return x != v.
x ||
y != v.
y ||
z != v.
z ||
w != v.
w;
1868 for (
int i = 0; i < 4; i++)
1879 for (
int i = 0; i < 4; i++)
1890 return x * v.
x +
y * v.
y +
z * v.
z +
w * v.
w;
1988 return Vec4 (
x * a,
y * a,
z * a,
w * a);
2024 return Vec4 (
x / a,
y / a,
z / a,
w / a);
2031 T absX = (
x >=
T (0))?
x: -
x;
2032 T absY = (
y >=
T (0))?
y: -
y;
2033 T absZ = (
z >=
T (0))?
z: -
z;
2034 T absW = (
w >=
T (0))?
w: -
w;
2062 Math<T>::sqrt (absX * absX + absY * absY + absZ * absZ + absW * absW);
2069 T length2 =
dot (*
this);
2072 return lengthTiny();
2114 throw NullVecExc (
"Cannot normalize null vector.");
2143 return Vec4 (
T (0));
2145 return Vec4 (
x / l,
y / l,
z / l,
w / l);
2155 throw NullVecExc (
"Cannot normalize null vector.");
2157 return Vec4 (
x / l,
y / l,
z / l,
w / l);
2166 return Vec4 (
x / l,
y / l,
z / l,
w / l);
2175 operator << (std::ostream &s, const Vec2<T> &
v)
2177 return s <<
'(' <<
v.x <<
' ' <<
v.y <<
')';
2182 operator << (std::ostream &s, const Vec3<T> &
v)
2184 return s <<
'(' <<
v.x <<
' ' <<
v.y <<
' ' <<
v.z <<
')';
2189 operator << (std::ostream &s, const Vec4<T> &
v)
2191 return s <<
'(' <<
v.x <<
' ' <<
v.y <<
' ' <<
v.z <<
' ' <<
v.w <<
')';
2217 return Vec4<T> (a * v.
x, a * v.
y, a * v.
z, a * v.
w);
2221 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
2222 #pragma warning(pop)
2227 #endif // INCLUDED_IMATHVEC_H
#define IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
Vec2 operator*(const Vec2 &v) const
const Vec3 & normalizeNonNull()
GLboolean GLboolean GLboolean b
Vec3 operator*(const Vec3 &v) const
Vec4< T > normalizedExc() const
T dot(const Vec2 &v) const
bool operator==(const Vec2< S > &v) const
bool operator!=(const Vec3< S > &v) const
#define IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
const Vec4 & operator/=(const Vec4 &v)
Vec3 cross(const Vec3 &v) const
Vec4 operator/(const Vec4 &v) const
const Vec2 & operator=(const Vec2 &v)
const Vec4 & normalizeNonNull()
bool operator!=(const Vec4< S > &v) const
bool equalWithRelError(T x1, T x2, T e)
bool equalWithRelError(const Vec3< T > &v, T e) const
const Vec2 & operator+=(const Vec2 &v)
T operator^(const Vec2 &v) const
bool equalWithRelError(const Vec4< T > &v, T e) const
Vec4 operator+(const Vec4 &v) const
Vec3 operator+(const Vec3 &v) const
static unsigned int dimensions()
const Vec3 & operator/=(const Vec3 &v)
bool equalWithRelError(const Vec2< T > &v, T e) const
Vec3< T > normalizedExc() const
GLubyte GLubyte GLubyte GLubyte w
T operator%(const Vec2 &v) const
Vec2 operator/(const Vec2 &v) const
static T baseTypeEpsilon()
bool equalWithAbsError(const Vec4< T > &v, T e) const
const Vec4 & operator+=(const Vec4 &v)
const Vec3 & operator%=(const Vec3 &v)
Vec2< T > normalizedNonNull() const
void setValue(S a, S b, S c)
Vec3< T > normalizedNonNull() const
const Vec4 & normalizeExc()
T dot(const Vec3 &v) const
T operator^(const Vec3 &v) const
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
GLboolean GLboolean GLboolean GLboolean a
bool equalWithAbsError(const Vec2< T > &v, T e) const
Vec4< T > normalizedNonNull() const
const Vec3 & normalizeExc()
Vec3< T > normalized() const
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
const Vec3 & operator=(const Vec3 &v)
GLdouble GLdouble GLdouble z
const Vec3 & operator*=(const Vec3 &v)
Vec4 operator*(const Vec4 &v) const
T dot(const Vec4 &v) const
static T baseTypeSmallest()
Vec3 operator%(const Vec3 &v) const
bool equalWithAbsError(const Vec3< T > &v, T e) const
bool operator==(const Vec4< S > &v) const
GLuint GLsizei GLsizei * length
static T baseTypeEpsilon()
T cross(const Vec2 &v) const
const Vec4 & operator*=(const Vec4 &v)
const Vec2 & operator-=(const Vec2 &v)
static T baseTypeEpsilon()
Vec2< T > normalized() const
const Vec4 & operator=(const Vec4 &v)
static unsigned int dimensions()
bool operator==(const Vec3< S > &v) const
const Vec2 & operator/=(const Vec2 &v)
const Vec3 & operator+=(const Vec3 &v)
static T baseTypeSmallest()
Vec4< T > normalized() const
Vec3 operator/(const Vec3 &v) const
const Vec2 & normalizeNonNull()
Vec2 operator+(const Vec2 &v) const
const Vec2 & normalizeExc()
const Vec3 & operator-=(const Vec3 &v)
bool operator!=(const Vec2< S > &v) const
const Vec2 & operator*=(const Vec2 &v)
static T baseTypeSmallest()
static unsigned int dimensions()
Vec2< T > normalizedExc() const
T operator^(const Vec4 &v) const
bool equalWithAbsError(T x1, T x2, T e)
const Vec4 & operator-=(const Vec4 &v)