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>
108 x() = (T_Scalar)other.x();
109 y() = (T_Scalar)other.y();
188 *
this = *
this + other;
193 *
this = *
this - other;
198 *
this = *
this * other;
203 *
this = *
this / other;
239 return x() == other.
x() &&
y() == other.
y();
247 if (
x() != other.
x())
248 return x() < other.
x();
250 return y() < other.
y();
263 *
this *= (T_Scalar)(1.0/l);
294 #if VL_PIPELINE_PRECISION == 2 302 inline float dot(
const fvec2& v1,
const fvec2& v2) {
return v1.
x()*v2.
x() + v1.
y()*v2.
y(); }
303 inline double dot(
const dvec2& v1,
const dvec2& v2) {
return v1.
x()*v2.
x() + v1.
y()*v2.
y(); }
304 inline float dot(
const ivec2& v1,
const ivec2& v2) {
return (
float)(v1.
x()*v2.
x() + v1.
y()*v2.
y()); }
305 inline float dot(
const uvec2& v1,
const uvec2& v2) {
return (
float)(v1.
x()*v2.
x() + v1.
y()*v2.
y()); }
307 inline float min(
float a,
float b) {
return a < b ? a : b; }
308 inline double min(
double a,
double b) {
return a < b ? a : b; }
309 inline int min(
int a,
int b) {
return a < b ? a : b; }
310 inline unsigned int min(
unsigned int a,
unsigned int b) {
return a < b ? a : b; }
311 inline float max(
float a,
float b) {
return a > b ? a : b; }
312 inline double max(
double a,
double b) {
return a > b ? a : b; }
313 inline int max(
int a,
int b) {
return a > b ? a : b; }
314 inline unsigned int max(
unsigned int a,
unsigned int b) {
return a > b ? a : b; }
315 inline float clamp(
float x,
float minval,
float maxval) {
return min(
max(x,minval),maxval); }
316 inline double clamp(
double x,
double minval,
double maxval) {
return min(
max(x,minval),maxval); }
317 inline int clamp(
int x,
int minval,
int maxval) {
return min(
max(x,minval),maxval); }
318 inline unsigned int clamp(
unsigned int x,
unsigned int minval,
unsigned int maxval) {
return min(
max(x,minval),maxval); }
320 inline fvec2
min(
const fvec2& a,
const fvec2& b)
322 return fvec2( a.
x() < b.
x() ? a.
x() : b.
x(),
323 a.
y() < b.
y() ? a.
y() : b.
y());
325 inline fvec2
min(
const fvec2& a,
float b)
327 return fvec2( a.
x() < b ? a.
x() : b,
328 a.
y() < b ? a.
y() : b);
330 inline dvec2
min(
const dvec2& a,
const dvec2& b)
332 return dvec2( a.
x() < b.
x() ? a.
x() : b.
x(),
333 a.
y() < b.
y() ? a.
y() : b.
y());
335 inline dvec2
min(
const dvec2& a,
double b)
337 return dvec2( a.
x() < b ? a.
x() : b,
338 a.
y() < b ? a.
y() : b);
340 inline ivec2
min(
const ivec2& a,
const ivec2& b)
342 return ivec2( a.
x() < b.
x() ? a.
x() : b.
x(),
343 a.
y() < b.
y() ? a.
y() : b.
y());
345 inline ivec2
min(
const ivec2& a,
int b)
347 return ivec2( a.
x() < b ? a.
x() : b,
348 a.
y() < b ? a.
y() : b);
350 inline uvec2
min(
const uvec2& a,
const uvec2& b)
352 return uvec2( a.
x() < b.
x() ? a.
x() : b.
x(),
353 a.
y() < b.
y() ? a.
y() : b.
y());
355 inline uvec2
min(
const uvec2& a,
unsigned int b)
357 return uvec2( a.
x() < b ? a.
x() : b,
358 a.
y() < b ? a.
y() : b);
360 inline fvec2
max(
const fvec2& a,
const fvec2& b)
362 return fvec2( a.
x() > b.
x() ? a.
x() : b.
x(),
363 a.
y() > b.
y() ? a.
y() : b.
y());
365 inline fvec2
max(
const fvec2& a,
float b)
367 return fvec2( a.
x() > b ? a.
x() : b,
368 a.
y() > b ? a.
y() : b);
370 inline dvec2
max(
const dvec2& a,
const dvec2& b)
372 return dvec2( a.
x() > b.
x() ? a.
x() : b.
x(),
373 a.
y() > b.
y() ? a.
y() : b.
y());
375 inline dvec2
max(
const dvec2& a,
double b)
377 return dvec2( a.
x() > b ? a.
x() : b,
378 a.
y() > b ? a.
y() : b);
380 inline ivec2
max(
const ivec2& a,
const ivec2& b)
382 return ivec2( a.
x() > b.
x() ? a.
x() : b.
x(),
383 a.
y() > b.
y() ? a.
y() : b.
y());
385 inline ivec2
max(
const ivec2& a,
int b)
387 return ivec2( a.
x() > b ? a.
x() : b,
388 a.
y() > b ? a.
y() : b);
390 inline uvec2
max(
const uvec2& a,
const uvec2& b)
392 return uvec2( a.
x() > b.
x() ? a.
x() : b.
x(),
393 a.
y() > b.
y() ? a.
y() : b.
y());
395 inline uvec2
max(
const uvec2& a,
unsigned int b)
397 return uvec2( a.
x() > b ? a.
x() : b,
398 a.
y() > b ? a.
y() : b);
400 inline fvec2
clamp(
const fvec2&
x,
float minval,
float maxval) {
return min(
max(x,minval),maxval); }
401 inline fvec2
clamp(
const fvec2&
x,
const fvec2& minval,
const fvec2& maxval) {
return min(
max(x,minval),maxval); }
402 inline dvec2
clamp(
const dvec2&
x,
double minval,
double maxval) {
return min(
max(x,minval),maxval); }
403 inline dvec2
clamp(
const dvec2&
x,
const dvec2& minval,
const dvec2& maxval) {
return min(
max(x,minval),maxval); }
404 inline ivec2
clamp(
const ivec2&
x,
int minval,
int maxval) {
return min(
max(x,minval),maxval); }
405 inline ivec2
clamp(
const ivec2&
x,
const ivec2& minval,
const ivec2& maxval) {
return min(
max(x,minval),maxval); }
406 inline uvec2
clamp(
const uvec2&
x,
unsigned int minval,
unsigned int maxval) {
return min(
max(x,minval),maxval); }
407 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.
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 & 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