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