HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec2.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2012-2017 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
29 ///////////////////////////////////////////////////////////////////////////
30 
31 #ifndef OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
33 
34 #include <openvdb/Exceptions.h>
35 #include "Math.h"
36 #include "Tuple.h"
37 #include <cmath>
38 #include <type_traits>
39 
40 
41 namespace openvdb {
43 namespace OPENVDB_VERSION_NAME {
44 namespace math {
45 
46 template<typename T> class Mat2;
47 
48 template<typename T>
49 class Vec2: public Tuple<2, T>
50 {
51 public:
52  typedef T value_type;
53  typedef T ValueType;
54 
55  /// Trivial constructor, the vector is NOT initialized
56  Vec2() {}
57 
58  /// @brief Construct a vector all of whose components have the given value.
59  explicit Vec2(T val) { this->mm[0] = this->mm[1] = val; }
60 
61  /// Constructor with two arguments, e.g. Vec2f v(1,2,3);
62  Vec2(T x, T y)
63  {
64  this->mm[0] = x;
65  this->mm[1] = y;
66  }
67 
68  /// Constructor with array argument, e.g. float a[2]; Vec2f v(a);
69  template <typename Source>
70  Vec2(Source *a)
71  {
72  this->mm[0] = a[0];
73  this->mm[1] = a[1];
74  } // trivial
75 
76  /// Conversion constructor
77  template<typename Source>
78  explicit Vec2(const Tuple<2, Source> &t)
79  {
80  this->mm[0] = static_cast<T>(t[0]);
81  this->mm[1] = static_cast<T>(t[1]);
82  }
83 
84  /// @brief Construct a vector all of whose components have the given value,
85  /// which may be of an arithmetic type different from this vector's value type.
86  /// @details Type conversion warnings are suppressed.
87  template<typename Other>
88  explicit Vec2(Other val,
89  typename std::enable_if<std::is_arithmetic<Other>::value, Conversion>::type = Conversion{})
90  {
91  this->mm[0] = this->mm[1] = static_cast<T>(val);
92  }
93 
94  /// Reference to the component, e.g. v.x() = 4.5f;
95  T& x() {return this->mm[0];}
96  T& y() {return this->mm[1];}
97 
98  /// Get the component, e.g. float f = v.y();
99  T x() const {return this->mm[0];}
100  T y() const {return this->mm[1];}
101 
102  /// Alternative indexed reference to the elements
103  T& operator()(int i) {return this->mm[i];}
104 
105  /// Alternative indexed constant reference to the elements,
106  T operator()(int i) const {return this->mm[i];}
107 
108  T* asPointer() {return this->mm;}
109  const T* asPointer() const {return this->mm;}
110 
111  /// "this" vector gets initialized to [x, y, z],
112  /// calling v.init(); has same effect as calling v = Vec2::zero();
113  const Vec2<T>& init(T x=0, T y=0)
114  {
115  this->mm[0] = x; this->mm[1] = y;
116  return *this;
117  }
118 
119  /// Set "this" vector to zero
120  const Vec2<T>& setZero()
121  {
122  this->mm[0] = 0; this->mm[1] = 0;
123  return *this;
124  }
125 
126  /// Assignment operator
127  template<typename Source>
129  {
130  // note: don't static_cast because that suppresses warnings
131  this->mm[0] = v[0];
132  this->mm[1] = v[1];
133 
134  return *this;
135  }
136 
137  /// Equality operator, does exact floating point comparisons
138  bool operator==(const Vec2<T> &v) const
139  {
140  return (isExactlyEqual(this->mm[0], v.mm[0]) && isExactlyEqual(this->mm[1], v.mm[1]));
141  }
142 
143  /// Inequality operator, does exact floating point comparisons
144  bool operator!=(const Vec2<T> &v) const { return !(*this==v); }
145 
146  /// Test if "this" vector is equivalent to vector v with tolerance of eps
147  bool eq(const Vec2<T> &v, T eps = static_cast<T>(1.0e-7)) const
148  {
149  return isApproxEqual(this->mm[0], v.mm[0], eps) &&
150  isApproxEqual(this->mm[1], v.mm[1], eps);
151  } // trivial
152 
153  /// Negation operator, for e.g. v1 = -v2;
154  Vec2<T> operator-() const {return Vec2<T>(-this->mm[0], -this->mm[1]);}
155 
156  /// this = v1 + v2
157  /// "this", v1 and v2 need not be distinct objects, e.g. v.add(v1,v);
158  template <typename T0, typename T1>
159  const Vec2<T>& add(const Vec2<T0> &v1, const Vec2<T1> &v2)
160  {
161  this->mm[0] = v1[0] + v2[0];
162  this->mm[1] = v1[1] + v2[1];
163 
164  return *this;
165  }
166 
167  /// this = v1 - v2
168  /// "this", v1 and v2 need not be distinct objects, e.g. v.sub(v1,v);
169  template <typename T0, typename T1>
170  const Vec2<T>& sub(const Vec2<T0> &v1, const Vec2<T1> &v2)
171  {
172  this->mm[0] = v1[0] - v2[0];
173  this->mm[1] = v1[1] - v2[1];
174 
175  return *this;
176  }
177 
178  /// this = scalar*v, v need not be a distinct object from "this",
179  /// e.g. v.scale(1.5,v1);
180  template <typename T0, typename T1>
181  const Vec2<T>& scale(T0 scalar, const Vec2<T1> &v)
182  {
183  this->mm[0] = scalar * v[0];
184  this->mm[1] = scalar * v[1];
185 
186  return *this;
187  }
188 
189  template <typename T0, typename T1>
190  const Vec2<T> &div(T0 scalar, const Vec2<T1> &v)
191  {
192  this->mm[0] = v[0] / scalar;
193  this->mm[1] = v[1] / scalar;
194 
195  return *this;
196  }
197 
198  /// Dot product
199  T dot(const Vec2<T> &v) const { return this->mm[0]*v[0] + this->mm[1]*v[1]; } // trivial
200 
201  /// Length of the vector
202  T length() const
203  {
204  return static_cast<T>(sqrt(double(this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1])));
205  }
206 
207  /// Squared length of the vector, much faster than length() as it
208  /// does not involve square root
209  T lengthSqr() const { return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]); }
210 
211  /// Return a reference to itsef after the exponent has been
212  /// applied to all the vector components.
213  inline const Vec2<T>& exp()
214  {
215  this->mm[0] = std::exp(this->mm[0]);
216  this->mm[1] = std::exp(this->mm[1]);
217  return *this;
218  }
219 
220  /// Return a reference to itself after log has been
221  /// applied to all the vector components.
222  inline const Vec2<T>& log()
223  {
224  this->mm[0] = std::log(this->mm[0]);
225  this->mm[1] = std::log(this->mm[1]);
226  return *this;
227  }
228 
229  /// Return the sum of all the vector components.
230  inline T sum() const
231  {
232  return this->mm[0] + this->mm[1];
233  }
234 
235  /// Return the product of all the vector components.
236  inline T product() const
237  {
238  return this->mm[0] * this->mm[1];
239  }
240 
241  /// this = normalized this
242  bool normalize(T eps=1.0e-8)
243  {
244  T d = length();
245  if (isApproxEqual(d, T(0), eps)) {
246  return false;
247  }
248  *this *= (T(1) / d);
249  return true;
250  }
251 
252  /// return normalized this, throws if null vector
253  Vec2<T> unit(T eps=0) const
254  {
255  T d;
256  return unit(eps, d);
257  }
258 
259  /// return normalized this and length, throws if null vector
260  Vec2<T> unit(T eps, T& len) const
261  {
262  len = length();
263  if (isApproxEqual(len, T(0), eps)) {
264  OPENVDB_THROW(ArithmeticError, "Normalizing null 2-vector");
265  }
266  return *this / len;
267  }
268 
269  /// return normalized this, or (1, 0) if this is null vector
271  {
272  T l2 = lengthSqr();
273  return l2 ? *this/static_cast<T>(sqrt(l2)) : Vec2<T>(1,0);
274  }
275 
276  /// Returns v, where \f$v_i *= scalar\f$ for \f$i \in [0, 1]\f$
277  template <typename S>
278  const Vec2<T> &operator*=(S scalar)
279  {
280  this->mm[0] *= scalar;
281  this->mm[1] *= scalar;
282  return *this;
283  }
284 
285  /// Returns v0, where \f$v0_i *= v1_i\f$ for \f$i \in [0, 1]\f$
286  template <typename S>
287  const Vec2<T> &operator*=(const Vec2<S> &v1)
288  {
289  this->mm[0] *= v1[0];
290  this->mm[1] *= v1[1];
291  return *this;
292  }
293 
294  /// Returns v, where \f$v_i /= scalar\f$ for \f$i \in [0, 1]\f$
295  template <typename S>
296  const Vec2<T> &operator/=(S scalar)
297  {
298  this->mm[0] /= scalar;
299  this->mm[1] /= scalar;
300  return *this;
301  }
302 
303  /// Returns v0, where \f$v0_i /= v1_i\f$ for \f$i \in [0, 1]\f$
304  template <typename S>
305  const Vec2<T> &operator/=(const Vec2<S> &v1)
306  {
307  this->mm[0] /= v1[0];
308  this->mm[1] /= v1[1];
309  return *this;
310  }
311 
312  /// Returns v, where \f$v_i += scalar\f$ for \f$i \in [0, 1]\f$
313  template <typename S>
314  const Vec2<T> &operator+=(S scalar)
315  {
316  this->mm[0] += scalar;
317  this->mm[1] += scalar;
318  return *this;
319  }
320 
321  /// Returns v0, where \f$v0_i += v1_i\f$ for \f$i \in [0, 1]\f$
322  template <typename S>
323  const Vec2<T> &operator+=(const Vec2<S> &v1)
324  {
325  this->mm[0] += v1[0];
326  this->mm[1] += v1[1];
327  return *this;
328  }
329 
330  /// Returns v, where \f$v_i += scalar\f$ for \f$i \in [0, 1]\f$
331  template <typename S>
332  const Vec2<T> &operator-=(S scalar)
333  {
334  this->mm[0] -= scalar;
335  this->mm[1] -= scalar;
336  return *this;
337  }
338 
339  /// Returns v0, where \f$v0_i -= v1_i\f$ for \f$i \in [0, 1]\f$
340  template <typename S>
341  const Vec2<T> &operator-=(const Vec2<S> &v1)
342  {
343  this->mm[0] -= v1[0];
344  this->mm[1] -= v1[1];
345  return *this;
346  }
347 
348  // Number of cols, rows, elements
349  static unsigned numRows() { return 1; }
350  static unsigned numColumns() { return 2; }
351  static unsigned numElements() { return 2; }
352 
353  /// Returns the scalar component of v in the direction of onto, onto need
354  /// not be unit. e.g float c = Vec2f::component(v1,v2);
355  T component(const Vec2<T> &onto, T eps=1.0e-8) const
356  {
357  T l = onto.length();
358  if (isApproxEqual(l, T(0), eps)) return 0;
359 
360  return dot(onto)*(T(1)/l);
361  }
362 
363  /// Return the projection of v onto the vector, onto need not be unit
364  /// e.g. Vec2f v = Vec2f::projection(v,n);
365  Vec2<T> projection(const Vec2<T> &onto, T eps=1.0e-8) const
366  {
367  T l = onto.lengthSqr();
368  if (isApproxEqual(l, T(0), eps)) return Vec2::zero();
369 
370  return onto*(dot(onto)*(T(1)/l));
371  }
372 
373  /// Return an arbitrary unit vector perpendicular to v
374  /// Vector v must be a unit vector
375  /// e.g. v.normalize(); Vec2f n = Vec2f::getArbPerpendicular(v);
376  Vec2<T> getArbPerpendicular() const { return Vec2<T>(-this->mm[1], this->mm[0]); }
377 
378  /// True if a Nan is present in vector
379  bool isNan() const { return isnan(this->mm[0]) || isnan(this->mm[1]); }
380 
381  /// True if an Inf is present in vector
382  bool isInfinite() const { return isinf(this->mm[0]) || isinf(this->mm[1]); }
383 
384  /// True if all no Nan or Inf values present
385  bool isFinite() const { return finite(this->mm[0]) && finite(this->mm[1]); }
386 
387  /// Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();
388  static Vec2<T> zero() { return Vec2<T>(0, 0); }
389  static Vec2<T> ones() { return Vec2<T>(1, 1); }
390 };
391 
392 
393 /// Returns V, where \f$V_i = v_i * scalar\f$ for \f$i \in [0, 1]\f$
394 template <typename S, typename T>
396 {
397  return v * scalar;
398 }
399 
400 /// Returns V, where \f$V_i = v_i * scalar\f$ for \f$i \in [0, 1]\f$
401 template <typename S, typename T>
403 {
405  result *= scalar;
406  return result;
407 }
408 
409 /// Returns V, where \f$V_i = v0_i * v1_i\f$ for \f$i \in [0, 1]\f$
410 template <typename T0, typename T1>
412 {
413  Vec2<typename promote<T0, T1>::type> result(v0[0] * v1[0], v0[1] * v1[1]);
414  return result;
415 }
416 
417 /// Returns V, where \f$V_i = scalar / v_i\f$ for \f$i \in [0, 1]\f$
418 template <typename S, typename T>
420 {
421  return Vec2<typename promote<S, T>::type>(scalar/v[0], scalar/v[1]);
422 }
423 
424 /// Returns V, where \f$V_i = v_i / scalar\f$ for \f$i \in [0, 1]\f$
425 template <typename S, typename T>
427 {
429  result /= scalar;
430  return result;
431 }
432 
433 /// Returns V, where \f$V_i = v0_i / v1_i\f$ for \f$i \in [0, 1]\f$
434 template <typename T0, typename T1>
436 {
437  Vec2<typename promote<T0, T1>::type> result(v0[0] / v1[0], v0[1] / v1[1]);
438  return result;
439 }
440 
441 /// Returns V, where \f$V_i = v0_i + v1_i\f$ for \f$i \in [0, 1]\f$
442 template <typename T0, typename T1>
444 {
446  result += v1;
447  return result;
448 }
449 
450 /// Returns V, where \f$V_i = v_i + scalar\f$ for \f$i \in [0, 1]\f$
451 template <typename S, typename T>
453 {
455  result += scalar;
456  return result;
457 }
458 
459 /// Returns V, where \f$V_i = v0_i - v1_i\f$ for \f$i \in [0, 1]\f$
460 template <typename T0, typename T1>
462 {
464  result -= v1;
465  return result;
466 }
467 
468 /// Returns V, where \f$V_i = v_i - scalar\f$ for \f$i \in [0, 1]\f$
469 template <typename S, typename T>
471 {
473  result -= scalar;
474  return result;
475 }
476 
477 /// Angle between two vectors, the result is between [0, pi],
478 /// e.g. float a = Vec2f::angle(v1,v2);
479 template <typename T>
480 inline T angle(const Vec2<T> &v1, const Vec2<T> &v2)
481 {
482  T c = v1.dot(v2);
483  return acos(c);
484 }
485 
486 template <typename T>
487 inline bool
488 isApproxEqual(const Vec2<T>& a, const Vec2<T>& b)
489 {
490  return a.eq(b);
491 }
492 template <typename T>
493 inline bool
494 isApproxEqual(const Vec2<T>& a, const Vec2<T>& b, const Vec2<T>& eps)
495 {
496  return isApproxEqual(a.x(), b.x(), eps.x()) &&
497  isApproxEqual(a.y(), b.y(), eps.y());
498 }
499 
500 template<typename T>
501 inline bool
503 {
504  return isFinite(v[0]) && isFinite(v[1]);
505 }
506 
507 /// Return @c true if all components are exactly equal to zero.
508 template<typename T>
509 inline bool
510 isZero(const Vec2<T>& v)
511 {
512  return isZero(v[0]) && isZero(v[1]);
513 }
514 
515 template<typename T>
516 inline Vec2<T>
517 Abs(const Vec2<T>& v)
518 {
519  return Vec2<T>(Abs(v[0]), Abs(v[1]));
520 }
521 
522 /// Orthonormalize vectors v1 and v2 and store back the resulting basis
523 /// e.g. Vec2f::orthonormalize(v1,v2);
524 template <typename T>
526 {
527  // If the input vectors are v0, v1, and v2, then the Gram-Schmidt
528  // orthonormalization produces vectors u0, u1, and u2 as follows,
529  //
530  // u0 = v0/|v0|
531  // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0|
532  //
533  // where |A| indicates length of vector A and A*B indicates dot
534  // product of vectors A and B.
535 
536  // compute u0
537  v1.normalize();
538 
539  // compute u1
540  T d0 = v1.dot(v2);
541  v2 -= v1*d0;
542  v2.normalize();
543 }
544 
545 
546 /// \remark We are switching to a more explicit name because the semantics
547 /// are different from std::min/max. In that case, the function returns a
548 /// reference to one of the objects based on a comparator. Here, we must
549 /// fabricate a new object which might not match either of the inputs.
550 
551 /// Return component-wise minimum of the two vectors.
552 template <typename T>
553 inline Vec2<T> minComponent(const Vec2<T> &v1, const Vec2<T> &v2)
554 {
555  return Vec2<T>(
556  std::min(v1.x(), v2.x()),
557  std::min(v1.y(), v2.y()));
558 }
559 
560 /// Return component-wise maximum of the two vectors.
561 template <typename T>
562 inline Vec2<T> maxComponent(const Vec2<T> &v1, const Vec2<T> &v2)
563 {
564  return Vec2<T>(
565  std::max(v1.x(), v2.x()),
566  std::max(v1.y(), v2.y()));
567 }
568 
569 /// @brief Return a vector with the exponent applied to each of
570 /// the components of the input vector.
571 template <typename T>
572 inline Vec2<T> Exp(Vec2<T> v) { return v.exp(); }
573 
574 /// @brief Return a vector with log applied to each of
575 /// the components of the input vector.
576 template <typename T>
577 inline Vec2<T> Log(Vec2<T> v) { return v.log(); }
578 
583 
584 } // namespace math
585 } // namespace OPENVDB_VERSION_NAME
586 } // namespace openvdb
587 
588 #endif // OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
589 
590 // Copyright (c) 2012-2017 DreamWorks Animation LLC
591 // All rights reserved. This software is distributed under the
592 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:553
const Vec2< T > & operator-=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:341
Vec2< T > projection(const Vec2< T > &onto, T eps=1.0e-8) const
Definition: Vec2.h:365
const Vec2< T > & div(T0 scalar, const Vec2< T1 > &v)
Definition: Vec2.h:190
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec2.h:95
T length() const
Length of the vector.
Definition: Vec2.h:202
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
bool isFinite() const
True if all no Nan or Inf values present.
Definition: Vec2.h:385
T component(const Vec2< T > &onto, T eps=1.0e-8) const
Definition: Vec2.h:355
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
const GLdouble * v
Definition: glcorearb.h:836
void orthonormalize(Vec2< T > &v1, Vec2< T > &v2)
Definition: Vec2.h:525
Vec2< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec2.h:154
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:527
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:654
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
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
Dummy class for tag dispatch of conversion constructors.
Definition: Tuple.h:47
GLint y
Definition: glcorearb.h:102
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec2.h:106
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
Vec2()
Trivial constructor, the vector is NOT initialized.
Definition: Vec2.h:56
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
bool operator==(const Vec2< T > &v) const
Equality operator, does exact floating point comparisons.
Definition: Vec2.h:138
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
png_uint_32 i
Definition: png.h:2877
Vec2< typename promote< S, T >::type > operator/(S scalar, const Vec2< T > &v)
Returns V, where for .
Definition: Vec2.h:419
Vec2< T > getArbPerpendicular() const
Definition: Vec2.h:376
const Vec2< T > & operator+=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:323
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
SYS_API double log(double x)
Vec2(T val)
Construct a vector all of whose components have the given value.
Definition: Vec2.h:59
Coord Abs(const Coord &xyz)
Definition: Coord.h:254
bool isFinite(const Type &x)
Return true if x is finite.
Definition: Math.h:363
#define OPENVDB_VERSION_NAME
Definition: version.h:43
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
bool isInfinite() const
True if an Inf is present in vector.
Definition: Vec2.h:382
SYS_API double exp(double x)
T product() const
Return the product of all the vector components.
Definition: Vec2.h:236
T sum() const
Return the sum of all the vector components.
Definition: Vec2.h:230
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:480
const Vec2< T > & operator*=(S scalar)
Returns v, where for .
Definition: Vec2.h:278
bool isNan() const
True if a Nan is present in vector.
Definition: Vec2.h:379
SYS_API double acos(double x)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
bool normalize(T eps=1.0e-8)
this = normalized this
Definition: Vec2.h:242
const Vec2< T > & operator*=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:287
bool isApproxEqual(const Type &a, const Type &b)
Return true if a is equal to b to within the default floating-point comparison tolerance.
Definition: Math.h:370
GLfloat v0
Definition: glcorearb.h:815
T dot(const Vec2< T > &v) const
Dot product.
Definition: Vec2.h:199
const Vec2< T > & operator=(const Vec2< Source > &v)
Assignment operator.
Definition: Vec2.h:128
GLsizei const GLfloat * value
Definition: glcorearb.h:823
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec2.h:103
Vec2< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec2.h:260
const Vec2< T > & init(T x=0, T y=0)
Definition: Vec2.h:113
Vec2(T x, T y)
Constructor with two arguments, e.g. Vec2f v(1,2,3);.
Definition: Vec2.h:62
const Vec2< T > & operator/=(S scalar)
Returns v, where for .
Definition: Vec2.h:296
const Vec2< T > & operator+=(S scalar)
Returns v, where for .
Definition: Vec2.h:314
bool operator!=(const Vec2< T > &v) const
Inequality operator, does exact floating point comparisons.
Definition: Vec2.h:144
static Vec2< T > zero()
Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();.
Definition: Vec2.h:388
GLint GLenum GLint x
Definition: glcorearb.h:408
Vec2(Source *a)
Constructor with array argument, e.g. float a[2]; Vec2f v(a);.
Definition: Vec2.h:70
GLfloat GLfloat v1
Definition: glcorearb.h:816
GLuint GLfloat * val
Definition: glcorearb.h:1607
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec2.h:562
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
const Vec2< T > & setZero()
Set "this" vector to zero.
Definition: Vec2.h:120
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:501
const Vec2< T > & operator-=(S scalar)
Returns v, where for .
Definition: Vec2.h:332
const Vec2< T > & scale(T0 scalar, const Vec2< T1 > &v)
Definition: Vec2.h:181
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Vec2< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec2.h:253
const Vec2< T > & operator/=(const Vec2< S > &v1)
Returns v0, where for .
Definition: Vec2.h:305
Vec2< T > unitSafe() const
return normalized this, or (1, 0) if this is null vector
Definition: Vec2.h:270
Vec2(const Tuple< 2, Source > &t)
Conversion constructor.
Definition: Vec2.h:78
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec2.h:99
const Vec2< T > & sub(const Vec2< T0 > &v1, const Vec2< T1 > &v2)
Definition: Vec2.h:170
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:324
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
Type Exp(const Type &x)
Return .
Definition: Math.h:676
const Vec2< T > & add(const Vec2< T0 > &v1, const Vec2< T1 > &v2)
Definition: Vec2.h:159