31 #ifndef OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
45 template<
typename T>
class Mat2;
58 explicit Vec2(T val) { this->mm[0] = this->mm[1] = val; }
68 template <
typename Source>
76 template<
typename Source>
79 this->mm[0] =
static_cast<T
>(t[0]);
80 this->mm[1] =
static_cast<T
>(t[1]);
84 T&
x() {
return this->mm[0];}
85 T&
y() {
return this->mm[1];}
88 T
x()
const {
return this->mm[0];}
89 T
y()
const {
return this->mm[1];}
104 this->mm[0] = x; this->mm[1] = y;
111 this->mm[0] = 0; this->mm[1] = 0;
116 template<
typename Source>
136 bool eq(
const Vec2<T> &v, T eps = static_cast<T>(1.0e-7))
const
147 template <
typename T0,
typename T1>
150 this->mm[0] = v1[0] + v2[0];
151 this->mm[1] = v1[1] + v2[1];
158 template <
typename T0,
typename T1>
161 this->mm[0] = v1[0] - v2[0];
162 this->mm[1] = v1[1] - v2[1];
169 template <
typename T0,
typename T1>
172 this->mm[0] = scalar * v[0];
173 this->mm[1] = scalar * v[1];
178 template <
typename T0,
typename T1>
181 this->mm[0] = v[0] / scalar;
182 this->mm[1] = v[1] / scalar;
188 T
dot(
const Vec2<T> &v)
const {
return this->mm[0]*v[0] + this->mm[1]*v[1]; }
193 return static_cast<T
>(sqrt(
double(this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1])));
198 T
lengthSqr()
const {
return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]); }
204 this->mm[0] = std::exp(this->mm[0]);
205 this->mm[1] = std::exp(this->mm[1]);
212 return this->mm[0] + this->mm[1];
244 template <
typename S>
247 this->mm[0] *= scalar;
248 this->mm[1] *= scalar;
253 template <
typename S>
256 this->mm[0] *= v1[0];
257 this->mm[1] *= v1[1];
262 template <
typename S>
265 this->mm[0] /= scalar;
266 this->mm[1] /= scalar;
271 template <
typename S>
274 this->mm[0] /= v1[0];
275 this->mm[1] /= v1[1];
280 template <
typename S>
283 this->mm[0] += scalar;
284 this->mm[1] += scalar;
289 template <
typename S>
292 this->mm[0] += v1[0];
293 this->mm[1] += v1[1];
298 template <
typename S>
301 this->mm[0] -= scalar;
302 this->mm[1] -= scalar;
307 template <
typename S>
310 this->mm[0] -= v1[0];
311 this->mm[1] -= v1[1];
327 return dot(onto)*(T(1)/l);
337 return onto*(dot(onto)*(T(1)/l));
346 bool isNan()
const {
return isnan(this->mm[0]) || isnan(this->mm[1]); }
349 bool isInfinite()
const {
return isinf(this->mm[0]) || isinf(this->mm[1]); }
352 bool isFinite()
const {
return finite(this->mm[0]) && finite(this->mm[1]); }
360 template <
typename S,
typename T>
367 template <
typename S,
typename T>
376 template <
typename T0,
typename T1>
384 template <
typename S,
typename T>
391 template <
typename S,
typename T>
400 template <
typename T0,
typename T1>
408 template <
typename T0,
typename T1>
417 template <
typename S,
typename T>
426 template <
typename T0,
typename T1>
435 template <
typename S,
typename T>
445 template <
typename T>
452 template <
typename T>
458 template <
typename T>
482 template <
typename T>
510 template <
typename T>
519 template <
typename T>
529 template <
typename T>
541 #endif // OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
Vec2< typename promote< S, T >::type > operator-(const Vec2< T > &v, S scalar)
Returns V, where for .
Definition: Vec2.h:436
Vec2< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec2.h:227
Vec2< typename promote< S, T >::type > operator+(const Vec2< T > &v, S scalar)
Returns V, where for .
Definition: Vec2.h:418
const Vec2< T > & operator/=(S scalar)
Returns v, where for .
Definition: Vec2.h:263
Vec2< typename promote< T0, T1 >::type > operator/(const Vec2< T0 > &v0, const Vec2< T1 > &v1)
Returns V, where for .
Definition: Vec2.h:401
const Vec2< T > & operator*=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:254
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
const Vec2< T > & setZero()
Set "this" vector to zero.
Definition: Vec2.h:109
bool isFinite(const Vec2< T > &v)
Definition: Vec2.h:468
const Vec2< T > & operator*=(S scalar)
Returns v, where for .
Definition: Vec2.h:245
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec2.h:88
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
const Vec2< T > & sub(const Vec2< T0 > &v1, const Vec2< T1 > &v2)
Definition: Vec2.h:159
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec2.h:520
Vec2< uint32_t > Vec2ui
Definition: Vec2.h:533
Vec2< int32_t > Vec2i
Definition: Vec2.h:532
T y() const
Definition: Vec2.h:89
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:446
const Vec2< T > & scale(T0 scalar, const Vec2< T1 > &v)
Definition: Vec2.h:170
T ValueType
Definition: Vec2.h:52
const Vec2< T > & operator/=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:272
bool isFinite() const
True if all no Nan or Inf values present.
Definition: Vec2.h:352
static unsigned numRows()
Definition: Vec2.h:316
const Vec2< T > & operator-=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:308
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:511
const Vec2< T > & operator=(const Vec2< Source > &v)
Assignment operator.
Definition: Vec2.h:117
bool operator==(const Vec2< T > &v) const
Equality operator, does exact floating point comparisons.
Definition: Vec2.h:127
#define OPENVDB_VERSION_NAME
Definition: version.h:43
static Vec2< T > zero()
Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();.
Definition: Vec2.h:355
Vec2< T > getArbPerpendicular() const
Definition: Vec2.h:343
Vec2< typename promote< T0, T1 >::type > operator*(const Vec2< T0 > &v0, const Vec2< T1 > &v1)
Returns V, where for .
Definition: Vec2.h:377
Vec2< T > Abs(const Vec2< T > &v)
Definition: Vec2.h:475
T * asPointer()
Definition: Vec2.h:97
Vec2(Source *a)
Constructor with array argument, e.g. float a[2]; Vec2f v(a);.
Definition: Vec2.h:69
void orthonormalize(Vec2< T > &v1, Vec2< T > &v2)
Definition: Vec2.h:483
Definition: Exceptions.h:39
bool eq(const Vec2< T > &v, T eps=static_cast< T >(1.0e-7)) const
Test if "this" vector is equivalent to vector v with tolerance of eps.
Definition: Vec2.h:136
T mm[SIZE]
Definition: Tuple.h:148
T & y()
Definition: Vec2.h:85
bool normalize(T eps=1.0e-8)
this = normalized this
Definition: Vec2.h:216
T dot(const Vec2< T > &v) const
Dot product.
Definition: Vec2.h:188
const Vec2< T > & operator+=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:290
Vec2< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec2.h:143
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec2.h:84
const Vec2< T > & add(const Vec2< T0 > &v1, const Vec2< T1 > &v2)
Definition: Vec2.h:148
const Vec2< T > & operator-=(S scalar)
Returns v, where for .
Definition: Vec2.h:299
Vec2(const Tuple< 2, Source > &t)
Conversion constructor.
Definition: Vec2.h:77
MatType unit(const MatType &mat, typename MatType::value_type eps=1.0e-8)
Return a copy of the given matrix with its upper 3x3 rows normalized.
Definition: Mat.h:627
const Vec2< T > & init(T x=0, T y=0)
Definition: Vec2.h:102
const Vec2< T > & div(T0 scalar, const Vec2< T1 > &v)
Definition: Vec2.h:179
T component(const Vec2< T > &onto, T eps=1.0e-8) const
Definition: Vec2.h:322
const Vec2< T > & operator+=(S scalar)
Returns v, where for .
Definition: Vec2.h:281
bool isNan() const
True if a Nan is present in vector.
Definition: Vec2.h:346
T lengthSqr() const
Definition: Vec2.h:198
Vec2< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec2.h:234
bool operator!=(const Vec2< T > &v) const
Inequality operator, does exact floating point comparisons.
Definition: Vec2.h:133
Vec2(T val)
Constructor with one argument, e.g. Vec2f v(0);.
Definition: Vec2.h:58
Vec2< T > Exp(Vec2< T > v)
Return a vector with the exponent applied to each of the components of the input vector.
Definition: Vec2.h:530
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec2.h:95
const Vec2< T > & exp()
Definition: Vec2.h:202
T sum() const
Return the sum of all the vector components.
Definition: Vec2.h:210
Definition: Exceptions.h:78
bool isInfinite() const
True if an Inf is present in vector.
Definition: Vec2.h:349
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec2.h:92
Vec2< float > Vec2s
Definition: Vec2.h:534
Vec2< T > projection(const Vec2< T > &onto, T eps=1.0e-8) const
Definition: Vec2.h:332
static unsigned numElements()
Definition: Vec2.h:318
Vec2(T x, T y)
Constructor with two arguments, e.g. Vec2f v(1,2,3);.
Definition: Vec2.h:61
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Vec2()
Trivial constructor, the vector is NOT initialized.
Definition: Vec2.h:55
bool isApproxEqual(const Vec2< T > &a, const Vec2< T > &b, const Vec2< T > &eps)
Definition: Vec2.h:460
T length() const
Length of the vector.
Definition: Vec2.h:191
const T * asPointer() const
Definition: Vec2.h:98
Vec2< double > Vec2d
Definition: Vec2.h:535
T value_type
Definition: Vec2.h:51
static unsigned numColumns()
Definition: Vec2.h:317