4 #ifndef OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_VEC2_HAS_BEEN_INCLUDED
12 #include <type_traits>
20 template<
typename T>
class Mat2;
43 template <
typename Source>
46 this->
mm[0] =
static_cast<T>(a[0]);
47 this->
mm[1] =
static_cast<T>(a[1]);
51 template<
typename Source>
54 this->
mm[0] =
static_cast<T>(t[0]);
55 this->
mm[1] =
static_cast<T>(t[1]);
61 template<
typename Other>
65 this->
mm[0] = this->
mm[1] =
static_cast<T>(
val);
69 T&
x() {
return this->
mm[0];}
70 T&
y() {
return this->
mm[1];}
73 T x()
const {
return this->
mm[0];}
74 T y()
const {
return this->
mm[1];}
89 this->
mm[0] =
x; this->
mm[1] =
y;
96 this->
mm[0] = 0; this->
mm[1] = 0;
101 template<
typename Source>
121 bool eq(
const Vec2<T> &
v, T eps = static_cast<T>(1.0e-7))
const
132 template <
typename T0,
typename T1>
135 this->
mm[0] = v1[0] + v2[0];
136 this->
mm[1] = v1[1] + v2[1];
143 template <
typename T0,
typename T1>
146 this->
mm[0] = v1[0] - v2[0];
147 this->
mm[1] = v1[1] - v2[1];
154 template <
typename T0,
typename T1>
157 this->
mm[0] = scalar * v[0];
158 this->
mm[1] = scalar * v[1];
163 template <
typename T0,
typename T1>
166 this->
mm[0] = v[0] / scalar;
167 this->
mm[1] = v[1] / scalar;
178 return static_cast<T>(
sqrt(
double(this->
mm[0]*this->
mm[0] + this->
mm[1]*this->
mm[1])));
206 return this->
mm[0] + this->
mm[1];
212 return this->
mm[0] * this->
mm[1];
247 return l2 ? *
this/
static_cast<T>(
sqrt(l2)) :
Vec2<T>(1,0);
251 template <
typename S>
254 this->
mm[0] *= scalar;
255 this->
mm[1] *= scalar;
260 template <
typename S>
263 this->
mm[0] *= v1[0];
264 this->
mm[1] *= v1[1];
269 template <
typename S>
272 this->
mm[0] /= scalar;
273 this->
mm[1] /= scalar;
278 template <
typename S>
281 this->
mm[0] /= v1[0];
282 this->
mm[1] /= v1[1];
287 template <
typename S>
290 this->
mm[0] += scalar;
291 this->
mm[1] += scalar;
296 template <
typename S>
299 this->
mm[0] += v1[0];
300 this->
mm[1] += v1[1];
305 template <
typename S>
308 this->
mm[0] -= scalar;
309 this->
mm[1] -= scalar;
314 template <
typename S>
317 this->
mm[0] -= v1[0];
318 this->
mm[1] -= v1[1];
334 return dot(onto)*(
T(1)/
l);
344 return onto*(
dot(onto)*(
T(1)/
l));
359 template <
typename S,
typename T>
366 template <
typename S,
typename T>
375 template <
typename T0,
typename T1>
383 template <
typename S,
typename T>
390 template <
typename S,
typename T>
399 template <
typename T0,
typename T1>
407 template <
typename T0,
typename T1>
416 template <
typename S,
typename T>
425 template <
typename T0,
typename T1>
434 template <
typename S,
typename T>
444 template <
typename T>
451 template <
typename T>
457 template <
typename T>
474 template <
typename T>
502 template <
typename T>
511 template <
typename T>
521 template <
typename T>
526 template <
typename T>
538 #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.
bool normalize(T eps=static_cast< T >(1.0e-8))
this = normalized this
vint4 max(const vint4 &a, const vint4 &b)
const Vec2< T > & operator-=(const Vec2< S > &v1)
Subtract each element of the given vector from the corresponding element of this vector.
static unsigned numColumns()
const Vec2< T > & div(T0 scalar, const Vec2< T1 > &v)
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Vec2< T > projection(const Vec2< T > &onto, T eps=static_cast< T >(1.0e-8)) const
T length() const
Length of the vector.
T component(const Vec2< T > &onto, T eps=static_cast< T >(1.0e-8)) const
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
GLuint const GLfloat * val
void orthonormalize(Vec2< T > &v1, Vec2< T > &v2)
Vec2< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
GLboolean GLboolean GLboolean GLboolean a
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
vfloat4 sqrt(const vfloat4 &a)
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
#define OPENVDB_USE_VERSION_NAMESPACE
Vec2< T > Log(Vec2< T > v)
Return a vector with log applied to each of the components of the input vector.
Dummy class for tag dispatch of conversion constructors.
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Vec2()
Trivial constructor, the vector is NOT initialized.
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...
bool operator==(const Vec2< T > &v) const
Equality operator, does exact floating point comparisons.
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.
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.
Vec2< T > getArbPerpendicular() const
const Vec2< T > & operator+=(const Vec2< S > &v1)
Add each element of the given vector to the corresponding element of this vector. ...
GLfloat GLfloat GLfloat v2
static unsigned numRows()
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Vec2(T val)
Construct a vector all of whose components have the given value.
GLint GLint GLint GLint GLint x
Coord Abs(const Coord &xyz)
GLint GLint GLint GLint GLint GLint y
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.
T sum() const
Return the sum of all the vector components.
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
const Vec2< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
SYS_API double acos(double x)
GLuint GLuint GLsizei GLenum type
const Vec2< T > & operator*=(const Vec2< S > &v1)
Multiply each element of this vector by the corresponding element of the given vector.
T dot(const Vec2< T > &v) const
Dot product.
GLdouble GLdouble GLdouble b
const Vec2< T > & operator=(const Vec2< Source > &v)
Assignment operator.
T & operator()(int i)
Alternative indexed reference to the elements.
Vec2< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
const Vec2< T > & init(T x=0, T y=0)
Vec2(T x, T y)
Constructor with two arguments, e.g. Vec2f v(1,2,3);.
const Vec2< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
const Vec2< T > & operator+=(S scalar)
Add scalar to each element of this vector.
bool operator!=(const Vec2< T > &v) const
Inequality operator, does exact floating point comparisons.
static Vec2< T > zero()
Predefined constants, e.g. Vec2f v = Vec2f::xNegAxis();.
Vec2(Source *a)
Constructor with array argument, e.g. float a[2]; Vec2f v(a);.
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
const Vec2< T > & setZero()
Set "this" vector to zero.
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.
const Vec2< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
const Vec2< T > & scale(T0 scalar, const Vec2< T1 > &v)
static unsigned numElements()
Vec2< T > unit(T eps=0) const
return normalized this, throws if null vector
vint4 min(const vint4 &a, const vint4 &b)
const Vec2< T > & operator/=(const Vec2< S > &v1)
Divide each element of this vector by the corresponding element of the given vector.
Vec2< T > unitSafe() const
return normalized this, or (1, 0) if this is null vector
Vec2(const Tuple< 2, Source > &t)
Conversion constructor.
T x() const
Get the component, e.g. float f = v.y();.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
GLsizei const GLfloat * value
const Vec2< T > & sub(const Vec2< T0 > &v1, const Vec2< T1 > &v2)
#define OPENVDB_THROW(exception, message)
const T * asPointer() const
Type Exp(const Type &x)
Return ex.
const Vec2< T > & add(const Vec2< T0 > &v1, const Vec2< T1 > &v2)