1 #ifndef GUI_MATH___GLOBALS__HPP
2 #define GUI_MATH___GLOBALS__HPP
46 template <
class T>
class CVect2;
47 template <
class T>
class CVect3;
48 template <
class T>
class CVect4;
88 template <
class T,
class U>
94 (v1[0]+
v2[0], v1[1]+
v2[1]);
98 template <
class T,
class U>
104 (v1[0]+
v2[0], v1[1]+
v2[1], v1[2]+
v2[2]);
108 template <
class T,
class U>
114 (v1[0]+
v2[0], v1[1]+
v2[1], v1[2]+
v2[2], v1[3]+
v2[3]);
124 #define NCBI_ADD_VECT2(type) \
126 inline CVect2< NCBI_PROMOTE(type,U) > \
127 operator+ (type v1, const CVect2<U>& v2) \
130 CVect2< NCBI_PROMOTE(type,U) > \
131 (v1 + v2[0], v1 + v2[1]); \
134 inline CVect2< NCBI_PROMOTE(T,type) > \
135 operator+ (const CVect2<T>& v1, type v2) \
138 CVect2< NCBI_PROMOTE(T,type) > \
139 (v1[0] + v2, v1[1] + v2); \
147 #undef NCBI_ADD_VECT2
150 #define NCBI_ADD_VECT3(type) \
152 inline CVect3< NCBI_PROMOTE(type,U) > \
153 operator+ (type v1, const CVect3<U>& v2) \
156 CVect3< NCBI_PROMOTE(type,U) > \
157 (v1 + v2[0], v1 + v2[1], v1 + v2[2]); \
160 inline CVect3< NCBI_PROMOTE(T,type) > \
161 operator+ (const CVect3<T>& v1, type v2) \
164 CVect3< NCBI_PROMOTE(T,type) > \
165 (v1[0] + v2, v1[1] + v2, v1[2] + v2); \
173 #undef NCBI_ADD_VECT3
176 #define NCBI_ADD_VECT4(type) \
178 inline CVect4< NCBI_PROMOTE(type,U) > \
179 operator+ (type v1, const CVect4<U>& v2) \
182 CVect4< NCBI_PROMOTE(type,U) > \
183 (v1 + v2[0], v1 + v2[1], v1 + v2[2], v1 + v2[3]); \
186 inline CVect4< NCBI_PROMOTE(T,type) > \
187 operator+ (const CVect4<T>& v1, type v2) \
190 CVect4< NCBI_PROMOTE(T,type) > \
191 (v1[0] + v2, v1[1] + v2, v1[2] + v2, v1[3] + v2); \
199 #undef NCBI_ADD_VECT4
225 return CVect4<T> (-v[0], -v[1], -v[2], -v[3]);
231 template <
class T,
class U>
237 (v1[0]-
v2[0], v1[1]-
v2[1]);
241 template <
class T,
class U>
247 (v1[0]-
v2[0], v1[1]-
v2[1], v1[2]-
v2[2]);
251 template <
class T,
class U>
257 (v1[0]-
v2[0], v1[1]-
v2[1], v1[2]-
v2[2], v1[3]-
v2[3]);
267 #define NCBI_SUBTRACT_VECT2(type) \
269 inline CVect2< NCBI_PROMOTE(type,U) > \
270 operator- (type v1, const CVect2<U>& v2) \
273 CVect2< NCBI_PROMOTE(type,U) > \
274 (v1 - v2[0], v1 - v2[1]); \
277 inline CVect2< NCBI_PROMOTE(T,type) > \
278 operator- (const CVect2<T>& v1, type v2) \
281 CVect2< NCBI_PROMOTE(T,type) > \
282 (v1[0] - v2, v1[1] - v2); \
290 #undef NCBI_SUBTRACT_VECT2
293 #define NCBI_SUBTRACT_VECT3(type) \
295 inline CVect3< NCBI_PROMOTE(type,U) > \
296 operator- (type v1, const CVect3<U>& v2) \
299 CVect3< NCBI_PROMOTE(type,U) > \
300 (v1 - v2[0], v1 - v2[1], v1 - v2[2]); \
303 inline CVect3< NCBI_PROMOTE(T,type) > \
304 operator- (const CVect3<T>& v1, type v2) \
307 CVect3< NCBI_PROMOTE(T,type) > \
308 (v1[0] - v2, v1[1] - v2, v1[2] - v2); \
316 #undef NCBI_SUBTRACT_VECT3
319 #define NCBI_SUBTRACT_VECT4(type) \
321 inline CVect4< NCBI_PROMOTE(type,U) > \
322 operator- (type v1, const CVect4<U>& v2) \
325 CVect4< NCBI_PROMOTE(type,U) > \
326 (v1 - v2[0], v1 - v2[1], v1 - v2[2], v1 - v2[3]); \
329 inline CVect4< NCBI_PROMOTE(T,type) > \
330 operator- (const CVect4<T>& v1, type v2) \
333 CVect4< NCBI_PROMOTE(T,type) > \
334 (v1[0] - v2, v1[1] - v2, v1[2] - v2, v1[3] - v2); \
342 #undef NCBI_SUBTRACT_VECT4
352 #define NCBI_MULTIPLY_VECT2(type) \
354 inline CVect2< NCBI_PROMOTE(type,U) > \
355 operator* (type v1, const CVect2<U>& v2) \
358 CVect2< NCBI_PROMOTE(type,U) > \
359 (v1 * v2[0], v1 * v2[1]); \
362 inline CVect2< NCBI_PROMOTE(T,type) > \
363 operator* (const CVect2<T>& v1, type v2) \
366 CVect2< NCBI_PROMOTE(T,type) > \
367 (v1[0] * v2, v1[1] * v2); \
375 #undef NCBI_MULTIPLY_VECT2
378 #define NCBI_MULTIPLY_VECT3(type) \
380 inline CVect3< NCBI_PROMOTE(type,U) > \
381 operator* (type v1, const CVect3<U>& v2) \
384 CVect3< NCBI_PROMOTE(type,U) > \
385 (v1 * v2[0], v1 * v2[1], v1 * v2[2]); \
388 inline CVect3< NCBI_PROMOTE(T,type) > \
389 operator* (const CVect3<T>& v1, type v2) \
392 CVect3< NCBI_PROMOTE(T,type) > \
393 (v1[0] * v2, v1[1] * v2, v1[2] * v2); \
401 #undef NCBI_MULTIPLY_VECT3
404 #define NCBI_MULTIPLY_VECT4(type) \
406 inline CVect4< NCBI_PROMOTE(type,U) > \
407 operator* (type v1, const CVect4<U>& v2) \
410 CVect4< NCBI_PROMOTE(type,U) > \
411 (v1 * v2[0], v1 * v2[1], v1 * v2[2], v1 * v2[3]); \
414 inline CVect4< NCBI_PROMOTE(T,type) > \
415 operator* (const CVect4<T>& v1, type v2) \
418 CVect4< NCBI_PROMOTE(T,type) > \
419 (v1[0] * v2, v1[1] * v2, v1[2] * v2, v1[3] * v2); \
427 #undef NCBI_MULTIPLY_VECT4
437 template <
class T,
class U>
441 return (v1[0] *
v2[0] +
446 template <
class T,
class U>
450 return (v1[0] *
v2[0] +
456 template <
class T,
class U>
460 return (v1[0] *
v2[0] +
471 template <
class T,
class U>
478 (v1[0]*
v2, v1[1]*
v2);
482 template <
class T,
class U>
489 (v1[0]*
v2, v1[1]*
v2, v1[2]*
v2);
493 template <
class T,
class U>
500 (v1[0]*
v2, v1[1]*
v2, v1[2]*
v2, v1[3]*
v2);
507 template <
class T,
class U>
511 return (v1[0] ==
v2[0] &&
516 template <
class T,
class U>
520 return (v1[0] ==
v2[0] &&
526 template <
class T,
class U>
530 return (v1[0] ==
v2[0] &&
540 template <
class T,
class U>
546 }
else if (v1[0] >
v2[0]) {
558 template <
class T,
class U>
564 }
else if (v1[0] >
v2[0]) {
570 }
else if (v1[1] >
v2[1]) {
582 template <
class T,
class U>
588 }
else if (v1[0] >
v2[0]) {
594 }
else if (v1[1] >
v2[1]) {
600 }
else if (v1[2] >
v2[2]) {
624 template <
class T,
class U>
630 (m1[0]+m2[0], m1[1]+m2[1], m1[2]+m2[2],
631 m1[3]+m2[3], m1[4]+m2[4], m1[5]+m2[5],
632 m1[6]+m2[6], m1[7]+m2[7], m1[8]+m2[8]);
636 template <
class T,
class U>
642 (m1[ 0]+m2[ 0], m1[ 1]+m2[ 1], m1[ 2]+m2[ 2], m1[ 3]+m2[ 3],
643 m1[ 4]+m2[ 4], m1[ 5]+m2[ 5], m1[ 6]+m2[ 6], m1[ 7]+m2[ 7],
644 m1[ 8]+m2[ 8], m1[ 9]+m2[ 9], m1[10]+m2[10], m1[11]+m2[11],
645 m1[12]+m2[12], m1[13]+m2[13], m1[14]+m2[14], m1[15]+m2[15]);
652 #define NCBI_ADD_MATRIX3(type) \
654 inline CMatrix3< NCBI_PROMOTE(type,U) > \
655 operator+ (type s, const CMatrix3<U>& m) \
658 CMatrix3< NCBI_PROMOTE(type,U) > \
659 (m[0]+s, m[1]+s, m[2]+s, \
660 m[3]+s, m[4]+s, m[5]+s, \
661 m[6]+s, m[7]+s, m[8]+s); \
664 inline CMatrix3< NCBI_PROMOTE(T,type) > \
665 operator+ (const CMatrix3<T>& m, type s) \
668 CMatrix3< NCBI_PROMOTE(T,type) > \
669 (m[0]+s, m[1]+s, m[2]+s, \
670 m[3]+s, m[4]+s, m[5]+s, \
671 m[6]+s, m[7]+s, m[8]+s); \
679 #undef NCBI_ADD_MATRIX3
682 #define NCBI_ADD_MATRIX4(type) \
684 inline CMatrix4< NCBI_PROMOTE(type,U) > \
685 operator+ (type s, const CMatrix4<U>& m) \
688 CMatrix4< NCBI_PROMOTE(type,U) > \
689 (m[ 0]+s, m[ 1]+s, m[ 2]+s, m[ 3]+s, \
690 m[ 4]+s, m[ 5]+s, m[ 6]+s, m[ 7]+s, \
691 m[ 8]+s, m[ 9]+s, m[10]+s, m[11]+s, \
692 m[12]+s, m[13]+s, m[14]+s, m[15]+s); \
695 inline CMatrix4< NCBI_PROMOTE(T,type) > \
696 operator+ (const CMatrix4<T>& m, type s) \
699 CMatrix4< NCBI_PROMOTE(T,type) > \
700 (m[ 0]+s, m[ 1]+s, m[ 2]+s, m[ 3]+s, \
701 m[ 4]+s, m[ 5]+s, m[ 6]+s, m[ 7]+s, \
702 m[ 8]+s, m[ 9]+s, m[10]+s, m[11]+s, \
703 m[12]+s, m[13]+s, m[14]+s, m[15]+s); \
710 #undef NCBI_ADD_MATRIX3
716 #define NCBI_SUBTRACT_MATRIX3(type) \
718 inline CMatrix3< NCBI_PROMOTE(type,U) > \
719 operator- (type s, const CMatrix3<U>& m) \
722 CMatrix3< NCBI_PROMOTE(type,U) > \
723 (m[0]-s, m[1]-s, m[2]-s, \
724 m[3]-s, m[4]-s, m[5]-s, \
725 m[6]-s, m[7]-s, m[8]-s); \
728 inline CMatrix3< NCBI_PROMOTE(T,type) > \
729 operator- (const CMatrix3<T>& m, type s) \
732 CMatrix3< NCBI_PROMOTE(T,type) > \
733 (m[0]-s, m[1]-s, m[2]-s, \
734 m[3]-s, m[4]-s, m[5]-s, \
735 m[6]-s, m[7]-s, m[8]-s); \
743 #undef NCBI_SUBTRACT_MATRIX3
746 #define NCBI_SUBTRACT_MATRIX4(type) \
748 inline CMatrix4< NCBI_PROMOTE(type,U) > \
749 operator- (type s, const CMatrix4<U>& m) \
752 CMatrix4< NCBI_PROMOTE(type,U) > \
753 (m[ 0]-s, m[ 1]-s, m[ 2]-s, m[ 3]-s, \
754 m[ 4]-s, m[ 5]-s, m[ 6]-s, m[ 7]-s, \
755 m[ 8]-s, m[ 9]-s, m[10]-s, m[11]-s, \
756 m[12]-s, m[13]-s, m[14]-s, m[15]-s); \
759 inline CMatrix4< NCBI_PROMOTE(T,type) > \
760 operator- (const CMatrix4<T>& m, type s) \
763 CMatrix4< NCBI_PROMOTE(T,type) > \
764 (m[ 0]-s, m[ 1]-s, m[ 2]-s, m[ 3]-s, \
765 m[ 4]-s, m[ 5]-s, m[ 6]-s, m[ 7]-s, \
766 m[ 8]-s, m[ 9]-s, m[10]-s, m[11]-s, \
767 m[12]-s, m[13]-s, m[14]-s, m[15]-s); \
774 #undef NCBI_SUBTRACT_MATRIX3
780 #define NCBI_MULTIPLY_MATRIX3(type) \
782 inline CMatrix3< NCBI_PROMOTE(type,U) > \
783 operator* (type s, const CMatrix3<U>& m) \
786 CMatrix3< NCBI_PROMOTE(type,U) > \
787 (m[0]*s, m[1]*s, m[2]*s, \
788 m[3]*s, m[4]*s, m[5]*s, \
789 m[6]*s, m[7]*s, m[8]*s); \
792 inline CMatrix3< NCBI_PROMOTE(T,type) > \
793 operator* (const CMatrix3<T>& m, type s) \
796 CMatrix3< NCBI_PROMOTE(T,type) > \
797 (m[0]*s, m[1]*s, m[2]*s, \
798 m[3]*s, m[4]*s, m[5]*s, \
799 m[6]*s, m[7]*s, m[8]*s); \
807 #undef NCBI_MULTIPLY_MATRIX3
810 #define NCBI_MULTIPLY_MATRIX4(type) \
812 inline CMatrix4< NCBI_PROMOTE(type,U) > \
813 operator* (type s, const CMatrix4<U>& m) \
816 CMatrix4< NCBI_PROMOTE(type,U) > \
817 (m[ 0]*s, m[ 1]*s, m[ 2]*s, m[ 3]*s, \
818 m[ 4]*s, m[ 5]*s, m[ 6]*s, m[ 7]*s, \
819 m[ 8]*s, m[ 9]*s, m[10]*s, m[11]*s, \
820 m[12]*s, m[13]*s, m[14]*s, m[15]*s); \
823 inline CMatrix4< NCBI_PROMOTE(T,type) > \
824 operator* (const CMatrix4<T>& m, type s) \
827 CMatrix4< NCBI_PROMOTE(T,type) > \
828 (m[ 0]*s, m[ 1]*s, m[ 2]*s, m[ 3]*s, \
829 m[ 4]*s, m[ 5]*s, m[ 6]*s, m[ 7]*s, \
830 m[ 8]*s, m[ 9]*s, m[10]*s, m[11]*s, \
831 m[12]*s, m[13]*s, m[14]*s, m[15]*s); \
838 #undef NCBI_MULTIPLY_MATRIX3
844 template <
class T,
class U>
850 (m1[0]-m2[0], m1[1]-m2[1], m1[2]-m2[2],
851 m1[3]-m2[3], m1[4]-m2[4], m1[5]-m2[5],
852 m1[6]-m2[6], m1[7]-m2[7], m1[8]-m2[8]);
856 template <
class T,
class U>
862 (m1[ 0]-m2[ 0], m1[ 1]-m2[ 1], m1[ 2]-m2[ 2], m1[ 3]-m2[ 3],
863 m1[ 4]-m2[ 4], m1[ 5]-m2[ 5], m1[ 6]-m2[ 6], m1[ 7]-m2[ 7],
864 m1[ 8]-m2[ 8], m1[ 9]-m2[ 9], m1[10]-m2[10], m1[11]-m2[11],
865 m1[12]-m2[12], m1[13]-m2[13], m1[14]-m2[14], m1[15]-m2[15]);
873 template <
class T,
class U>
879 (m[0]*v[0] + m[1]*v[1] + m[2]*v[2],
880 m[3]*v[0] + m[4]*v[1] + m[5]*v[2],
881 m[6]*v[0] + m[7]*v[1] + m[8]*v[2] );
885 template <
class T,
class U>
891 (m[ 0]*v[0] + m[ 1]*v[1] + m[ 2]*v[2] + m[ 3]*v[3],
892 m[ 4]*v[0] + m[ 5]*v[1] + m[ 6]*v[2] + m[ 7]*v[3],
893 m[ 8]*v[0] + m[ 9]*v[1] + m[10]*v[2] + m[11]*v[3],
894 m[12]*v[0] + m[13]*v[1] + m[14]*v[2] + m[15]*v[3] );
901 template <
class T,
class U>
907 (v[0]*m[0] + v[1]*m[3] + v[2]*m[6],
908 v[0]*m[1] + v[1]*m[4] + v[2]*m[7],
909 v[0]*m[2] + v[1]*m[5] + v[2]*m[8] );
913 template <
class T,
class U>
919 (v[0]*m[ 0] + v[1]*m[ 4] + v[2]*m[ 8] + m[12]*v[3],
920 v[0]*m[ 1] + v[1]*m[ 5] + v[2]*m[ 9] + m[13]*v[3],
921 v[0]*m[ 2] + v[1]*m[ 6] + v[2]*m[10] + m[14]*v[3],
922 v[0]*m[ 3] + v[1]*m[ 7] + v[2]*m[11] + m[15]*v[3] );
929 template <
class T,
class U>
935 (m1[0]*m2[0] + m1[1]*m2[3] + m1[2]*m2[6],
936 m1[0]*m2[1] + m1[1]*m2[4] + m1[2]*m2[7],
937 m1[0]*m2[2] + m1[1]*m2[5] + m1[2]*m2[8],
939 m1[3]*m2[0] + m1[4]*m2[3] + m1[5]*m2[6],
940 m1[3]*m2[1] + m1[4]*m2[4] + m1[5]*m2[7],
941 m1[3]*m2[2] + m1[4]*m2[5] + m1[5]*m2[8],
943 m1[6]*m2[0] + m1[7]*m2[3] + m1[8]*m2[6],
944 m1[6]*m2[1] + m1[7]*m2[4] + m1[8]*m2[7],
945 m1[6]*m2[2] + m1[7]*m2[5] + m1[8]*m2[8]);
949 template <
class T,
class U>
955 (m1[ 0]*m2[ 0] + m1[ 1]*m2[ 4] + m1[ 2]*m2[ 8] + m1[ 3]*m2[12],
956 m1[ 0]*m2[ 1] + m1[ 1]*m2[ 5] + m1[ 2]*m2[ 9] + m1[ 3]*m2[13],
957 m1[ 0]*m2[ 2] + m1[ 1]*m2[ 6] + m1[ 2]*m2[10] + m1[ 3]*m2[14],
958 m1[ 0]*m2[ 3] + m1[ 1]*m2[ 7] + m1[ 2]*m2[11] + m1[ 3]*m2[15],
960 m1[ 4]*m2[ 0] + m1[ 5]*m2[ 4] + m1[ 6]*m2[ 8] + m1[ 7]*m2[12],
961 m1[ 4]*m2[ 1] + m1[ 5]*m2[ 5] + m1[ 6]*m2[ 9] + m1[ 7]*m2[13],
962 m1[ 4]*m2[ 2] + m1[ 5]*m2[ 6] + m1[ 6]*m2[10] + m1[ 7]*m2[14],
963 m1[ 4]*m2[ 3] + m1[ 5]*m2[ 7] + m1[ 6]*m2[11] + m1[ 7]*m2[15],
965 m1[ 8]*m2[ 0] + m1[ 9]*m2[ 4] + m1[10]*m2[ 8] + m1[11]*m2[12],
966 m1[ 8]*m2[ 1] + m1[ 9]*m2[ 5] + m1[10]*m2[ 9] + m1[11]*m2[13],
967 m1[ 8]*m2[ 2] + m1[ 9]*m2[ 6] + m1[10]*m2[10] + m1[11]*m2[14],
968 m1[ 8]*m2[ 3] + m1[ 9]*m2[ 7] + m1[10]*m2[11] + m1[11]*m2[15],
970 m1[12]*m2[ 0] + m1[13]*m2[ 4] + m1[14]*m2[ 8] + m1[15]*m2[12],
971 m1[12]*m2[ 1] + m1[13]*m2[ 5] + m1[14]*m2[ 9] + m1[15]*m2[13],
972 m1[12]*m2[ 2] + m1[13]*m2[ 6] + m1[14]*m2[10] + m1[15]*m2[14],
973 m1[12]*m2[ 3] + m1[13]*m2[ 7] + m1[14]*m2[11] + m1[15]*m2[15]);
979 template <
class T,
class U>
986 (m1[0]*s, m1[1]*s, m1[2]*s,
987 m1[3]*s, m1[4]*s, m1[5]*s,
988 m1[6]*s, m1[7]*s, m1[8]*s);
992 template <
class T,
class U>
999 (m1[ 0]*s, m1[ 1]*s, m1[ 2]*s, m1[ 3]*s,
1000 m1[ 4]*s, m1[ 5]*s, m1[ 6]*s, m1[ 7]*s,
1001 m1[ 8]*s, m1[ 9]*s, m1[10]*s, m1[11]*s,
1002 m1[12]*s, m1[13]*s, m1[14]*s, m1[15]*s);
Include a standard set of the NCBI C++ Toolkit most basic headers.
CVect2< T > operator-(const CVect2< T > &v)
bool operator==(const CVect2< T > &v1, const CVect2< U > &v2)
#define NCBI_ADD_MATRIX3(type)
#define NCBI_SUBTRACT_MATRIX3(type)
#define NCBI_ADD_VECT2(type)
#define NCBI_MULTIPLY_VECT2(type)
#define NCBI_MULTIPLY_VECT4(type)
#define NCBI_MULTIPLY_MATRIX3(type)
#define NCBI_ADD_VECT3(type)
bool operator<(const CVect2< T > &v1, const CVect2< U > &v2)
#define NCBI_ADD_VECT4(type)
#define NCBI_MULTIPLY_MATRIX4(type)
CVect2< NCBI_PROMOTE(T, U) > operator+(const CVect2< T > &v1, const CVect2< U > &v2)
#define NCBI_SUBTRACT_VECT4(type)
CVect2< NCBI_PROMOTE(T, U) > operator/(const CVect2< T > &v1, U v2)
#define NCBI_SUBTRACT_VECT3(type)
#define NCBI_SUBTRACT_MATRIX4(type)
#define NCBI_ADD_MATRIX4(type)
#define NCBI_SUBTRACT_VECT2(type)
NCBI_PROMOTE(T, U) operator*(const CVect2< T > &v1
#define NCBI_MULTIPLY_VECT3(type)
CVect2< NCBI_PROMOTE(int,U) > operator*(int v1, const CVect2< U > &v2)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.