Vec4¶
#include <Imath/ImathVec.h>
The Vec4
class template represents a 4D vector, with predefined
typedefs for vectors of type short
, int
, int64_t
,
float
, and double
.
Note that the integer specializations of Vec4
lack the
length()
and normalize()
methods that are present in the
float
and double
versions, because the results don’t fit into
integer quantities.
There are also various utility functions that operate on vectors
defined in ImathVecAlgo.h
and described in Vector Functions.
Example:
#include <Imath/ImathVec.h>
void
vec4_example()
{
Imath::V4f a (1.0f, 2.0f, 3.0f, 4.0f);
Imath::V4f b; // b is uninitialized
b.x = a[0];
b.y = a[1];
b.z = a[2];
b.w = a[3];
assert (a == b);
assert (a.length() == sqrt (a ^ a));
a.normalize();
assert (Imath::equalWithAbsError (a.length(), 1.0f, 1e-6f));
}
-
template<class T>
class Imath::Vec4¶ 4-element vector
Constructors and Assignment
-
inline Vec4() noexcept¶
Uninitialized by default.
-
template<class S>
inline constexpr Vec4(const Vec4<S> &v) noexcept¶ Construct from Vec4 of another base type.
-
~Vec4() noexcept = default¶
Destructor.
Arithmetic and Comparison
-
inline constexpr bool equalWithAbsError(const Vec4<T> &v, T e) const noexcept¶
Compare two matrices and test if they are “approximately equal”:
- Returns
True if the coefficients of this and
m
are the same with an absolute error of no more than e, i.e., for all i, j:abs (this[i][j] - m[i][j]) <= e
-
inline constexpr bool equalWithRelError(const Vec4<T> &v, T e) const noexcept¶
Compare two matrices and test if they are “approximately equal”:
- Returns
True if the coefficients of this and m are the same with a relative error of no more than e, i.e., for all i, j:
abs (this[i] - v[i][j]) <= e * abs (this[i][j])
Query and Manipulation
-
inline constexpr T length2() const noexcept¶
Return the square of the Euclidean norm, i.e.
the dot product with itself.
-
inline const Vec4 &normalizeNonNull() noexcept¶
Normalize without any checks for length()==0.
Slightly faster than the other normalization routines, but if v.length() is 0.0, the result is undefined.
Numeric Limits
- static inline constexpr static T baseTypeLowest () noexcept
Largest possible negative value.
- static inline constexpr static T baseTypeMax () noexcept
Largest possible positive value.
- static inline constexpr static T baseTypeSmallest () noexcept
Smallest possible positive value.
- static inline constexpr static T baseTypeEpsilon () noexcept
Smallest possible e for which 1+e != 1.
Public Types
Public Functions
-
short length() const noexcept = delete
-
const Vec4<short> &normalize() noexcept = delete
-
const Vec4<short> &normalizeExc() = delete
-
const Vec4<short> &normalizeNonNull() noexcept = delete
-
Vec4<short> normalized() const noexcept = delete
-
Vec4<short> normalizedExc() const = delete
-
Vec4<short> normalizedNonNull() const noexcept = delete
-
int length() const noexcept = delete
-
const Vec4<int> &normalize() noexcept = delete
-
const Vec4<int> &normalizeExc() = delete
-
const Vec4<int> &normalizeNonNull() noexcept = delete
-
Vec4<int> normalized() const noexcept = delete
-
Vec4<int> normalizedExc() const = delete
-
Vec4<int> normalizedNonNull() const noexcept = delete
-
int64_t length() const noexcept = delete
-
const Vec4<int64_t> &normalize() noexcept = delete
-
const Vec4<int64_t> &normalizeExc() = delete
-
const Vec4<int64_t> &normalizeNonNull() noexcept = delete
-
Vec4<int64_t> normalized() const noexcept = delete
-
Vec4<int64_t> normalizedExc() const = delete
-
Vec4<int64_t> normalizedNonNull() const noexcept = delete
Public Static Functions
- static inline constexpr static unsigned int dimensions () noexcept
Return the number of dimensions, i.e. 4.
-
inline Vec4() noexcept¶