32 #ifndef Vector2_INCLUDE_ONCE 33 #define Vector2_INCLUDE_ONCE 59 #if VL_FAST_SQUARE_ROOTS == 1 60 #define VL_FLOAT_SQRT(x) fast_sqrt(x) 61 #define VL_FLOAT_INVSQRT(x) fast2_inversesqrt(x) 63 #define VL_FLOAT_SQRT(x) ((float)::sqrt(x)) 64 #define VL_FLOAT_INVSQRT(x) (1.0f/(float)::sqrt(x)) 72 union {
float f;
unsigned int i; } num;
74 num.i = 0x5f3759df - (num.i>>1);
76 x = x*(1.5f - xhalf*x*x);
82 union {
float f;
unsigned int i; } num;
84 num.i = 0x5f3759df - (num.i>>1);
86 x = x*(1.5f - xhalf*x*x);
87 x = x*(1.5f - xhalf*x*x);
96 template<
typename T_Scalar>
109 x() = (T_Scalar)other.x();
110 y() = (T_Scalar)other.y();
189 *
this = *
this + other;
194 *
this = *
this - other;
199 *
this = *
this * other;
204 *
this = *
this / other;
240 return x() == other.
x() &&
y() == other.
y();
248 if (
x() != other.
x())
249 return x() < other.
x();
251 return y() < other.
y();
264 *
this *= (T_Scalar)(1.0/l);
295 #if VL_PIPELINE_PRECISION == 2 303 inline float dot(
const fvec2& v1,
const fvec2& v2) {
return v1.
x()*v2.
x() + v1.
y()*v2.
y(); }
304 inline double dot(
const dvec2& v1,
const dvec2& v2) {
return v1.
x()*v2.
x() + v1.
y()*v2.
y(); }
305 inline float dot(
const ivec2& v1,
const ivec2& v2) {
return (
float)(v1.
x()*v2.
x() + v1.
y()*v2.
y()); }
306 inline float dot(
const uvec2& v1,
const uvec2& v2) {
return (
float)(v1.
x()*v2.
x() + v1.
y()*v2.
y()); }
308 inline float min(
float a,
float b) {
return a < b ? a : b; }
309 inline double min(
double a,
double b) {
return a < b ? a : b; }
310 inline int min(
int a,
int b) {
return a < b ? a : b; }
311 inline unsigned int min(
unsigned int a,
unsigned int b) {
return a < b ? a : b; }
312 inline float max(
float a,
float b) {
return a > b ? a : b; }
313 inline double max(
double a,
double b) {
return a > b ? a : b; }
314 inline int max(
int a,
int b) {
return a > b ? a : b; }
315 inline unsigned int max(
unsigned int a,
unsigned int b) {
return a > b ? a : b; }
316 inline float clamp(
float x,
float minval,
float maxval) {
return min(
max(x,minval),maxval); }
317 inline double clamp(
double x,
double minval,
double maxval) {
return min(
max(x,minval),maxval); }
318 inline int clamp(
int x,
int minval,
int maxval) {
return min(
max(x,minval),maxval); }
319 inline unsigned int clamp(
unsigned int x,
unsigned int minval,
unsigned int maxval) {
return min(
max(x,minval),maxval); }
321 inline fvec2
min(
const fvec2& a,
const fvec2& b)
323 return fvec2( a.
x() < b.
x() ? a.
x() : b.
x(),
324 a.
y() < b.
y() ? a.
y() : b.
y());
326 inline fvec2
min(
const fvec2& a,
float b)
328 return fvec2( a.
x() < b ? a.
x() : b,
329 a.
y() < b ? a.
y() : b);
331 inline dvec2
min(
const dvec2& a,
const dvec2& b)
333 return dvec2( a.
x() < b.
x() ? a.
x() : b.
x(),
334 a.
y() < b.
y() ? a.
y() : b.
y());
336 inline dvec2
min(
const dvec2& a,
double b)
338 return dvec2( a.
x() < b ? a.
x() : b,
339 a.
y() < b ? a.
y() : b);
341 inline ivec2
min(
const ivec2& a,
const ivec2& b)
343 return ivec2( a.
x() < b.
x() ? a.
x() : b.
x(),
344 a.
y() < b.
y() ? a.
y() : b.
y());
346 inline ivec2
min(
const ivec2& a,
int b)
348 return ivec2( a.
x() < b ? a.
x() : b,
349 a.
y() < b ? a.
y() : b);
351 inline uvec2
min(
const uvec2& a,
const uvec2& b)
353 return uvec2( a.
x() < b.
x() ? a.
x() : b.
x(),
354 a.
y() < b.
y() ? a.
y() : b.
y());
356 inline uvec2
min(
const uvec2& a,
unsigned int b)
358 return uvec2( a.
x() < b ? a.
x() : b,
359 a.
y() < b ? a.
y() : b);
361 inline fvec2
max(
const fvec2& a,
const fvec2& b)
363 return fvec2( a.
x() > b.
x() ? a.
x() : b.
x(),
364 a.
y() > b.
y() ? a.
y() : b.
y());
366 inline fvec2
max(
const fvec2& a,
float b)
368 return fvec2( a.
x() > b ? a.
x() : b,
369 a.
y() > b ? a.
y() : b);
371 inline dvec2
max(
const dvec2& a,
const dvec2& b)
373 return dvec2( a.
x() > b.
x() ? a.
x() : b.
x(),
374 a.
y() > b.
y() ? a.
y() : b.
y());
376 inline dvec2
max(
const dvec2& a,
double b)
378 return dvec2( a.
x() > b ? a.
x() : b,
379 a.
y() > b ? a.
y() : b);
381 inline ivec2
max(
const ivec2& a,
const ivec2& b)
383 return ivec2( a.
x() > b.
x() ? a.
x() : b.
x(),
384 a.
y() > b.
y() ? a.
y() : b.
y());
386 inline ivec2
max(
const ivec2& a,
int b)
388 return ivec2( a.
x() > b ? a.
x() : b,
389 a.
y() > b ? a.
y() : b);
391 inline uvec2
max(
const uvec2& a,
const uvec2& b)
393 return uvec2( a.
x() > b.
x() ? a.
x() : b.
x(),
394 a.
y() > b.
y() ? a.
y() : b.
y());
396 inline uvec2
max(
const uvec2& a,
unsigned int b)
398 return uvec2( a.
x() > b ? a.
x() : b,
399 a.
y() > b ? a.
y() : b);
401 inline fvec2
clamp(
const fvec2&
x,
float minval,
float maxval) {
return min(
max(x,minval),maxval); }
402 inline fvec2
clamp(
const fvec2&
x,
const fvec2& minval,
const fvec2& maxval) {
return min(
max(x,minval),maxval); }
403 inline dvec2
clamp(
const dvec2&
x,
double minval,
double maxval) {
return min(
max(x,minval),maxval); }
404 inline dvec2
clamp(
const dvec2&
x,
const dvec2& minval,
const dvec2& maxval) {
return min(
max(x,minval),maxval); }
405 inline ivec2
clamp(
const ivec2&
x,
int minval,
int maxval) {
return min(
max(x,minval),maxval); }
406 inline ivec2
clamp(
const ivec2&
x,
const ivec2& minval,
const ivec2& maxval) {
return min(
max(x,minval),maxval); }
407 inline uvec2
clamp(
const uvec2&
x,
unsigned int minval,
unsigned int maxval) {
return min(
max(x,minval),maxval); }
408 inline uvec2
clamp(
const uvec2&
x,
const uvec2& minval,
const uvec2& maxval) {
return min(
max(x,minval),maxval); }
Vector2 operator-(T_Scalar val) const
float clamp(float x, float minval, float maxval)
Vector2< int > ivec2
A 2 components vector with int precision.
const T_Scalar & t() const
Vector2 & operator*=(const Vector2 &other)
Vector2(T_Scalar x, T_Scalar y)
Vector2< double > dvec2
A 2 components vector with double precision.
const T_Scalar & g() const
fvec2 vec2
Defined as: 'typedef fvec2 vec2'. See also VL_PIPELINE_PRECISION.
static const int scalar_count
T_Scalar & operator[](unsigned i)
Vector2< unsigned int > uvec2
A 2 components vector with unsigned int precision.
T_Scalar mScalar[scalar_count]
const T_Scalar & s() const
Vector2 operator-() const
const Vector2 & normalize(T_Scalar *len=NULL)
T_Scalar lengthSquared() const
Vector2 operator-(const Vector2 &other) const
Vector2 & operator-=(T_Scalar val)
Vector2 operator+(T_Scalar val) const
Vector2 operator*(T_Scalar val) const
Vector2(const Vector2 &other)
Vector2 operator*(const Vector2 &other) const
Vector2 & operator-=(const Vector2 &other)
Visualization Library main namespace.
float dot(float a, float b)
Vector2< float > fvec2
A 2 components vector with float precision.
T_Scalar * scalar_ptr_type
Vector2 & operator/=(const Vector2 &other)
Vector2< unsigned char > ubvec2
A 2 components vector with unsigned char precision.
bool operator==(const Vector2 &other) const
const T_Scalar & r() const
const T_Scalar & operator[](unsigned i) const
bool operator<(const Vector2 &other) const
float max(float a, float b)
float min(float a, float b)
Vector2 & operator=(T_Scalar val)
float fast1_inversesqrt(float x)
Vector2 & operator+=(T_Scalar val)
Vector2(const scalar_ptr_type &pval)
Vector2 & operator=(const Vector2 &other)
Vector2< char > bvec2
A 2 components vector with char precision.
float fast2_inversesqrt(float x)
The Vector2 class is a template class that implements a generic 2 components vector, see also vl::fvec2, vl::dvec2, vl::uvec2, vl::ivec2, vl::svec2, vl::usvec2, vl::bvec2, vl::ubvec2.
Vector2< short > svec2
A 2 components vector with short precision.
Vector2 operator+(const Vector2 &other) const
Vector2 & operator+=(const Vector2 &other)
Vector2 operator/(const Vector2 &other) const
Vector2< unsigned short > usvec2
A 2 components vector with unsigned short precision.
Vector2 operator/(T_Scalar val) const
const T_Scalar & x() const
bool operator!=(const Vector2 &other) const
Vector2 & operator/=(T_Scalar val)
const T_Scalar & y() const
Vector2 & operator*=(T_Scalar val)
const T_Scalar * ptr() const