HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vec2.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
4 #ifndef OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
6 
7 #include <openvdb/Exceptions.h>
8 #include "Math.h"
9 #include "Tuple.h"
10 #include <algorithm>
11 #include <cmath>
12 #include <type_traits>
13 
14 
15 namespace openvdb {
17 namespace OPENVDB_VERSION_NAME {
18 namespace math {
19 
20 template<typename T> class Mat2;
21 
22 template<typename T>
23 class Vec2: public Tuple<2, T>
24 {
25 public:
26  using value_type = T;
27  using ValueType = T;
28 
29  /// Trivial constructor, the vector is NOT initialized
30  /// @note destructor, copy constructor, assignment operator and
31  /// move constructor are left to be defined by the compiler (default)
32  Vec2() = default;
33 
34  /// @brief Construct a vector all of whose components have the given value.
35  explicit Vec2(T val) { this->mm[0] = this->mm[1] = val; }
36 
37  /// Constructor with two arguments, e.g. Vec2f v(1,2,3);
38  Vec2(T x, T y)
39  {
40  this->mm[0] = x;
41  this->mm[1] = y;
42  }
43 
44  /// Constructor with array argument, e.g. float a[2]; Vec2f v(a);
45  template <typename Source>
46  Vec2(Source *a)
47  {
48  this->mm[0] = static_cast<T>(a[0]);
49  this->mm[1] = static_cast<T>(a[1]);
50  } // trivial
51 
52  /// Conversion constructor
53  template<typename Source>
54  explicit Vec2(const Tuple<2, Source> &t)
55  {
56  this->mm[0] = static_cast<T>(t[0]);
57  this->mm[1] = static_cast<T>(t[1]);
58  }
59 
60  /// @brief Construct a vector all of whose components have the given value,
61  /// which may be of an arithmetic type different from this vector's value type.
62  /// @details Type conversion warnings are suppressed.
63  template<typename Other>
64  explicit Vec2(Other val,
65  typename std::enable_if<std::is_arithmetic<Other>::value, Conversion>::type = Conversion{})
66  {
67  this->mm[0] = this->mm[1] = static_cast<T>(val);
68  }
69 
70  /// Reference to the component, e.g. v.x() = 4.5f;
71  T& x() {return this->mm[0];}
72  T& y() {return this->mm[1];}
73 
74  /// Get the component, e.g. float f = v.y();
75  T x() const {return this->mm[0];}
76  T y() const {return this->mm[1];}
77 
78  /// Alternative indexed reference to the elements
79  T& operator()(int i) {return this->mm[i];}
80 
81  /// Alternative indexed constant reference to the elements,
82  T operator()(int i) const {return this->mm[i];}
83 
84  T* asPointer() {return this->mm;}
85  const T* asPointer() const {return this->mm;}
86 
87  /// "this" vector gets initialized to [x, y, z],
88  /// calling v.init(); has same effect as calling v = Vec2::zero();
89  const Vec2<T>& init(T x=0, T y=0)
90  {
91  this->mm[0] = x; this->mm[1] = y;
92  return *this;
93  }
94 
95  /// Set "this" vector to zero
96  const Vec2<T>& setZero()
97  {
98  this->mm[0] = 0; this->mm[1] = 0;
99  return *this;
100  }
101 
102  /// Assignment operator
103  template<typename Source>
105  {
106  // note: don't static_cast because that suppresses warnings
107  this->mm[0] = v[0];
108  this->mm[1] = v[1];
109 
110  return *this;
111  }
112 
113  /// Equality operator, does exact floating point comparisons
114  bool operator==(const Vec2<T> &v) const
115  {
116  return (isExactlyEqual(this->mm[0], v.mm[0]) && isExactlyEqual(this->mm[1], v.mm[1]));
117  }
118 
119  /// Inequality operator, does exact floating point comparisons
120  bool operator!=(const Vec2<T> &v) const { return !(*this==v); }
121 
122  /// Test if "this" vector is equivalent to vector v with tolerance of eps
123  bool eq(const Vec2<T> &v, T eps = static_cast<T>(1.0e-7)) const
124  {
125  return isApproxEqual(this->mm[0], v.mm[0], eps) &&
126  isApproxEqual(this->mm[1], v.mm[1], eps);
127  } // trivial
128 
129  /// Negation operator, for e.g. v1 = -v2;
130  Vec2<T> operator-() const {return Vec2<T>(-this->mm[0], -this->mm[1]);}
131 
132  /// this = v1 + v2
133  /// "this", v1 and v2 need not be distinct objects, e.g. v.add(v1,v);
134  template <typename T0, typename T1>
135  const Vec2<T>& add(const Vec2<T0> &v1, const Vec2<T1> &v2)
136  {
137  this->mm[0] = v1[0] + v2[0];
138  this->mm[1] = v1[1] + v2[1];
139 
140  return *this;
141  }
142 
143  /// this = v1 - v2
144  /// "this", v1 and v2 need not be distinct objects, e.g. v.sub(v1,v);
145  template <typename T0, typename T1>
146  const Vec2<T>& sub(const Vec2<T0> &v1, const Vec2<T1> &v2)
147  {
148  this->mm[0] = v1[0] - v2[0];
149  this->mm[1] = v1[1] - v2[1];
150 
151  return *this;
152  }
153 
154  /// this = scalar*v, v need not be a distinct object from "this",
155  /// e.g. v.scale(1.5,v1);
156  template <typename T0, typename T1>
157  const Vec2<T>& scale(T0 scalar, const Vec2<T1> &v)
158  {
159  this->mm[0] = scalar * v[0];
160  this->mm[1] = scalar * v[1];
161 
162  return *this;
163  }
164 
165  template <typename T0, typename T1>
166  const Vec2<T> &div(T0 scalar, const Vec2<T1> &v)
167  {
168  this->mm[0] = v[0] / scalar;
169  this->mm[1] = v[1] / scalar;
170 
171  return *this;
172  }
173 
174  /// Dot product
175  T dot(const Vec2<T> &v) const { return this->mm[0]*v[0] + this->mm[1]*v[1]; } // trivial
176 
177  /// Length of the vector
178  T length() const
179  {
180  return static_cast<T>(sqrt(double(this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1])));
181  }
182 
183  /// Squared length of the vector, much faster than length() as it
184  /// does not involve square root
185  T lengthSqr() const { return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]); }
186 
187  /// Return a reference to itsef after the exponent has been
188  /// applied to all the vector components.
189  inline const Vec2<T>& exp()
190  {
191  this->mm[0] = std::exp(this->mm[0]);
192  this->mm[1] = std::exp(this->mm[1]);
193  return *this;
194  }
195 
196  /// Return a reference to itself after log has been
197  /// applied to all the vector components.
198  inline const Vec2<T>& log()
199  {
200  this->mm[0] = std::log(this->mm[0]);
201  this->mm[1] = std::log(this->mm[1]);
202  return *this;
203  }
204 
205  /// Return the sum of all the vector components.
206  inline T sum() const
207  {
208  return this->mm[0] + this->mm[1];
209  }
210 
211  /// Return the product of all the vector components.
212  inline T product() const
213  {
214  return this->mm[0] * this->mm[1];
215  }
216 
217  /// this = normalized this
218  bool normalize(T eps = static_cast<T>(1.0e-8))
219  {
220  T d = length();
221  if (isApproxEqual(d, T(0), eps)) {
222  return false;
223  }
224  *this *= (T(1) / d);
225  return true;
226  }
227 
228  /// return normalized this, throws if null vector
229  Vec2<T> unit(T eps=0) const
230  {
231  T d;
232  return unit(eps, d);
233  }
234 
235  /// return normalized this and length, throws if null vector
236  Vec2<T> unit(T eps, T& len) const
237  {
238  len = length();
239  if (isApproxEqual(len, T(0), eps)) {
240  OPENVDB_THROW(ArithmeticError, "Normalizing null 2-vector");
241  }
242  return *this / len;
243  }
244 
245  /// return normalized this, or (1, 0) if this is null vector
247  {
248  T l2 = lengthSqr();
249  return l2 ? *this/static_cast<T>(sqrt(l2)) : Vec2<T>(1,0);
250  }
251 
252  /// Multiply each element of this vector by @a scalar.
253  template <typename S>
254  const Vec2<T> &operator*=(S scalar)
255  {
256  this->mm[0] *= scalar;
257  this->mm[1] *= scalar;
258  return *this;
259  }
260 
261  /// Multiply each element of this vector by the corresponding element of the given vector.
262  template <typename S>
263  const Vec2<T> &operator*=(const Vec2<S> &v1)
264  {
265  this->mm[0] *= v1[0];
266  this->mm[1] *= v1[1];
267  return *this;
268  }
269 
270  /// Divide each element of this vector by @a scalar.
271  template <typename S>
272  const Vec2<T> &operator/=(S scalar)
273  {
274  this->mm[0] /= scalar;
275  this->mm[1] /= scalar;
276  return *this;
277  }
278 
279  /// Divide each element of this vector by the corresponding element of the given vector.
280  template <typename S>
281  const Vec2<T> &operator/=(const Vec2<S> &v1)
282  {
283  this->mm[0] /= v1[0];
284  this->mm[1] /= v1[1];
285  return *this;
286  }
287 
288  /// Add @a scalar to each element of this vector.
289  template <typename S>
290  const Vec2<T> &operator+=(S scalar)
291  {
292  this->mm[0] += scalar;
293  this->mm[1] += scalar;
294  return *this;
295  }
296 
297  /// Add each element of the given vector to the corresponding element of this vector.
298  template <typename S>
299  const Vec2<T> &operator+=(const Vec2<S> &v1)
300  {
301  this->mm[0] += v1[0];
302  this->mm[1] += v1[1];
303  return *this;
304  }
305 
306  /// Subtract @a scalar from each element of this vector.
307  template <typename S>
308  const Vec2<T> &operator-=(S scalar)
309  {
310  this->mm[0] -= scalar;
311  this->mm[1] -= scalar;
312  return *this;
313  }
314 
315  /// Subtract each element of the given vector from the corresponding element of this vector.
316  template <typename S>
317  const Vec2<T> &operator-=(const Vec2<S> &v1)
318  {
319  this->mm[0] -= v1[0];
320  this->mm[1] -= v1[1];
321  return *this;
322  }
323 
324  // Number of cols, rows, elements
325  static unsigned numRows() { return 1; }
326  static unsigned numColumns() { return 2; }
327  static unsigned numElements() { return 2; }
328 
329  /// Returns the scalar component of v in the direction of onto, onto need
330  /// not be unit. e.g float c = Vec2f::component(v1,v2);
331  T component(const Vec2<T> &onto, T eps = static_cast<T>(1.0e-8)) const
332  {
333  T l = onto.length();
334  if (isApproxEqual(l, T(0), eps)) return 0;
335 
336  return dot(onto)*(T(1)/l);
337  }
338 
339  /// Return the projection of v onto the vector, onto need not be unit
340  /// e.g. Vec2f v = Vec2f::projection(v,n);
341  Vec2<T> projection(const Vec2<T> &onto, T eps = static_cast<T>(1.0e-8)) const
342  {
343  T l = onto.lengthSqr();
344  if (isApproxEqual(l, T(0), eps)) return Vec2::zero();
345 
346  return onto*(dot(onto)*(T(1)/l));
347  }
348 
349  /// Return an arbitrary unit vector perpendicular to v
350  /// Vector v must be a unit vector
351  /// e.g. v.normalize(); Vec2f n = Vec2f::getArbPerpendicular(v);
352  Vec2<T> getArbPerpendicular() const { return Vec2<T>(-this->mm[1], this->mm[0]); }
353 
354  /// Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();
355  static Vec2<T> zero() { return Vec2<T>(0, 0); }
356  static Vec2<T> ones() { return Vec2<T>(1, 1); }
357 };
358 
359 /// Multiply each element of the given vector by @a scalar and return the result.
360 template <typename S, typename T>
362 {
363  return v * scalar;
364 }
365 
366 /// Multiply each element of the given vector by @a scalar and return the result.
367 template <typename S, typename T>
369 {
371  result *= scalar;
372  return result;
373 }
374 
375 /// Multiply corresponding elements of @a v0 and @a v1 and return the result.
376 template <typename T0, typename T1>
378 {
379  Vec2<typename promote<T0, T1>::type> result(v0[0] * v1[0], v0[1] * v1[1]);
380  return result;
381 }
382 
383 /// Divide @a scalar by each element of the given vector and return the result.
384 template <typename S, typename T>
386 {
387  return Vec2<typename promote<S, T>::type>(scalar/v[0], scalar/v[1]);
388 }
389 
390 /// Divide each element of the given vector by @a scalar and return the result.
391 template <typename S, typename T>
393 {
395  result /= scalar;
396  return result;
397 }
398 
399 /// Divide corresponding elements of @a v0 and @a v1 and return the result.
400 template <typename T0, typename T1>
402 {
403  Vec2<typename promote<T0, T1>::type> result(v0[0] / v1[0], v0[1] / v1[1]);
404  return result;
405 }
406 
407 /// Add corresponding elements of @a v0 and @a v1 and return the result.
408 template <typename T0, typename T1>
410 {
412  result += v1;
413  return result;
414 }
415 
416 /// Add @a scalar to each element of the given vector and return the result.
417 template <typename S, typename T>
419 {
421  result += scalar;
422  return result;
423 }
424 
425 /// Subtract corresponding elements of @a v0 and @a v1 and return the result.
426 template <typename T0, typename T1>
428 {
430  result -= v1;
431  return result;
432 }
433 
434 /// Subtract @a scalar from each element of the given vector and return the result.
435 template <typename S, typename T>
437 {
439  result -= scalar;
440  return result;
441 }
442 
443 /// Angle between two vectors, the result is between [0, pi],
444 /// e.g. float a = Vec2f::angle(v1,v2);
445 template <typename T>
446 inline T angle(const Vec2<T> &v1, const Vec2<T> &v2)
447 {
448  T c = v1.dot(v2);
449  return acos(c);
450 }
451 
452 template <typename T>
453 inline bool
454 isApproxEqual(const Vec2<T>& a, const Vec2<T>& b)
455 {
456  return a.eq(b);
457 }
458 template <typename T>
459 inline bool
460 isApproxEqual(const Vec2<T>& a, const Vec2<T>& b, const Vec2<T>& eps)
461 {
462  return isApproxEqual(a.x(), b.x(), eps.x()) &&
463  isApproxEqual(a.y(), b.y(), eps.y());
464 }
465 
466 template<typename T>
467 inline Vec2<T>
468 Abs(const Vec2<T>& v)
469 {
470  return Vec2<T>(Abs(v[0]), Abs(v[1]));
471 }
472 
473 /// Orthonormalize vectors v1 and v2 and store back the resulting basis
474 /// e.g. Vec2f::orthonormalize(v1,v2);
475 template <typename T>
477 {
478  // If the input vectors are v0, v1, and v2, then the Gram-Schmidt
479  // orthonormalization produces vectors u0, u1, and u2 as follows,
480  //
481  // u0 = v0/|v0|
482  // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0|
483  //
484  // where |A| indicates length of vector A and A*B indicates dot
485  // product of vectors A and B.
486 
487  // compute u0
488  v1.normalize();
489 
490  // compute u1
491  T d0 = v1.dot(v2);
492  v2 -= v1*d0;
493  v2.normalize();
494 }
495 
496 
497 /// \remark We are switching to a more explicit name because the semantics
498 /// are different from std::min/max. In that case, the function returns a
499 /// reference to one of the objects based on a comparator. Here, we must
500 /// fabricate a new object which might not match either of the inputs.
501 
502 /// Return component-wise minimum of the two vectors.
503 template <typename T>
504 inline Vec2<T> minComponent(const Vec2<T> &v1, const Vec2<T> &v2)
505 {
506  return Vec2<T>(
507  std::min(v1.x(), v2.x()),
508  std::min(v1.y(), v2.y()));
509 }
510 
511 /// Return component-wise maximum of the two vectors.
512 template <typename T>
513 inline Vec2<T> maxComponent(const Vec2<T> &v1, const Vec2<T> &v2)
514 {
515  return Vec2<T>(
516  std::max(v1.x(), v2.x()),
517  std::max(v1.y(), v2.y()));
518 }
519 
520 /// @brief Return a vector with the exponent applied to each of
521 /// the components of the input vector.
522 template <typename T>
523 inline Vec2<T> Exp(Vec2<T> v) { return v.exp(); }
524 
525 /// @brief Return a vector with log applied to each of
526 /// the components of the input vector.
527 template <typename T>
528 inline Vec2<T> Log(Vec2<T> v) { return v.log(); }
529 
534 
539 
540 } // namespace math
541 } // namespace OPENVDB_VERSION_NAME
542 } // namespace openvdb
543 
544 #endif // OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:504
bool normalize(T eps=static_cast< T >(1.0e-8))
this = normalized this
Definition: Vec2.h:218
const Vec2< T > & operator-=(const Vec2< S > &v1)
Subtract each element of the given vector from the corresponding element of this vector.
Definition: Vec2.h:317
const Vec2< T > & div(T0 scalar, const Vec2< T1 > &v)
Definition: Vec2.h:166
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec2.h:71
Vec2< T > projection(const Vec2< T > &onto, T eps=static_cast< T >(1.0e-8)) const
Definition: Vec2.h:341
T length() const
Length of the vector.
Definition: Vec2.h:178
T component(const Vec2< T > &onto, T eps=static_cast< T >(1.0e-8)) const
Definition: Vec2.h:331
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:443
const GLdouble * v
Definition: glcorearb.h:837
GLsizei const GLfloat * value
Definition: glcorearb.h:824
void orthonormalize(Vec2< T > &v1, Vec2< T > &v2)
Definition: Vec2.h:476
Vec2< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec2.h:130
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
Definition: Coord.h:553
vfloat4 sqrt(const vfloat4 &a)
Definition: simd.h:7481
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition: Mat3.h:597
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:239
Vec2< T > Log(Vec2< T > v)
Return a vector with log applied to each of the components of the input vector.
Definition: Vec2.h:528
Dummy class for tag dispatch of conversion constructors.
Definition: Tuple.h:23
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLint y
Definition: glcorearb.h:103
**But if you need a result
Definition: thread.h:613
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec2.h:82
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
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:64
bool operator==(const Vec2< T > &v) const
Equality operator, does exact floating point comparisons.
Definition: Vec2.h:114
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:123
Vec2< typename promote< S, T >::type > operator/(S scalar, const Vec2< T > &v)
Divide scalar by each element of the given vector and return the result.
Definition: Vec2.h:385
Vec2< T > getArbPerpendicular() const
Definition: Vec2.h:352
const Vec2< T > & operator+=(const Vec2< S > &v1)
Add each element of the given vector to the corresponding element of this vector. ...
Definition: Vec2.h:299
#define OPENVDB_IS_POD(Type)
Definition: Math.h:56
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition: Math.h:406
Vec2(T val)
Construct a vector all of whose components have the given value.
Definition: Vec2.h:35
Coord Abs(const Coord &xyz)
Definition: Coord.h:517
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
T product() const
Return the product of all the vector components.
Definition: Vec2.h:212
T sum() const
Return the sum of all the vector components.
Definition: Vec2.h:206
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:446
const Vec2< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
Definition: Vec2.h:254
SYS_API double acos(double x)
Definition: SYS_FPUMath.h:83
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
const Vec2< T > & operator*=(const Vec2< S > &v1)
Multiply each element of this vector by the corresponding element of the given vector.
Definition: Vec2.h:263
GLdouble t
Definition: glad.h:2397
GLfloat v0
Definition: glcorearb.h:816
T dot(const Vec2< T > &v) const
Dot product.
Definition: Vec2.h:175
const Vec2< T > & operator=(const Vec2< Source > &v)
Assignment operator.
Definition: Vec2.h:104
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec2.h:79
Vec2< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec2.h:236
const Vec2< T > & init(T x=0, T y=0)
Definition: Vec2.h:89
Vec2(T x, T y)
Constructor with two arguments, e.g. Vec2f v(1,2,3);.
Definition: Vec2.h:38
Definition: ImathVec.h:31
const Vec2< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
Definition: Vec2.h:272
const Vec2< T > & operator+=(S scalar)
Add scalar to each element of this vector.
Definition: Vec2.h:290
bool operator!=(const Vec2< T > &v) const
Inequality operator, does exact floating point comparisons.
Definition: Vec2.h:120
static Vec2< T > zero()
Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();.
Definition: Vec2.h:355
Vec2(Source *a)
Constructor with array argument, e.g. float a[2]; Vec2f v(a);.
Definition: Vec2.h:46
GLfloat GLfloat v1
Definition: glcorearb.h:817
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLuint GLfloat * val
Definition: glcorearb.h:1608
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec2.h:513
const Vec2< T > & setZero()
Set "this" vector to zero.
Definition: Vec2.h:96
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be added to or subtracted from a Vec3.
Definition: Coord.h:527
const Vec2< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
Definition: Vec2.h:308
const Vec2< T > & scale(T0 scalar, const Vec2< T1 > &v)
Definition: Vec2.h:157
Vec2< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec2.h:229
const Vec2< T > & operator/=(const Vec2< S > &v1)
Divide each element of this vector by the corresponding element of the given vector.
Definition: Vec2.h:281
OIIO_FORCEINLINE T log(const T &v)
Definition: simd.h:7688
Vec2< T > unitSafe() const
return normalized this, or (1, 0) if this is null vector
Definition: Vec2.h:246
Vec2(const Tuple< 2, Source > &t)
Conversion constructor.
Definition: Vec2.h:54
type
Definition: core.h:1059
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec2.h:75
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:119
const Vec2< T > & sub(const Vec2< T0 > &v1, const Vec2< T1 > &v2)
Definition: Vec2.h:146
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
Type Exp(const Type &x)
Return ex.
Definition: Math.h:710
const Vec2< T > & add(const Vec2< T0 > &v1, const Vec2< T1 > &v2)
Definition: Vec2.h:135