31 #ifndef OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED 32 #define OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED 38 #include <type_traits> 46 template<
typename T>
class Mat2;
59 explicit Vec2(T val) { this->mm[0] = this->mm[1] = val; }
69 template <
typename Source>
77 template<
typename Source>
80 this->mm[0] =
static_cast<T
>(t[0]);
81 this->mm[1] =
static_cast<T
>(t[1]);
87 template<
typename Other>
91 this->mm[0] = this->mm[1] =
static_cast<T
>(val);
95 T&
x() {
return this->mm[0];}
96 T&
y() {
return this->mm[1];}
99 T
x()
const {
return this->mm[0];}
100 T
y()
const {
return this->mm[1];}
115 this->mm[0] = x; this->mm[1] = y;
122 this->mm[0] = 0; this->mm[1] = 0;
127 template<
typename Source>
147 bool eq(
const Vec2<T> &v, T eps = static_cast<T>(1.0e-7))
const 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] = v1[0] - v2[0];
173 this->mm[1] = v1[1] - v2[1];
180 template <
typename T0,
typename T1>
183 this->mm[0] = scalar * v[0];
184 this->mm[1] = scalar * v[1];
189 template <
typename T0,
typename T1>
192 this->mm[0] = v[0] / scalar;
193 this->mm[1] = v[1] / scalar;
199 T
dot(
const Vec2<T> &v)
const {
return this->mm[0]*v[0] + this->mm[1]*v[1]; }
204 return static_cast<T
>(sqrt(
double(this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1])));
209 T
lengthSqr()
const {
return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]); }
215 this->mm[0] = std::exp(this->mm[0]);
216 this->mm[1] = std::exp(this->mm[1]);
224 this->mm[0] = std::log(this->mm[0]);
225 this->mm[1] = std::log(this->mm[1]);
232 return this->mm[0] + this->mm[1];
238 return this->mm[0] * this->mm[1];
273 return l2 ? *
this/
static_cast<T
>(sqrt(l2)) :
Vec2<T>(1,0);
277 template <
typename S>
280 this->mm[0] *= scalar;
281 this->mm[1] *= scalar;
286 template <
typename S>
289 this->mm[0] *= v1[0];
290 this->mm[1] *= v1[1];
295 template <
typename S>
298 this->mm[0] /= scalar;
299 this->mm[1] /= scalar;
304 template <
typename S>
307 this->mm[0] /= v1[0];
308 this->mm[1] /= v1[1];
313 template <
typename S>
316 this->mm[0] += scalar;
317 this->mm[1] += scalar;
322 template <
typename S>
325 this->mm[0] += v1[0];
326 this->mm[1] += v1[1];
331 template <
typename S>
334 this->mm[0] -= scalar;
335 this->mm[1] -= scalar;
340 template <
typename S>
343 this->mm[0] -= v1[0];
344 this->mm[1] -= v1[1];
360 return dot(onto)*(T(1)/l);
370 return onto*(dot(onto)*(T(1)/l));
379 bool isNan()
const {
return isnan(this->mm[0]) || isnan(this->mm[1]); }
382 bool isInfinite()
const {
return isinf(this->mm[0]) || isinf(this->mm[1]); }
385 bool isFinite()
const {
return finite(this->mm[0]) && finite(this->mm[1]); }
394 template <
typename S,
typename T>
401 template <
typename S,
typename T>
410 template <
typename T0,
typename T1>
418 template <
typename S,
typename T>
425 template <
typename S,
typename T>
434 template <
typename T0,
typename T1>
442 template <
typename T0,
typename T1>
451 template <
typename S,
typename T>
460 template <
typename T0,
typename T1>
469 template <
typename S,
typename T>
479 template <
typename T>
486 template <
typename T>
492 template <
typename T>
524 template <
typename T>
552 template <
typename T>
561 template <
typename T>
571 template <
typename T>
576 template <
typename T>
588 #endif // OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED const Vec2< T > & operator-=(S scalar)
Returns v, where for .
Definition: Vec2.h:332
const Vec2< T > & div(T0 scalar, const Vec2< T1 > &v)
Definition: Vec2.h:190
const Vec2< T > & operator=(const Vec2< Source > &v)
Assignment operator.
Definition: Vec2.h:128
Vec2< double > Vec2d
Definition: Vec2.h:582
T * asPointer()
Definition: Vec2.h:108
bool isApproxEqual(const Vec2< T > &a, const Vec2< T > &b, const Vec2< T > &eps)
Definition: Vec2.h:494
static Vec2< T > zero()
Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();.
Definition: Vec2.h:388
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Vec2(const Tuple< 2, Source > &t)
Conversion constructor.
Definition: Vec2.h:78
Vec2(Other val, typename std::enable_if< std::is_arithmetic< Other >::value, Conversion >::type=Conversion{})
Construct a vector all of whose components have the given value, which may be of an arithmetic type d...
Definition: Vec2.h:88
T mm[SIZE]
Definition: Tuple.h:164
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:480
const Vec2< T > & operator+=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:323
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
Vec2< T > projection(const Vec2< T > &onto, T eps=1.0e-8) const
Definition: Vec2.h:365
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:147
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:572
Vec2< float > Vec2s
Definition: Vec2.h:581
Vec2< typename promote< T0, T1 >::type > operator*(const Vec2< T0 > &v0, const Vec2< T1 > &v1)
Returns V, where for .
Definition: Vec2.h:411
const Vec2< T > & exp()
Definition: Vec2.h:213
Vec2< T > getArbPerpendicular() const
Definition: Vec2.h:376
bool operator==(const Vec2< T > &v) const
Equality operator, does exact floating point comparisons.
Definition: Vec2.h:138
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec2.h:95
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec2.h:103
static Vec2< T > ones()
Definition: Vec2.h:389
T sum() const
Return the sum of all the vector components.
Definition: Vec2.h:230
Vec2(T val)
Construct a vector all of whose components have the given value.
Definition: Vec2.h:59
const Vec2< T > & init(T x=0, T y=0)
Definition: Vec2.h:113
bool isFinite(const Vec2< T > &v)
Definition: Vec2.h:502
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:643
static unsigned numColumns()
Definition: Vec2.h:350
void orthonormalize(Vec2< T > &v1, Vec2< T > &v2)
Definition: Vec2.h:525
const Vec2< T > & operator+=(S scalar)
Returns v, where for .
Definition: Vec2.h:314
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec2.h:99
Vec2< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec2.h:253
T length() const
Length of the vector.
Definition: Vec2.h:202
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec2.h:562
Vec2()
Trivial constructor, the vector is NOT initialized.
Definition: Vec2.h:56
Vec2< typename promote< S, T >::type > operator-(const Vec2< T > &v, S scalar)
Returns V, where for .
Definition: Vec2.h:470
#define OPENVDB_VERSION_NAME
Definition: version.h:43
T dot(const Vec2< T > &v) const
Dot product.
Definition: Vec2.h:199
Dummy class for tag dispatch of conversion constructors.
Definition: Tuple.h:47
const Vec2< T > & setZero()
Set "this" vector to zero.
Definition: Vec2.h:120
static unsigned numElements()
Definition: Vec2.h:351
Vec2(T x, T y)
Constructor with two arguments, e.g. Vec2f v(1,2,3);.
Definition: Vec2.h:62
bool operator!=(const Vec2< T > &v) const
Inequality operator, does exact floating point comparisons.
Definition: Vec2.h:144
Vec2< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec2.h:260
bool isInfinite() const
True if an Inf is present in vector.
Definition: Vec2.h:382
bool isNan() const
True if a Nan is present in vector.
Definition: Vec2.h:379
T value_type
Definition: Vec2.h:52
Definition: Exceptions.h:39
T component(const Vec2< T > &onto, T eps=1.0e-8) const
Definition: Vec2.h:355
T lengthSqr() const
Definition: Vec2.h:209
const Vec2< T > & operator/=(S scalar)
Returns v, where for .
Definition: Vec2.h:296
const Vec2< T > & log()
Definition: Vec2.h:222
T product() const
Return the product of all the vector components.
Definition: Vec2.h:236
Vec2< T > Log(Vec2< T > v)
Return a vector with log applied to each of the components of the input vector.
Definition: Vec2.h:577
const Vec2< T > & sub(const Vec2< T0 > &v1, const Vec2< T1 > &v2)
Definition: Vec2.h:170
Definition: Exceptions.h:82
T ValueType
Definition: Vec2.h:53
Vec2< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec2.h:154
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
const Vec2< T > & operator*=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:287
bool isZero(const Vec2< T > &v)
Return true if all components are exactly equal to zero.
Definition: Vec2.h:510
const Vec2< T > & scale(T0 scalar, const Vec2< T1 > &v)
Definition: Vec2.h:181
T y() const
Definition: Vec2.h:100
Vec2< typename promote< S, T >::type > operator+(const Vec2< T > &v, S scalar)
Returns V, where for .
Definition: Vec2.h:452
Vec2< T > Abs(const Vec2< T > &v)
Definition: Vec2.h:517
const Vec2< T > & operator*=(S scalar)
Returns v, where for .
Definition: Vec2.h:278
const Vec2< T > & operator-=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:341
Vec2< int32_t > Vec2i
Definition: Vec2.h:579
Vec2< T > unitSafe() const
return normalized this, or (1, 0) if this is null vector
Definition: Vec2.h:270
Vec2< typename promote< T0, T1 >::type > operator/(const Vec2< T0 > &v0, const Vec2< T1 > &v1)
Returns V, where for .
Definition: Vec2.h:435
const T * asPointer() const
Definition: Vec2.h:109
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Vec2< uint32_t > Vec2ui
Definition: Vec2.h:580
const Vec2< T > & operator/=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:305
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:553
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec2.h:106
T & y()
Definition: Vec2.h:96
bool normalize(T eps=1.0e-8)
this = normalized this
Definition: Vec2.h:242
bool isFinite() const
True if all no Nan or Inf values present.
Definition: Vec2.h:385
static unsigned numRows()
Definition: Vec2.h:349
Vec2(Source *a)
Constructor with array argument, e.g. float a[2]; Vec2f v(a);.
Definition: Vec2.h:70
const Vec2< T > & add(const Vec2< T0 > &v1, const Vec2< T1 > &v2)
Definition: Vec2.h:159