Vec2¶
The Vec2
class template represents a 2D vector, with predefined
typedefs for vectors of type short
, int
, int64_t
, float
, and
double
.
Note that the integer specializations of Vec2
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
vec2_example()
{
Imath::V2f a (1.0f, 2.0f);
Imath::V2f b; // b is uninitialized
b.x = a[0];
b.y = a[1];
assert (a == b);
assert (a.length() == sqrt (a ^ a));
a.normalize();
assert (Imath::equalWithAbsError (a.length(), 1.0f, 1e-6f));
}
-
template <class T>
classVec2
¶ 2-element vector
Constructors and Assignment
-
Vec2
()¶ Uninitialized by default.
-
constexpr
Vec2
(T a)¶ Initialize to a scalar
(a,a)
-
constexpr
Vec2
(T a, T b)¶ Initialize to given elements
(a,b)
-
~Vec2
()¶ Destructor.
Compatibility with Sb
-
template <class S>
voidsetValue
(S a, S b)¶ Set the value.
-
template <class S>
voidgetValue
(S &a, S &b) const¶ Return the value in
a
andb
-
T *
getValue
()¶ Return a raw pointer to the array of values.
-
const T *
getValue
() const¶ Return a raw pointer to the array of values.
Arithmetic and Comparison
-
constexpr bool
equalWithAbsError
(const Vec2<T> &v, T e) const¶ Compare two matrices and test if they are “approximately equal”:
- Return
- 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
-
constexpr bool
equalWithRelError
(const Vec2<T> &v, T e) const¶ Compare two matrices and test if they are “approximately equal”:
- Return
- 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])
-
constexpr T
cross
(const Vec2 &v) const¶ Right-handed cross product, i.e.
z component of Vec3 (this->x, this->y, 0) % Vec3 (v.x, v.y, 0)
Query and Manipulation
-
T
length
() const¶ Return the Euclidean norm.
-
constexpr T
length2
() const¶ Return the square of the Euclidean norm, i.e.
the dot product with itself.
-
const Vec2<T> &
normalizeNonNull
()¶ 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 constexpr T
baseTypeLowest
()¶ Largest possible negative value.
-
static constexpr T
baseTypeMax
()¶ Largest possible positive value.
-
static constexpr T
baseTypeSmallest
()¶ Smallest possible positive value.
-
static constexpr T
baseTypeEpsilon
()¶ Smallest possible e for which 1+e != 1.
Public Types
-
typedef T
BaseType
¶ The base type: In templates that accept a parameter
V
, you can refer toT
asV::BaseType
Public Functions
-
constexpr T &
operator[]
(int i)¶ Element access by index.
-
constexpr const T &
operator[]
(int i) const¶ Element access by index.
-
template <>
shortlength
() const
-
template <>
const Vec2<short> &normalize
()
-
template <>
const Vec2<short> &normalizeExc
()
-
template <>
const Vec2<short> &normalizeNonNull
()
-
template <>
Vec2<short>normalized
() const
-
template <>
Vec2<short>normalizedExc
() const
-
template <>
Vec2<short>normalizedNonNull
() const
-
template <>
intlength
() const
-
template <>
const Vec2<int> &normalize
()
-
template <>
const Vec2<int> &normalizeExc
()
-
template <>
const Vec2<int> &normalizeNonNull
()
-
template <>
Vec2<int>normalized
() const
-
template <>
Vec2<int>normalizedExc
() const
-
template <>
Vec2<int>normalizedNonNull
() const
-
template <>
int64_tlength
() const
-
template <>
const Vec2<int64_t> &normalize
()
-
template <>
const Vec2<int64_t> &normalizeExc
()
-
template <>
const Vec2<int64_t> &normalizeNonNull
()
-
template <>
Vec2<int64_t>normalized
() const
-
template <>
Vec2<int64_t>normalizedExc
() const
-
template <>
Vec2<int64_t>normalizedNonNull
() const
Public Static Functions
-
static constexpr unsigned int
dimensions
()¶ Return the number of dimensions, i.e. 2.
-
Warning
doxygenfunction: Unable to resolve multiple matches for function “operator<<” with arguments (std::ostream& s, const Vec2<T>& v) in doxygen xml output for project “Imath” from directory: doxyxml/. Potential matches:
- std::ostream &operator<<(std::ostream&, Imath::half)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Color4<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Euler<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Interval<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Line3<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix22<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix33<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Matrix44<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Plane3<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Quat<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Shear6<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec2<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec3<T>&)
- template <class T>
std::ostream &Imath::operator<<(std::ostream&, const Vec4<T>&)