OpenVDB: openvdb/math/Vec2.h Source File

OpenVDB 9.1.0

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