58 #define M_PI 3.14159265358979323846
71 THE_NEAR_ZERO_VECTOR_LENGTH = 1e+1f * FLT_MIN;
112 inline bool operator < (const the_duplet_t<T> & d)
const
114 return ((X_ < d.X_) ||
115 (X_ == d.X_ && Y_ < d.Y_));
121 return ((X_ == d.X_) &&
126 inline void assign(
const T * data)
132 inline void assign(
const T & x,
const T & y)
139 inline void scale(
const T & s)
140 { X_ *= s; Y_ *= s; }
144 { X_ += d.X_; Y_ += d.Y_; }
148 { X_ -= d.X_; Y_ -= d.Y_; }
151 inline void dump(ostream & stream,
const char * type_name)
const
153 stream <<
'(' << type_name <<
" *)(" << (
void *)
this <<
") "
154 << setw(12) << X_ <<
' '
159 inline const T & x()
const {
return X_; }
160 inline const T & y()
const {
return Y_; }
163 inline T & x() {
return X_; }
164 inline T & y() {
return Y_; }
167 inline const T & operator[] (
const unsigned int & i)
const
170 inline T & operator[] (
const unsigned int & i)
174 inline const T * data()
const
189 operator << (ostream & stream, const the_duplet_t<T> & p)
191 p.dump(stream,
"the_duplet_t<T>");
227 inline bool operator < (const the_duplet_t<T> & d)
const
229 return ((X_ < d.X_) ||
230 (X_ == d.X_ && Y_ < d.Y_) ||
231 (X_ == d.X_ && Y_ == d.Y_ && Z_ < d.Z_));
237 return ((X_ == d.X_) &&
243 inline void assign(
const T * data)
250 inline void assign(
const T & x,
const T & y,
const T & z)
258 inline void get(T * data)
const
259 {
get(data[0], data[1], data[2]); }
261 inline void get(T & x, T & y, T & z)
const
262 { x = X_; y = Y_; z = Z_; }
265 inline void scale(
const T & s)
266 { X_ *= s; Y_ *= s; Z_ *= s; }
270 { X_ = -X_; Y_ = -Y_; Z_ = -Z_; }
274 { X_ += d.X_; Y_ += d.Y_; Z_ += d.Z_; }
278 { X_ -= d.X_; Y_ -= d.Y_; Z_ -= d.Z_; }
281 inline void dump(ostream & stream,
const char * type_name)
const
283 stream <<
'(' << type_name <<
" *)(" << (
void *)
this <<
") "
284 << setw(12) << X_ <<
' '
285 << setw(12) << Y_ <<
' '
290 inline const T & x()
const {
return X_; }
291 inline const T & y()
const {
return Y_; }
292 inline const T & z()
const {
return Z_; }
295 inline T & x() {
return X_; }
296 inline T & y() {
return Y_; }
297 inline T & z() {
return Z_; }
300 inline const T & operator[] (
const unsigned int & i)
const
303 inline T & operator[] (
const unsigned int & i)
307 inline const T * data()
const
322 operator << (ostream & stream, const the_triplet_t<T> & p)
324 p.dump(stream,
"the_triplet_t<T>");
362 inline bool operator < (const the_duplet_t<T> & d)
const
364 return ((X_ < d.X_) ||
365 (X_ == d.X_ && Y_ < d.Y_) ||
366 (X_ == d.X_ && Y_ == d.Y_ && Z_ < d.Z_) ||
367 (X_ == d.X_ && Y_ == d.Y_ && Z_ == d.Z_ && W_ < d.W_));
373 return ((X_ == d.X_) &&
380 inline void assign(
const T * data)
388 inline void assign(
const T & x,
const T & y,
const T & z,
const T & w)
397 inline void scale(
const T & s)
398 { X_ *= s; Y_ *= s; Z_ *= s; W_ *= s; }
402 { X_ += d.X_; Y_ += d.Y_; Z_ += d.Z_; W_ += d.W_; }
406 { X_ -= d.X_; Y_ -= d.Y_; Z_ -= d.Z_; W_ -= d.W_; }
409 inline void dump(ostream & stream,
const char * type_name)
const
411 stream <<
'(' << type_name <<
" *)(" << (
void *)
this <<
") "
412 << setw(12) << X_ <<
' '
413 << setw(12) << Y_ <<
' '
414 << setw(12) << Z_ <<
' '
419 inline const T & x()
const {
return X_; }
420 inline const T & y()
const {
return Y_; }
421 inline const T & z()
const {
return Z_; }
422 inline const T & w()
const {
return W_; }
425 inline T & x() {
return X_; }
426 inline T & y() {
return Y_; }
427 inline T & z() {
return Z_; }
428 inline T & w() {
return W_; }
431 inline const T & operator[] (
const unsigned int & i)
const
434 inline T & operator[] (
const unsigned int & i)
438 inline const T * data()
const
453 operator << (ostream & stream, const the_quadruplet_t<T> & p)
455 p.dump(stream,
"the_quadruplet_t<T>");
468 v2x1_t(
const float * data):
472 v2x1_t(
const float & x,
const float & y):
477 inline bool operator == (
const v2x1_t & v)
const {
return equal(v); }
478 inline bool operator != (
const v2x1_t & v)
const {
return !equal(v); }
481 inline v2x1_t & operator *= (
const float & s)
482 { scale(s);
return *
this; }
484 inline v2x1_t & operator /= (
const float & s)
485 { scale(1 / s);
return *
this; }
488 inline const v2x1_t operator * (
const float & s)
const
489 {
v2x1_t r(*
this); r *= s;
return r; }
491 inline const v2x1_t operator / (
const float & s)
const
492 {
v2x1_t r(*
this); r /= s;
return r; }
496 { increment(v);
return *
this; }
499 { decrement(v);
return *
this; }
503 {
v2x1_t r(*
this); r += v;
return r; }
506 {
v2x1_t r(*
this); r -= v;
return r; }
509 inline float operator * (
const v2x1_t & v)
const
510 {
return (X_ * v.X_ + Y_ * v.Y_); }
513 inline float operator ~ ()
const {
return norm(); }
517 inline const v2x1_t operator ! ()
const
518 {
v2x1_t r(*
this); r.normalize();
return r; }
521 inline bool normalize()
524 if (n < THE_NEAR_ZERO_VECTOR_LENGTH)
535 inline bool operator < (
const v2x1_t & v)
const
536 {
return norm_sqrd() < v.norm_sqrd(); }
539 inline float norm_sqrd()
const
540 {
return operator * (*
this); }
543 inline float norm()
const
544 {
return sqrtf(norm_sqrd()); }
551 operator - (
const v2x1_t & v)
560 operator * (
const float & s,
const v2x1_t & v)
569 operator << (ostream & stream,
const v2x1_t & v)
571 v.dump(stream,
"v2x1_t");
584 v3x1_t(
const float * data):
588 v3x1_t(
const float x,
const float & y,
const float & z):
597 inline bool operator == (
const v3x1_t & v)
const {
return equal(v); }
598 inline bool operator != (
const v3x1_t & v)
const {
return !equal(v); }
601 inline v3x1_t & operator *= (
const float & s)
602 { scale(s);
return *
this; }
604 inline v3x1_t & operator /= (
const float & s)
605 { scale(1 / s);
return *
this; }
608 inline const v3x1_t operator * (
const float & s)
const
609 {
v3x1_t r(*
this); r *= s;
return r; }
611 inline const v3x1_t operator / (
const float & s)
const
612 {
v3x1_t r(*
this); r /= s;
return r; }
616 { increment(v);
return *
this; }
619 { decrement(v);
return *
this; }
623 {
v3x1_t r(*
this); r += v;
return r; }
626 {
v3x1_t r(*
this); r -= v;
return r; }
629 inline float operator * (
const v3x1_t & v)
const
630 {
return (X_ * v.X_ + Y_ * v.Y_ + Z_ * v.Z_); }
635 return v3x1_t((Y_ * v.Z_) - (Z_ * v.Y_),
636 (Z_ * v.X_) - (X_ * v.Z_),
637 (X_ * v.Y_) - (v.X_ * Y_));
641 inline float operator ~ ()
const {
return norm(); }
645 inline const v3x1_t operator ! ()
const
646 {
v3x1_t r(*
this); r.normalize();
return r; }
649 inline bool normalize()
652 if (n < THE_NEAR_ZERO_VECTOR_LENGTH)
663 inline bool operator < (
const v3x1_t & v)
const
664 {
return norm_sqrd() < v.norm_sqrd(); }
667 inline float norm_sqrd()
const
668 {
return operator * (*
this); }
671 inline float norm()
const
672 {
return sqrtf(norm_sqrd()); }
675 inline const v3x1_t normal()
const
677 static const v3x1_t xyz[] =
684 v3x1_t unit_vec = !(*this);
685 for (
unsigned int i = 0; i < 3; i++)
687 if (fabsf(unit_vec * xyz[i]) > 0.7)
continue;
688 return !(unit_vec % xyz[i]);
693 return v3x1_t(0.0, 0.0, 0.0);
697 inline operator v2x1_t()
const
698 {
return v2x1_t(X_, Y_); }
705 operator - (
const v3x1_t & v)
707 return v3x1_t(-v.x(), -v.y(), -v.z());
714 operator * (
const float & s,
const v3x1_t & v)
723 operator << (ostream & stream,
const v3x1_t & v)
725 v.dump(stream,
"v3x1_t");
738 p2x1_t(
const float * data):
742 p2x1_t(
const float & x,
const float & y):
747 inline bool operator == (
const p2x1_t & p)
const {
return equal(p); }
748 inline bool operator != (
const p2x1_t & p)
const {
return !equal(p); }
751 inline bool operator < (
const p2x1_t & p)
const
754 return (*
this - zero) < (p - zero);
758 inline p2x1_t & operator *= (
const float & s)
759 { scale(s);
return *
this; }
761 inline p2x1_t & operator /= (
const float & s)
762 { scale(1 / s);
return *
this; }
765 inline const p2x1_t operator * (
const float & s)
const
766 {
p2x1_t r(*
this); r *= s;
return r; }
768 inline const p2x1_t operator / (
const float & s)
const
769 {
p2x1_t r(*
this); r /= s;
return r; }
773 {
p2x1_t r(*
this); r.increment(p);
return r; }
777 { increment(v);
return *
this; }
780 { decrement(v);
return *
this; }
784 {
p2x1_t r(data_); r += v;
return r; }
787 {
p2x1_t r(data_); r -= v;
return r; }
791 {
v2x1_t r(data_); r.decrement(p);
return r; }
807 operator * (
const float & s,
const p2x1_t & p)
816 operator << (ostream & stream,
const p2x1_t & p)
818 p.dump(stream,
"p2x1_t");
831 p3x1_t(
const float * data):
835 p3x1_t(
const float & x,
const float & y,
const float & z):
844 inline bool operator == (
const p3x1_t & p)
const {
return equal(p); }
845 inline bool operator != (
const p3x1_t & p)
const {
return !equal(p); }
848 inline bool operator < (
const p3x1_t & p)
const
850 p3x1_t zero(0.0, 0.0, 0.0);
851 return (*
this - zero) < (p - zero);
855 inline p3x1_t & operator *= (
const float & s)
856 { scale(s);
return *
this; }
858 inline p3x1_t & operator /= (
const float & s)
859 { scale(1 / s);
return *
this; }
862 inline const p3x1_t operator * (
const float & s)
const
863 {
p3x1_t r(*
this); r *= s;
return r; }
865 inline const p3x1_t operator / (
const float & s)
const
866 {
p3x1_t r(*
this); r /= s;
return r; }
870 {
p3x1_t r(*
this); r.increment(p);
return r; }
874 { increment(v);
return *
this; }
877 { increment(p);
return *
this; }
880 { decrement(v);
return *
this; }
884 {
p3x1_t r(data_); r += v;
return r; }
887 {
p3x1_t r(data_); r -= v;
return r; }
891 {
v3x1_t r(data_); r.decrement(p);
return r; }
894 inline operator p2x1_t()
const
895 {
return p2x1_t(X_, Y_); }
911 operator * (
const float & s,
const p3x1_t & p)
920 operator << (ostream & stream,
const p3x1_t & p)
922 p.dump(stream,
"p3x1_t");
935 p4x1_t(
const float * data):
951 inline void homogenize()
952 { X_ = X_ / W_; Y_ = Y_ / W_; Z_ = Z_ / W_; W_ = 1.0; }
955 inline operator p3x1_t()
const
956 {
return p3x1_t(X_ / W_, Y_ / W_, Z_ / W_); }
963 operator << (ostream & stream,
const p4x1_t & p)
965 p.dump(stream,
"p4x1_t");
977 #endif // V3X1P3X1_HXX_
Definition: v3x1p3x1.hxx:826
Definition: v3x1p3x1.hxx:202
Definition: v3x1p3x1.hxx:579
Definition: v3x1p3x1.hxx:930
Definition: v3x1p3x1.hxx:335
Definition: v3x1p3x1.hxx:733
Definition: v3x1p3x1.hxx:91
Definition: v3x1p3x1.hxx:463