39 #define dSqrt(x) (sqrtf(x))                     // square root  
   40 #define dRecip(x) ((1.0f/(x)))                          // reciprocal  
   41 #define dSin(x) (sinf(x))                               // sin 
   42 #define dCos(x) (cosf(x))                               // cos 
   45 #define dSqrt(x) (sqrt(x))                      // square root 
   46 #define dRecip(x) ((1.0/(x)))                           // reciprocal 
   47 #define dSin(x) (sin(x))                                // sin 
   48 #define dCos(x) (cos(x))                                // cos 
   57 #define _R(i,j) R[(i)*4+(j)] 
   62     assert(qa && qb && qc);
 
   63     qa[0] = qb[0]*qc[0] - qb[1]*qc[1] - qb[2]*qc[2] - qb[3]*qc[3];
 
   64     qa[1] = qb[0]*qc[1] + qb[1]*qc[0] + qb[2]*qc[3] - qb[3]*qc[2];
 
   65     qa[2] = qb[0]*qc[2] + qb[2]*qc[0] + qb[3]*qc[1] - qb[1]*qc[3];
 
   66     qa[3] = qb[0]*qc[3] + qb[3]*qc[0] + qb[1]*qc[2] - qb[2]*qc[1];
 
   73     dReal qq1 = 2*q[1]*q[1];
 
   74     dReal qq2 = 2*q[2]*q[2];
 
   75     dReal qq3 = 2*q[3]*q[3];
 
   76     _R(0,0) = 1 - qq2 - qq3;
 
   77     _R(0,1) = 2*(q[1]*q[2] - q[0]*q[3]);
 
   78     _R(0,2) = 2*(q[1]*q[3] + q[0]*q[2]);
 
   80     _R(1,0) = 2*(q[1]*q[2] + q[0]*q[3]);
 
   81     _R(1,1) = 1 - qq1 - qq3;
 
   82     _R(1,2) = 2*(q[2]*q[3] - q[0]*q[1]);
 
   84     _R(2,0) = 2*(q[1]*q[3] - q[0]*q[2]);
 
   85     _R(2,1) = 2*(q[2]*q[3] + q[0]*q[1]);
 
   86     _R(2,2) = 1 - qq1 - qq2;
 
   94     tr = 
_R(0,0) + 
_R(1,1) + 
_R(2,2);
 
   99         q[1] = (
_R(2,1) - 
_R(1,2)) * 
s;
 
  100         q[2] = (
_R(0,2) - 
_R(2,0)) * 
s;
 
  101         q[3] = (
_R(1,0) - 
_R(0,1)) * 
s;
 
  105         if (
_R(1,1) > 
_R(0,0)) {
 
  106             if (
_R(2,2) > 
_R(1,1)) 
goto case_2;
 
  109         if (
_R(2,2) > 
_R(0,0)) 
goto case_2;
 
  116         q[2] = (
_R(0,1) + 
_R(1,0)) * 
s;
 
  117         q[3] = (
_R(2,0) + 
_R(0,2)) * 
s;
 
  118         q[0] = (
_R(2,1) - 
_R(1,2)) * 
s;
 
  125         q[3] = (
_R(1,2) + 
_R(2,1)) * 
s;
 
  126         q[1] = (
_R(0,1) + 
_R(1,0)) * 
s;
 
  127         q[0] = (
_R(0,2) - 
_R(2,0)) * 
s;
 
  134         q[1] = (
_R(2,0) + 
_R(0,2)) * 
s;
 
  135         q[2] = (
_R(1,2) + 
_R(2,1)) * 
s;
 
  136         q[0] = (
_R(1,0) - 
_R(0,1)) * 
s;
 
  146 #define PI ((dReal)3.141592654) 
  149 #define rswap(x, y) *(int*)&(x) ^= *(int*)&(y) ^= *(int*)&(x) ^= *(int*)&(y); 
  151 #define g_fEpsilon 1e-8 
  152 #define distinctRoots   0                       // roots r0 < r1 < r2 
  153 #define singleRoot              1                       // root r0 
  154 #define floatRoot01             2                       // roots r0 = r1 < r2 
  155 #define floatRoot12             4                       // roots r0 < r1 = r2 
  156 #define tripleRoot              6                       // roots r0 = r1 = r2 
  158 template <
class T> 
inline T 
RAD_2_DEG(T radians)  { 
return (radians * (T)57.29577951); }
 
  164 inline float* 
mult4(
float* pfres, 
const float* pf1, 
const float* pf2);
 
  167 inline float* 
multtrans3(
float* pfres, 
const float* pf1, 
const float* pf2);
 
  168 inline float* 
multtrans4(
float* pfres, 
const float* pf1, 
const float* pf2);
 
  169 inline float* 
transnorm3(
float* pfout, 
const float* pfmat, 
const float* pf);
 
  171 inline float* 
transpose3(
const float* pf, 
float* pfres);
 
  172 inline float* 
transpose4(
const float* pf, 
float* pfres);
 
  174 inline float dot2(
const float* pf1, 
const float* pf2);
 
  175 inline float dot3(
const float* pf1, 
const float* pf2);
 
  176 inline float dot4(
const float* pf1, 
const float* pf2);
 
  182 inline float* 
normalize2(
float* pfout, 
const float* pf);
 
  183 inline float* 
normalize3(
float* pfout, 
const float* pf);
 
  184 inline float* 
normalize4(
float* pfout, 
const float* pf);
 
  186 inline float* 
cross3(
float* pfout, 
const float* pf1, 
const float* pf2);
 
  189 inline float* 
mult3_s4(
float* pfres, 
const float* pf1, 
const float* pf2);
 
  190 inline float* 
mult3_s3(
float* pfres, 
const float* pf1, 
const float* pf2);
 
  192 inline float* 
inv3(
const float* pf, 
float* pfres, 
float* pfdet, 
int stride);
 
  193 inline float* 
inv4(
const float* pf, 
float* pfres);
 
  196 inline double* 
mult4(
double* pfres, 
const double* pf1, 
const double* pf2);
 
  199 inline double* 
multtrans3(
double* pfres, 
const double* pf1, 
const double* pf2);
 
  200 inline double* 
multtrans4(
double* pfres, 
const double* pf1, 
const double* pf2);
 
  201 inline double* 
transnorm3(
double* pfout, 
const double* pfmat, 
const double* pf);
 
  203 inline double* 
transpose3(
const double* pf, 
double* pfres);
 
  204 inline double* 
transpose4(
const double* pf, 
double* pfres);
 
  206 inline double dot2(
const double* pf1, 
const double* pf2);
 
  207 inline double dot3(
const double* pf1, 
const double* pf2);
 
  208 inline double dot4(
const double* pf1, 
const double* pf2);
 
  214 inline double* 
normalize2(
double* pfout, 
const double* pf);
 
  215 inline double* 
normalize3(
double* pfout, 
const double* pf);
 
  216 inline double* 
normalize4(
double* pfout, 
const double* pf);
 
  218 inline double* 
cross3(
double* pfout, 
const double* pf1, 
const double* pf2);
 
  221 inline double* 
mult3_s4(
double* pfres, 
const double* pf1, 
const double* pf2);
 
  222 inline double* 
mult3_s3(
double* pfres, 
const double* pf1, 
const double* pf2);
 
  224 inline double* 
inv3(
const double* pf, 
double* pfres, 
double* pfdet, 
int stride);
 
  225 inline double* 
inv4(
const double* pf, 
double* pfres);
 
  254     template<
class U> 
RaveVector(
const U* pf) { assert(pf != NULL); 
x = (T)pf[0]; 
y = (T)pf[1]; 
z = (T)pf[2]; 
w = 0; }
 
  260     operator T* () { 
return &
x; }
 
  261     operator const T* () 
const { 
return (
const T*)&
x; }
 
  289     inline void Set3(
const T* pvals) { 
x = pvals[0]; 
y = pvals[1]; 
z = pvals[2]; }
 
  290     inline void Set3(T val1, T val2, T val3) { 
x = val1; 
y = val2; 
z = val3; }
 
  291     inline void Set4(
const T* pvals) { 
x = pvals[0]; 
y = pvals[1]; 
z = pvals[2]; 
w = pvals[3]; }
 
  292     inline void Set4(T val1, T val2, T val3, T val4) { 
x = val1; 
y = val2; 
z = val3; 
w = val4;}
 
  300         ucrossv[0] = u[1] * v[2] - u[2] * v[1];
 
  301         ucrossv[1] = u[2] * v[0] - u[0] * v[2];
 
  302         ucrossv[2] = u[0] * v[1] - u[1] * v[0];
 
  323     template <
class S, 
class U> 
friend std::basic_ostream<S>& 
operator<<(std::basic_ostream<S>& O, 
const RaveVector<U>& v);
 
  324     template <
class S, 
class U> 
friend std::basic_istream<S>& 
operator>>(std::basic_istream<S>& I, 
RaveVector<U>& v);
 
  329         ucrossv[0] = 
y * v[2] - 
z * v[1];
 
  330         ucrossv[1] = 
z * v[0] - 
x * v[2];
 
  331         ucrossv[2] = 
x * v[1] - 
y * v[0];
 
  382         rot.y = axis.
x*sinang;
 
  383         rot.z = axis.
y*sinang;
 
  384         rot.w = axis.
z*sinang;
 
  404         v.
x = (1-yy-zz) * r.
x + (xy-zw) * r.
y + (xz+yw)*r.
z;
 
  405         v.
y = (xy+zw) * r.
x + (1-xx-zz) * r.
y + (yz-xw)*r.
z;
 
  406         v.
z = (xz-yw) * r.
x + (yz+xw) * r.
y + (1-xx-yy)*r.
z;
 
  454         m[0] = t.
m[0]; 
m[1] = t.
m[1]; 
m[2] = t.
m[2]; 
m[3] = t.
m[3];
 
  455         m[4] = t.
m[4]; 
m[5] = t.
m[5]; 
m[6] = t.
m[6]; 
m[7] = t.
m[7];
 
  456         m[8] = t.
m[8]; 
m[9] = t.
m[9]; 
m[10] = t.
m[10]; 
m[11] = t.
m[11];
 
  462         m[0] = 1; 
m[1] = 0; 
m[2] = 0;
 
  463         m[4] = 0; 
m[5] = 1; 
m[6] = 0;
 
  464         m[8] = 0; 
m[9] = 0; 
m[10] = 1;
 
  473         quat.
y = axis.
x*sinang;
 
  474         quat.
z = axis.
y*sinang;
 
  475         quat.
w = axis.
z*sinang;
 
  482         T qq1 = 2*quat[1]*quat[1];
 
  483         T qq2 = 2*quat[2]*quat[2];
 
  484         T qq3 = 2*quat[3]*quat[3];
 
  485         m[4*0+0] = 1 - qq2 - qq3;
 
  486         m[4*0+1] = 2*(quat[1]*quat[2] - quat[0]*quat[3]);
 
  487         m[4*0+2] = 2*(quat[1]*quat[3] + quat[0]*quat[2]);
 
  489         m[4*1+0] = 2*(quat[1]*quat[2] + quat[0]*quat[3]);
 
  490         m[4*1+1] = 1 - qq1 - qq3;
 
  491         m[4*1+2] = 2*(quat[2]*quat[3] - quat[0]*quat[1]);
 
  493         m[4*2+0] = 2*(quat[1]*quat[3] - quat[0]*quat[2]);
 
  494         m[4*2+1] = 2*(quat[2]*quat[3] + quat[0]*quat[1]);
 
  495         m[4*2+2] = 1 - qq1 - qq2;
 
  499     inline void rotfrommat(T m_00, T m_01, T m_02, T m_10, T m_11, T m_12, T m_20, T m_21, T m_22) {
 
  500         m[0] = m_00; 
m[1] = m_01; 
m[2] = m_02; 
m[3] = 0;
 
  501         m[4] = m_10; 
m[5] = m_11; 
m[6] = m_12; 
m[7] = 0;
 
  502         m[8] = m_20; 
m[9] = m_21; 
m[10] = m_22; 
m[11] = 0;
 
  505     inline T 
rot(
int i, 
int j)
 const {
 
  506         assert( i >= 0 && i < 3 && j >= 0 && j < 3);
 
  509     inline T& 
rot(
int i, 
int j) {
 
  510         assert( i >= 0 && i < 3 && j >= 0 && j < 3);
 
  517         v[0] = r[0] * 
m[0] + r[1] * 
m[1] + r[2] * 
m[2] + 
trans.x;
 
  518         v[1] = r[0] * 
m[4] + r[1] * 
m[5] + r[2] * 
m[6] + 
trans.y;
 
  519         v[2] = r[0] * 
m[8] + r[1] * 
m[9] + r[2] * 
m[10] + 
trans.z;
 
  541         v.
x = r.
x * 
m[0] + r.
y * 
m[1] + r.
z * 
m[2];
 
  542         v.
y = r.
x * 
m[4] + r.
y * 
m[5] + r.
z * 
m[6];
 
  543         v.
z = r.
x * 
m[8] + r.
y * 
m[9] + r.
z * 
m[10];
 
  556         right.
x = 
m[0]; up.
x = 
m[1]; dir.
x = 
m[2];
 
  557         right.
y = 
m[4]; up.
y = 
m[5]; dir.
y = 
m[6];
 
  558         right.
z = 
m[8]; up.
z = 
m[9]; dir.
z = 
m[10];
 
  576     tr = t.
m[4*0+0] + t.
m[4*1+1] + t.
m[4*2+2];
 
  579         rot[0] = (
dReal)(0.5) * 
s;
 
  581         rot[1] = (t.
m[4*2+1] - t.
m[4*1+2]) * 
s;
 
  582         rot[2] = (t.
m[4*0+2] - t.
m[4*2+0]) * 
s;
 
  583         rot[3] = (t.
m[4*1+0] - t.
m[4*0+1]) * 
s;
 
  587         if (t.
m[4*1+1] > t.
m[4*0+0]) {
 
  588             if (t.
m[4*2+2] > t.
m[4*1+1]) 
goto case_2;
 
  591         if (t.
m[4*2+2] > t.
m[4*0+0]) 
goto case_2;
 
  595         s = 
RaveSqrt((t.
m[4*0+0] - (t.
m[4*1+1] + t.
m[4*2+2])) + 1);
 
  596         rot[1] = (
dReal)(0.5) * 
s;
 
  598         rot[2] = (t.
m[4*0+1] + t.
m[4*1+0]) * 
s;
 
  599         rot[3] = (t.
m[4*2+0] + t.
m[4*0+2]) * 
s;
 
  600         rot[0] = (t.
m[4*2+1] - t.
m[4*1+2]) * 
s;
 
  604         s = 
RaveSqrt((t.
m[4*1+1] - (t.
m[4*2+2] + t.
m[4*0+0])) + 1);
 
  605         rot[2] = (
dReal)(0.5) * 
s;
 
  607         rot[3] = (t.
m[4*1+2] + t.
m[4*2+1]) * 
s;
 
  608         rot[1] = (t.
m[4*0+1] + t.
m[4*1+0]) * 
s;
 
  609         rot[0] = (t.
m[4*0+2] - t.
m[4*2+0]) * 
s;
 
  613         s = 
RaveSqrt((t.
m[4*2+2] - (t.
m[4*0+0] + t.
m[4*1+1])) + 1);
 
  614         rot[3] = (
dReal)(0.5) * 
s;
 
  616         rot[1] = (t.
m[4*2+0] + t.
m[4*0+2]) * 
s;
 
  617         rot[2] = (t.
m[4*1+2] + t.
m[4*2+1]) * 
s;
 
  618         rot[0] = (t.
m[4*1+0] - t.
m[4*0+1]) * 
s;
 
  692 int CubicRoots (
double c0, 
double c1, 
double c2, 
double *r0, 
double *r1, 
double *r2);
 
  693 template <
class T, 
class S> 
void Tridiagonal3 (S* mat, T* diag, T* subd);
 
  694 bool QLAlgorithm3 (
float* m_aafEntry, 
float* afDiag, 
float* afSubDiag);
 
  695 bool QLAlgorithm3 (
double* m_aafEntry, 
double* afDiag, 
double* afSubDiag);
 
  715 template <
class T> 
int Min(T* pts, 
int stride, 
int numPts); 
 
  716 template <
class T> 
int Max(T* pts, 
int stride, 
int numPts); 
 
  719 template <
class T> 
inline void mult(T* pf, T fa, 
int r);
 
  723 template <
class T, 
class R, 
class S>
 
  724 inline S* 
mult(T* pf1, R* pf2, 
int r1, 
int c1, 
int c2, S* pfres, 
bool badd = 
false);
 
  729 template <
class T, 
class R, 
class S>
 
  730 inline S* 
multtrans(T* pf1, R* pf2, 
int r1, 
int c1, 
int c2, S* pfres, 
bool badd = 
false);
 
  736 template <
class T, 
class R, 
class S>
 
  737 inline S* 
multtrans_to2(T* pf1, R* pf2, 
int r1, 
int c1, 
int r2, S* pfres, 
bool badd = 
false);
 
  743 template <
class T> 
inline T* 
multto1(T* pf1, T* pf2, 
int r1, 
int c1, T* pftemp = NULL);
 
  747 template <
class T, 
class S> 
inline T* 
multto2(T* pf1, S* pf2, 
int r2, 
int c2, S* pftemp = NULL);
 
  750 template <
class T> 
inline void sub(T* pf1, T* pf2, 
int r);
 
  751 template <
class T> 
inline T 
normsqr(
const T* pf1, 
int r);
 
  752 template <
class T> 
inline T 
lengthsqr(
const T* pf1, 
const T* pf2, 
int length);
 
  753 template <
class T> 
inline T 
dot(T* pf1, T* pf2, 
int length);
 
  755 template <
class T> 
inline T 
sum(T* pf, 
int length);
 
  758 template <
class T> 
inline bool inv2(T* pf, T* pfres);
 
  767         b = -(pfmat[0] + pfmat[3]);
 
  768         c = pfmat[0] * pfmat[3] - pfmat[1] * pfmat[2];
 
  769         d = b * b - 4.0f * c + 1e-16
f;
 
  771         if( 
d < 0 ) 
return false;
 
  774                 peigs[0] = a;   peigs[1] = a;
 
  775                 fv1x = pfmat[1];                fv1y = a - pfmat[0];
 
  776                 c = 1 / 
RaveSqrt(fv1x*fv1x + fv1y*fv1y);
 
  777                 fv1x *= c;              fv1y *= c;
 
  778                 fv2x = -fv1y;           fv2y = fv1x;
 
  786         fv1x = pfmat[1];                fv1y = a-pfmat[0];
 
  787         c = 1 / 
RaveSqrt(fv1x*fv1x + fv1y*fv1y);
 
  788         fv1x *= c;              fv1y *= c;
 
  792         fv2x = pfmat[1];                fv2y = a-pfmat[0];
 
  793         c = 1 / 
RaveSqrt(fv2x*fv2x + fv2y*fv2y);
 
  794         fv2x *= c;              fv2y *= c;
 
  802     T 
d = b * b - (T)4 * c * a + (T)1e-16;
 
  804         if( 
d < 0 ) 
return 0;
 
  807                 r1 = r2 = (T)-0.5 * b / a;
 
  813         r1 = (T)-0.5 * (b + 
d) / a;
 
  820 #define MULT3(stride) { \ 
  821         pfres2[0*stride+0] = pf1[0*stride+0]*pf2[0*stride+0]+pf1[0*stride+1]*pf2[1*stride+0]+pf1[0*stride+2]*pf2[2*stride+0]; \ 
  822         pfres2[0*stride+1] = pf1[0*stride+0]*pf2[0*stride+1]+pf1[0*stride+1]*pf2[1*stride+1]+pf1[0*stride+2]*pf2[2*stride+1]; \ 
  823         pfres2[0*stride+2] = pf1[0*stride+0]*pf2[0*stride+2]+pf1[0*stride+1]*pf2[1*stride+2]+pf1[0*stride+2]*pf2[2*stride+2]; \ 
  824         pfres2[1*stride+0] = pf1[1*stride+0]*pf2[0*stride+0]+pf1[1*stride+1]*pf2[1*stride+0]+pf1[1*stride+2]*pf2[2*stride+0]; \ 
  825         pfres2[1*stride+1] = pf1[1*stride+0]*pf2[0*stride+1]+pf1[1*stride+1]*pf2[1*stride+1]+pf1[1*stride+2]*pf2[2*stride+1]; \ 
  826         pfres2[1*stride+2] = pf1[1*stride+0]*pf2[0*stride+2]+pf1[1*stride+1]*pf2[1*stride+2]+pf1[1*stride+2]*pf2[2*stride+2]; \ 
  827         pfres2[2*stride+0] = pf1[2*stride+0]*pf2[0*stride+0]+pf1[2*stride+1]*pf2[1*stride+0]+pf1[2*stride+2]*pf2[2*stride+0]; \ 
  828         pfres2[2*stride+1] = pf1[2*stride+0]*pf2[0*stride+1]+pf1[2*stride+1]*pf2[1*stride+1]+pf1[2*stride+2]*pf2[2*stride+1]; \ 
  829         pfres2[2*stride+2] = pf1[2*stride+0]*pf2[0*stride+2]+pf1[2*stride+1]*pf2[1*stride+2]+pf1[2*stride+2]*pf2[2*stride+2]; \ 
  834 inline T* 
_mult3_s4(T* pfres, 
const T* pf1, 
const T* pf2)
 
  836         assert( pf1 != NULL && pf2 != NULL && pfres != NULL );
 
  839         if( pfres == pf1 || pfres == pf2 ) pfres2 = (T*)alloca(12 * 
sizeof(T));
 
  844         if( pfres2 != pfres ) memcpy(pfres, pfres2, 12*
sizeof(T));
 
  851 inline T* 
_mult3_s3(T* pfres, 
const T* pf1, 
const T* pf2)
 
  853         assert( pf1 != NULL && pf2 != NULL && pfres != NULL );
 
  856         if( pfres == pf1 || pfres == pf2 ) pfres2 = (T*)alloca(9 * 
sizeof(T));
 
  861         if( pfres2 != pfres ) memcpy(pfres, pfres2, 9*
sizeof(T));
 
  868 inline T* 
_mult4(T* pfres, 
const T* p1, 
const T* p2)
 
  870         assert( pfres != NULL && p1 != NULL && p2 != NULL );
 
  873         if( pfres == p1 || pfres == p2 ) pfres2 = (T*)alloca(16 * 
sizeof(T));
 
  876         pfres2[0*4+0] = p1[0*4+0]*p2[0*4+0] + p1[0*4+1]*p2[1*4+0] + p1[0*4+2]*p2[2*4+0] + p1[0*4+3]*p2[3*4+0];
 
  877         pfres2[0*4+1] = p1[0*4+0]*p2[0*4+1] + p1[0*4+1]*p2[1*4+1] + p1[0*4+2]*p2[2*4+1] + p1[0*4+3]*p2[3*4+1];
 
  878         pfres2[0*4+2] = p1[0*4+0]*p2[0*4+2] + p1[0*4+1]*p2[1*4+2] + p1[0*4+2]*p2[2*4+2] + p1[0*4+3]*p2[3*4+2];
 
  879         pfres2[0*4+3] = p1[0*4+0]*p2[0*4+3] + p1[0*4+1]*p2[1*4+3] + p1[0*4+2]*p2[2*4+3] + p1[0*4+3]*p2[3*4+3];
 
  881         pfres2[1*4+0] = p1[1*4+0]*p2[0*4+0] + p1[1*4+1]*p2[1*4+0] + p1[1*4+2]*p2[2*4+0] + p1[1*4+3]*p2[3*4+0];
 
  882         pfres2[1*4+1] = p1[1*4+0]*p2[0*4+1] + p1[1*4+1]*p2[1*4+1] + p1[1*4+2]*p2[2*4+1] + p1[1*4+3]*p2[3*4+1];
 
  883         pfres2[1*4+2] = p1[1*4+0]*p2[0*4+2] + p1[1*4+1]*p2[1*4+2] + p1[1*4+2]*p2[2*4+2] + p1[1*4+3]*p2[3*4+2];
 
  884         pfres2[1*4+3] = p1[1*4+0]*p2[0*4+3] + p1[1*4+1]*p2[1*4+3] + p1[1*4+2]*p2[2*4+3] + p1[1*4+3]*p2[3*4+3];
 
  886         pfres2[2*4+0] = p1[2*4+0]*p2[0*4+0] + p1[2*4+1]*p2[1*4+0] + p1[2*4+2]*p2[2*4+0] + p1[2*4+3]*p2[3*4+0];
 
  887         pfres2[2*4+1] = p1[2*4+0]*p2[0*4+1] + p1[2*4+1]*p2[1*4+1] + p1[2*4+2]*p2[2*4+1] + p1[2*4+3]*p2[3*4+1];
 
  888         pfres2[2*4+2] = p1[2*4+0]*p2[0*4+2] + p1[2*4+1]*p2[1*4+2] + p1[2*4+2]*p2[2*4+2] + p1[2*4+3]*p2[3*4+2];
 
  889         pfres2[2*4+3] = p1[2*4+0]*p2[0*4+3] + p1[2*4+1]*p2[1*4+3] + p1[2*4+2]*p2[2*4+3] + p1[2*4+3]*p2[3*4+3];
 
  891         pfres2[3*4+0] = p1[3*4+0]*p2[0*4+0] + p1[3*4+1]*p2[1*4+0] + p1[3*4+2]*p2[2*4+0] + p1[3*4+3]*p2[3*4+0];
 
  892         pfres2[3*4+1] = p1[3*4+0]*p2[0*4+1] + p1[3*4+1]*p2[1*4+1] + p1[3*4+2]*p2[2*4+1] + p1[3*4+3]*p2[3*4+1];
 
  893         pfres2[3*4+2] = p1[3*4+0]*p2[0*4+2] + p1[3*4+1]*p2[1*4+2] + p1[3*4+2]*p2[2*4+2] + p1[3*4+3]*p2[3*4+2];
 
  894         pfres2[3*4+3] = p1[3*4+0]*p2[0*4+3] + p1[3*4+1]*p2[1*4+3] + p1[3*4+2]*p2[2*4+3] + p1[3*4+3]*p2[3*4+3];
 
  896         if( pfres != pfres2 ) memcpy(pfres, pfres2, 
sizeof(T)*16);
 
  904         if( pfres == pf1 ) pfres2 = (T*)alloca(9 * 
sizeof(T));
 
  907         pfres2[0] = pf1[0]*pf2[0]+pf1[3]*pf2[3]+pf1[6]*pf2[6];
 
  908         pfres2[1] = pf1[0]*pf2[1]+pf1[3]*pf2[4]+pf1[6]*pf2[7];
 
  909         pfres2[2] = pf1[0]*pf2[2]+pf1[3]*pf2[5]+pf1[6]*pf2[8];
 
  911         pfres2[3] = pf1[1]*pf2[0]+pf1[4]*pf2[3]+pf1[7]*pf2[6];
 
  912         pfres2[4] = pf1[1]*pf2[1]+pf1[4]*pf2[4]+pf1[7]*pf2[7];
 
  913         pfres2[5] = pf1[1]*pf2[2]+pf1[4]*pf2[5]+pf1[7]*pf2[8];
 
  915         pfres2[6] = pf1[2]*pf2[0]+pf1[5]*pf2[3]+pf1[8]*pf2[6];
 
  916         pfres2[7] = pf1[2]*pf2[1]+pf1[5]*pf2[4]+pf1[8]*pf2[7];
 
  917         pfres2[8] = pf1[2]*pf2[2]+pf1[5]*pf2[5]+pf1[8]*pf2[8];
 
  919         if( pfres2 != pfres ) memcpy(pfres, pfres2, 9*
sizeof(T));
 
  928         if( pfres == pf1 ) pfres2 = (T*)alloca(16 * 
sizeof(T));
 
  931         for(
int i = 0; i < 4; ++i) {
 
  932                 for(
int j = 0; j < 4; ++j) {
 
  933                         pfres[4*i+j] = pf1[i] * pf2[j] + pf1[i+4] * pf2[j+4] + pf1[i+8] * pf2[j+8] + pf1[i+12] * pf2[j+12];
 
  946         q.
x = -1 + 2*(rand()/((
dReal)RAND_MAX));
 
  947         q.
y = -1 + 2*(rand()/((
dReal)RAND_MAX));
 
  948         q.
z = -1 + 2*(rand()/((
dReal)RAND_MAX));
 
  949         q.
w = -1 + 2*(rand()/((
dReal)RAND_MAX));
 
  976         T cosHalfTheta = qa.
w * qb.
w + qa.
x * qb.
x + qa.
y * qb.
y + qa.
z * qb.
z;
 
  979                 qm.
w = qa.
w;qm.
x = qa.
x;qm.
y = qa.
y;qm.
z = qa.
z;
 
  983         T halfTheta = 
RaveAcos(cosHalfTheta);
 
  984         T sinHalfTheta = 
RaveSqrt(1 - cosHalfTheta*cosHalfTheta);
 
  988                 qm.
w = (qa.
w * 0.5f + qb.
w * 0.5f);
 
  989                 qm.
x = (qa.
x * 0.5f + qb.
x * 0.5f);
 
  990                 qm.
y = (qa.
y * 0.5f + qb.
y * 0.5f);
 
  991                 qm.
z = (qa.
z * 0.5f + qb.
z * 0.5f);
 
  995         T ratioA = 
RaveSin((1 - t) * halfTheta) / sinHalfTheta;
 
  996         T ratioB = 
RaveSin(t * halfTheta) / sinHalfTheta; 
 
  998         qm.
w = (qa.
w * ratioA + qb.
w * ratioB);
 
  999         qm.
x = (qa.
x * ratioA + qb.
x * ratioB);
 
 1000         qm.
y = (qa.
y * ratioA + qb.
y * ratioB);
 
 1001         qm.
z = (qa.
z * ratioA + qb.
z * ratioB);
 
 1008     return pf[0*stride+2] * (pf[1*stride + 0] * pf[2*stride + 1] - pf[1*stride + 1] * pf[2*stride + 0]) +
 
 1009         pf[1*stride+2] * (pf[0*stride + 1] * pf[2*stride + 0] - pf[0*stride + 0] * pf[2*stride + 1]) +
 
 1010         pf[2*stride+2] * (pf[0*stride + 0] * pf[1*stride + 1] - pf[0*stride + 1] * pf[1*stride + 0]);
 
 1016 inline T* 
_inv3(
const T* pf, T* pfres, T* pfdet, 
int stride)
 
 1019         if( pfres == pf ) pfres2 = (T*)alloca(3 * stride * 
sizeof(T));
 
 1020         else pfres2 = pfres;
 
 1025         pfres2[0*stride + 0] = pf[1*stride + 1] * pf[2*stride + 2] - pf[1*stride + 2] * pf[2*stride + 1];
 
 1026         pfres2[0*stride + 1] = pf[0*stride + 2] * pf[2*stride + 1] - pf[0*stride + 1] * pf[2*stride + 2];
 
 1027         pfres2[0*stride + 2] = pf[0*stride + 1] * pf[1*stride + 2] - pf[0*stride + 2] * pf[1*stride + 1];
 
 1028         pfres2[1*stride + 0] = pf[1*stride + 2] * pf[2*stride + 0] - pf[1*stride + 0] * pf[2*stride + 2];
 
 1029         pfres2[1*stride + 1] = pf[0*stride + 0] * pf[2*stride + 2] - pf[0*stride + 2] * pf[2*stride + 0];
 
 1030         pfres2[1*stride + 2] = pf[0*stride + 2] * pf[1*stride + 0] - pf[0*stride + 0] * pf[1*stride + 2];
 
 1031         pfres2[2*stride + 0] = pf[1*stride + 0] * pf[2*stride + 1] - pf[1*stride + 1] * pf[2*stride + 0];
 
 1032         pfres2[2*stride + 1] = pf[0*stride + 1] * pf[2*stride + 0] - pf[0*stride + 0] * pf[2*stride + 1];
 
 1033         pfres2[2*stride + 2] = pf[0*stride + 0] * pf[1*stride + 1] - pf[0*stride + 1] * pf[1*stride + 0];
 
 1035         T fdet = pf[0*stride + 2] * pfres2[2*stride + 0] + pf[1*stride + 2] * pfres2[2*stride + 1] +
 
 1036                 pf[2*stride + 2] * pfres2[2*stride + 2];
 
 1041     if( fabs(fdet) < 1e-12 ) {
 
 1049                 pfres[0*stride+0] *= fdet;              pfres[0*stride+1] *= fdet;              pfres[0*stride+2] *= fdet;
 
 1050                 pfres[1*stride+0] *= fdet;              pfres[1*stride+1] *= fdet;              pfres[1*stride+2] *= fdet;
 
 1051                 pfres[2*stride+0] *= fdet;              pfres[2*stride+1] *= fdet;              pfres[2*stride+2] *= fdet;
 
 1055         pfres[0*stride+0] = pfres2[0*stride+0] * fdet;
 
 1056         pfres[0*stride+1] = pfres2[0*stride+1] * fdet;
 
 1057         pfres[0*stride+2] = pfres2[0*stride+2] * fdet;
 
 1058         pfres[1*stride+0] = pfres2[1*stride+0] * fdet;
 
 1059         pfres[1*stride+1] = pfres2[1*stride+1] * fdet;
 
 1060         pfres[1*stride+2] = pfres2[1*stride+2] * fdet;
 
 1061         pfres[2*stride+0] = pfres2[2*stride+0] * fdet;
 
 1062         pfres[2*stride+1] = pfres2[2*stride+1] * fdet;
 
 1063         pfres[2*stride+2] = pfres2[2*stride+2] * fdet;
 
 1072         if( pfres == pf ) pfres2 = (T*)alloca(16 * 
sizeof(T));
 
 1073         else pfres2 = pfres;
 
 1082         fd0 = pf[2*4 + 0] * pf[3*4 + 1] - pf[2*4 + 1] * pf[3*4 + 0];
 
 1083         fd1 = pf[2*4 + 1] * pf[3*4 + 2] - pf[2*4 + 2] * pf[3*4 + 1];
 
 1084         fd2 = pf[2*4 + 2] * pf[3*4 + 3] - pf[2*4 + 3] * pf[3*4 + 2];
 
 1086         f1 = pf[2*4 + 1] * pf[3*4 + 3] - pf[2*4 + 3] * pf[3*4 + 1];
 
 1087         f2 = pf[2*4 + 0] * pf[3*4 + 3] - pf[2*4 + 3] * pf[3*4 + 0];
 
 1088         f3 = pf[2*4 + 0] * pf[3*4 + 2] - pf[2*4 + 2] * pf[3*4 + 0];
 
 1090         pfres2[0*4 + 0] =   pf[1*4 + 1] * fd2 - pf[1*4 + 2] * f1 + pf[1*4 + 3] * fd1;
 
 1091         pfres2[0*4 + 1] = -(pf[0*4 + 1] * fd2 - pf[0*4 + 2] * f1 + pf[0*4 + 3] * fd1);
 
 1093         pfres2[1*4 + 0] = -(pf[1*4 + 0] * fd2 - pf[1*4 + 2] * f2 + pf[1*4 + 3] * f3);
 
 1094         pfres2[1*4 + 1] =   pf[0*4 + 0] * fd2 - pf[0*4 + 2] * f2 + pf[0*4 + 3] * f3;
 
 1096         pfres2[2*4 + 0] =   pf[1*4 + 0] * f1 -  pf[1*4 + 1] * f2 + pf[1*4 + 3] * fd0;
 
 1097         pfres2[2*4 + 1] = -(pf[0*4 + 0] * f1 -  pf[0*4 + 1] * f2 + pf[0*4 + 3] * fd0);
 
 1099         pfres2[3*4 + 0] = -(pf[1*4 + 0] * fd1 - pf[1*4 + 1] * f3 + pf[1*4 + 2] * fd0);
 
 1100         pfres2[3*4 + 1] =   pf[0*4 + 0] * fd1 - pf[0*4 + 1] * f3 + pf[0*4 + 2] * fd0;
 
 1103         fd0 = pf[0*4 + 0] * pf[1*4 + 1] - pf[0*4 + 1] * pf[1*4 + 0];
 
 1104         fd1 = pf[0*4 + 1] * pf[1*4 + 2] - pf[0*4 + 2] * pf[1*4 + 1];
 
 1105         fd2 = pf[0*4 + 2] * pf[1*4 + 3] - pf[0*4 + 3] * pf[1*4 + 2];
 
 1107         f1 = pf[0*4 + 1] * pf[1*4 + 3] - pf[0*4 + 3] * pf[1*4 + 1];
 
 1108         f2 = pf[0*4 + 0] * pf[1*4 + 3] - pf[0*4 + 3] * pf[1*4 + 0];
 
 1109         f3 = pf[0*4 + 0] * pf[1*4 + 2] - pf[0*4 + 2] * pf[1*4 + 0];
 
 1111         pfres2[0*4 + 2] =   pf[3*4 + 1] * fd2 - pf[3*4 + 2] * f1 + pf[3*4 + 3] * fd1;
 
 1112         pfres2[0*4 + 3] = -(pf[2*4 + 1] * fd2 - pf[2*4 + 2] * f1 + pf[2*4 + 3] * fd1);
 
 1114         pfres2[1*4 + 2] = -(pf[3*4 + 0] * fd2 - pf[3*4 + 2] * f2 + pf[3*4 + 3] * f3);
 
 1115         pfres2[1*4 + 3] =   pf[2*4 + 0] * fd2 - pf[2*4 + 2] * f2 + pf[2*4 + 3] * f3;
 
 1117         pfres2[2*4 + 2] =   pf[3*4 + 0] * f1 -  pf[3*4 + 1] * f2 + pf[3*4 + 3] * fd0;
 
 1118         pfres2[2*4 + 3] = -(pf[2*4 + 0] * f1 -  pf[2*4 + 1] * f2 + pf[2*4 + 3] * fd0);
 
 1120         pfres2[3*4 + 2] = -(pf[3*4 + 0] * fd1 - pf[3*4 + 1] * f3 + pf[3*4 + 2] * fd0);
 
 1121         pfres2[3*4 + 3] =   pf[2*4 + 0] * fd1 - pf[2*4 + 1] * f3 + pf[2*4 + 2] * fd0;
 
 1123         T fdet = pf[0*4 + 3] * pfres2[3*4 + 0] + pf[1*4 + 3] * pfres2[3*4 + 1] +
 
 1124                         pf[2*4 + 3] * pfres2[3*4 + 2] + pf[3*4 + 3] * pfres2[3*4 + 3];
 
 1126         if( fabs(fdet) < 1e-9) 
return NULL;
 
 1131         if( pfres2 == pfres ) {
 
 1132                 mult(pfres, fdet, 16);
 
 1138                 pfres[i] = pfres2[i] * fdet;
 
 1148         assert( pf != NULL && pfres != NULL );
 
 1151                 rswap(pfres[1], pfres[3]);
 
 1152                 rswap(pfres[2], pfres[6]);
 
 1153                 rswap(pfres[5], pfres[7]);
 
 1157         pfres[0] = pf[0];       pfres[1] = pf[3];       pfres[2] = pf[6];
 
 1158         pfres[3] = pf[1];       pfres[4] = pf[4];       pfres[5] = pf[7];
 
 1159         pfres[6] = pf[2];       pfres[7] = pf[5];       pfres[8] = pf[8];
 
 1167         assert( pf != NULL && pfres != NULL );
 
 1170                 rswap(pfres[1], pfres[4]);
 
 1171                 rswap(pfres[2], pfres[8]);
 
 1172                 rswap(pfres[3], pfres[12]);
 
 1173                 rswap(pfres[6], pfres[9]);
 
 1174                 rswap(pfres[7], pfres[13]);
 
 1175                 rswap(pfres[11], pfres[15]);
 
 1179         pfres[0] = pf[0];       pfres[1] = pf[4];       pfres[2] = pf[8];               pfres[3] = pf[12];
 
 1180         pfres[4] = pf[1];       pfres[5] = pf[5];       pfres[6] = pf[9];               pfres[7] = pf[13];
 
 1181         pfres[8] = pf[2];       pfres[9] = pf[6];       pfres[10] = pf[10];             pfres[11] = pf[14];
 
 1182         pfres[12] = pf[3];      pfres[13] = pf[7];      pfres[14] = pf[11];             pfres[15] = pf[15];
 
 1187 inline T 
_dot2(
const T* pf1, 
const T* pf2)
 
 1189         assert( pf1 != NULL && pf2 != NULL );
 
 1190         return pf1[0]*pf2[0] + pf1[1]*pf2[1];
 
 1194 inline T 
_dot3(
const T* pf1, 
const T* pf2)
 
 1196         assert( pf1 != NULL && pf2 != NULL );
 
 1197         return pf1[0]*pf2[0] + pf1[1]*pf2[1] + pf1[2]*pf2[2];
 
 1201 inline T 
_dot4(
const T* pf1, 
const T* pf2)
 
 1203         assert( pf1 != NULL && pf2 != NULL );
 
 1204         return pf1[0]*pf2[0] + pf1[1]*pf2[1] + pf1[2]*pf2[2] + pf1[3] * pf2[3];
 
 1210         assert( pf != NULL );
 
 1211         return pf[0] * pf[0] + pf[1] * pf[1];
 
 1217         assert( pf != NULL );
 
 1218         return pf[0] * pf[0] + pf[1] * pf[1] + pf[2] * pf[2];
 
 1224         assert( pf != NULL );
 
 1225         return pf[0] * pf[0] + pf[1] * pf[1] + pf[2] * pf[2] + pf[3] * pf[3];
 
 1233         T 
f = pf[0]*pf[0] + pf[1]*pf[1];
 
 1235         pfout[0] = pf[0] * 
f;
 
 1236         pfout[1] = pf[1] * 
f;
 
 1246         T 
f = pf[0]*pf[0] + pf[1]*pf[1] + pf[2]*pf[2];
 
 1249         pfout[0] = pf[0] * 
f;
 
 1250         pfout[1] = pf[1] * 
f;
 
 1251         pfout[2] = pf[2] * 
f;
 
 1261         T 
f = pf[0]*pf[0] + pf[1]*pf[1] + pf[2]*pf[2] + pf[3]*pf[3];
 
 1264         pfout[0] = pf[0] * 
f;
 
 1265         pfout[1] = pf[1] * 
f;
 
 1266         pfout[2] = pf[2] * 
f;
 
 1267         pfout[3] = pf[3] * 
f;
 
 1273 inline T* 
_cross3(T* pfout, 
const T* pf1, 
const T* pf2)
 
 1275         assert( pfout != NULL && pf1 != NULL && pf2 != NULL );
 
 1278         temp[0] = pf1[1] * pf2[2] - pf1[2] * pf2[1];
 
 1279         temp[1] = pf1[2] * pf2[0] - pf1[0] * pf2[2];
 
 1280         temp[2] = pf1[0] * pf2[1] - pf1[1] * pf2[0];
 
 1282         pfout[0] = temp[0]; pfout[1] = temp[1]; pfout[2] = temp[2];
 
 1289         assert( pfout != NULL && pf != NULL && pmat != NULL );
 
 1292         T* pfreal = (pfout == pf) ? dummy : pfout;
 
 1294         pfreal[0] = pf[0] * pmat->
m[0] + pf[1] * pmat->
m[1] + pf[2] * pmat->
m[2] + pmat->
trans.x;
 
 1295     pfreal[1] = pf[0] * pmat->
m[4] + pf[1] * pmat->
m[5] + pf[2] * pmat->
m[6] + pmat->
trans.y;
 
 1296     pfreal[2] = pf[0] * pmat->
m[8] + pf[1] * pmat->
m[9] + pf[2] * pmat->
m[10] + pmat->
trans.z;
 
 1299         pfout[0] = pfreal[0];
 
 1300         pfout[1] = pfreal[1];
 
 1301         pfout[2] = pfreal[2];
 
 1310         assert( pfout != NULL && pf != NULL && pfmat != NULL );
 
 1313         T* pfreal = (pfout == pf) ? dummy : pfout;
 
 1315         pfreal[0] = pf[0] * pfmat[0] + pf[1] * pfmat[1] + pf[2] * pfmat[2];
 
 1316     pfreal[1] = pf[0] * pfmat[3] + pf[1] * pfmat[4] + pf[2] * pfmat[5];
 
 1317     pfreal[2] = pf[0] * pfmat[6] + pf[1] * pfmat[7] + pf[2] * pfmat[8];
 
 1320         pfout[0] = pfreal[0];
 
 1321         pfout[1] = pfreal[1];
 
 1322         pfout[2] = pfreal[2];
 
 1331         assert( pfout != NULL && pf != NULL && pmat != NULL );
 
 1334     T* pfreal = (pfout == pf) ? dummy : pfout;
 
 1336         pfreal[0] = pf[0] * pmat->
m[0] + pf[1] * pmat->
m[1] + pf[2] * pmat->
m[2];
 
 1337     pfreal[1] = pf[0] * pmat->
m[4] + pf[1] * pmat->
m[5] + pf[2] * pmat->
m[6];
 
 1338     pfreal[2] = pf[0] * pmat->
m[8] + pf[1] * pmat->
m[9] + pf[2] * pmat->
m[10];
 
 1340         if( pfreal != pfout ) {
 
 1341         pfout[0] = pfreal[0];
 
 1342         pfout[1] = pfreal[1];
 
 1343         pfout[2] = pfreal[2];
 
 1349 inline float* 
mult4(
float* pfres, 
const float* pf1, 
const float* pf2) { 
return _mult4<float>(pfres, pf1, pf2); }
 
 1351 inline float* 
multtrans3(
float* pfres, 
const float* pf1, 
const float* pf2) { 
return _multtrans3<float>(pfres, pf1, pf2); }
 
 1352 inline float* 
multtrans4(
float* pfres, 
const float* pf1, 
const float* pf2) { 
return _multtrans4<float>(pfres, pf1, pf2); }
 
 1353 inline float* 
transnorm3(
float* pfout, 
const float* pfmat, 
const float* pf) { 
return _transnorm3<float>(pfout, pfmat, pf); }
 
 1355 inline float* 
transpose3(
const float* pf, 
float* pfres) { 
return _transpose3<float>(pf, pfres); }
 
 1356 inline float* 
transpose4(
const float* pf, 
float* pfres) { 
return _transpose4<float>(pf, pfres); }
 
 1358 inline float dot2(
const float* pf1, 
const float* pf2) { 
return _dot2<float>(pf1, pf2); }
 
 1359 inline float dot3(
const float* pf1, 
const float* pf2) { 
return _dot3<float>(pf1, pf2); }
 
 1360 inline float dot4(
const float* pf1, 
const float* pf2) { 
return _dot4<float>(pf1, pf2); }
 
 1362 inline float lengthsqr2(
const float* pf) { 
return _lengthsqr2<float>(pf); }
 
 1363 inline float lengthsqr3(
const float* pf) { 
return _lengthsqr3<float>(pf); }
 
 1364 inline float lengthsqr4(
const float* pf) { 
return _lengthsqr4<float>(pf); }
 
 1366 inline float* 
normalize2(
float* pfout, 
const float* pf) { 
return _normalize2<float>(pfout, pf); }
 
 1367 inline float* 
normalize3(
float* pfout, 
const float* pf) { 
return _normalize3<float>(pfout, pf); }
 
 1368 inline float* 
normalize4(
float* pfout, 
const float* pf) { 
return _normalize4<float>(pfout, pf); }
 
 1370 inline float* 
cross3(
float* pfout, 
const float* pf1, 
const float* pf2) { 
return _cross3<float>(pfout, pf1, pf2); }
 
 1373 inline float* 
mult3_s4(
float* pfres, 
const float* pf1, 
const float* pf2) { 
return _mult3_s4<float>(pfres, pf1, pf2); }
 
 1374 inline float* 
mult3_s3(
float* pfres, 
const float* pf1, 
const float* pf2) { 
return _mult3_s3<float>(pfres, pf1, pf2); }
 
 1376 inline float* 
inv3(
const float* pf, 
float* pfres, 
float* pfdet, 
int stride) { 
return _inv3<float>(pf, pfres, pfdet, stride); }
 
 1377 inline float* 
inv4(
const float* pf, 
float* pfres) { 
return _inv4<float>(pf, pfres); }
 
 1380 inline double* 
mult4(
double* pfres, 
const double* pf1, 
const double* pf2) { 
return _mult4<double>(pfres, pf1, pf2); }
 
 1382 inline double* 
multtrans3(
double* pfres, 
const double* pf1, 
const double* pf2) { 
return _multtrans3<double>(pfres, pf1, pf2); }
 
 1383 inline double* 
multtrans4(
double* pfres, 
const double* pf1, 
const double* pf2) { 
return _multtrans4<double>(pfres, pf1, pf2); }
 
 1384 inline double* 
transnorm3(
double* pfout, 
const double* pfmat, 
const double* pf) { 
return _transnorm3<double>(pfout, pfmat, pf); }
 
 1386 inline double* 
transpose3(
const double* pf, 
double* pfres) { 
return _transpose3<double>(pf, pfres); }
 
 1387 inline double* 
transpose4(
const double* pf, 
double* pfres) { 
return _transpose4<double>(pf, pfres); }
 
 1389 inline double dot2(
const double* pf1, 
const double* pf2) { 
return _dot2<double>(pf1, pf2); }
 
 1390 inline double dot3(
const double* pf1, 
const double* pf2) { 
return _dot3<double>(pf1, pf2); }
 
 1391 inline double dot4(
const double* pf1, 
const double* pf2) { 
return _dot4<double>(pf1, pf2); }
 
 1393 inline double lengthsqr2(
const double* pf) { 
return _lengthsqr2<double>(pf); }
 
 1394 inline double lengthsqr3(
const double* pf) { 
return _lengthsqr3<double>(pf); }
 
 1395 inline double lengthsqr4(
const double* pf) { 
return _lengthsqr4<double>(pf); }
 
 1397 inline double* 
normalize2(
double* pfout, 
const double* pf) { 
return _normalize2<double>(pfout, pf); }
 
 1398 inline double* 
normalize3(
double* pfout, 
const double* pf) { 
return _normalize3<double>(pfout, pf); }
 
 1399 inline double* 
normalize4(
double* pfout, 
const double* pf) { 
return _normalize4<double>(pfout, pf); }
 
 1401 inline double* 
cross3(
double* pfout, 
const double* pf1, 
const double* pf2) { 
return _cross3<double>(pfout, pf1, pf2); }
 
 1404 inline double* 
mult3_s4(
double* pfres, 
const double* pf1, 
const double* pf2) { 
return _mult3_s4<double>(pfres, pf1, pf2); }
 
 1405 inline double* 
mult3_s3(
double* pfres, 
const double* pf1, 
const double* pf2) { 
return _mult3_s3<double>(pfres, pf1, pf2); }
 
 1407 inline double* 
inv3(
const double* pf, 
double* pfres, 
double* pfdet, 
int stride) { 
return _inv3<double>(pf, pfres, pfdet, stride); }
 
 1408 inline double* 
inv4(
const double* pf, 
double* pfres) { 
return _inv4<double>(pf, pfres); }
 
 1420 template <
class T> 
inline void mult(T* pf, T fa, 
int r)
 
 1422         assert( pf != NULL );
 
 1430 template <
class T, 
class R, 
class S>
 
 1431 inline S* 
mult(T* pf1, R* pf2, 
int r1, 
int c1, 
int c2, S* pfres, 
bool badd)
 
 1433         assert( pf1 != NULL && pf2 != NULL && pfres != NULL);
 
 1436         if( !badd ) memset(pfres, 0, 
sizeof(S) * r1 * c2);
 
 1445                                 pfres[j] += (S)(pf1[k] * pf2[k*c2 + j]);
 
 1458 template <
class T, 
class R, 
class S>
 
 1459 inline S* 
multtrans(T* pf1, R* pf2, 
int r1, 
int c1, 
int c2, S* pfres, 
bool badd)
 
 1461         assert( pf1 != NULL && pf2 != NULL && pfres != NULL);
 
 1464         if( !badd ) memset(pfres, 0, 
sizeof(S) * c1 * c2);
 
 1474                                 pfres[j] += (S)(pf1[k*c1] * pf2[k*c2 + j]);
 
 1489 template <
class T, 
class R, 
class S>
 
 1490 inline S* 
multtrans_to2(T* pf1, R* pf2, 
int r1, 
int c1, 
int r2, S* pfres, 
bool badd)
 
 1492         assert( pf1 != NULL && pf2 != NULL && pfres != NULL);
 
 1495         if( !badd ) memset(pfres, 0, 
sizeof(S) * r1 * r2);
 
 1504                                 pfres[j] += (S)(pf1[k] * pf2[j*c1 + k]);
 
 1517 template <
class T> 
inline T* 
multto1(T* pf1, T* pf2, 
int r, 
int c, T* pftemp)
 
 1519         assert( pf1 != NULL && pf2 != NULL );
 
 1524         if( pftemp == NULL ) {
 
 1539                                 pftemp[j] += pf1[k] * pf2[k*c + j];
 
 1545                 memcpy(pf1, pftemp, c * 
sizeof(T));
 
 1549         if( bdel ) 
delete[] pftemp;
 
 1554 template <
class T, 
class S> 
inline T* 
multto2(T* pf1, S* pf2, 
int r2, 
int c2, S* pftemp)
 
 1556         assert( pf1 != NULL && pf2 != NULL );
 
 1561         if( pftemp == NULL ) {
 
 1576                                 pftemp[i] += pf1[i*r2 + k] * pf2[k*c2 + j];
 
 1584                         *(pf2+i*c2+j) = pftemp[i];
 
 1591         if( bdel ) 
delete[] pftemp;
 
 1596 template <
class T> 
inline void add(T* pf1, T* pf2, 
int r)
 
 1598         assert( pf1 != NULL && pf2 != NULL);
 
 1606 template <
class T> 
inline void sub(T* pf1, T* pf2, 
int r)
 
 1608         assert( pf1 != NULL && pf2 != NULL);
 
 1616 template <
class T> 
inline T 
normsqr(
const T* pf1, 
int r)
 
 1618         assert( pf1 != NULL );
 
 1623                 d += pf1[r] * pf1[r];
 
 1629 template <
class T> 
inline T 
lengthsqr(
const T* pf1, 
const T* pf2, 
int length)
 
 1641 template <
class T> 
inline T 
dot(T* pf1, T* pf2, 
int length)
 
 1652 template <
class T> 
inline T 
sum(T* pf, 
int length)
 
 1663 template <
class T> 
inline bool inv2(T* pf, T* pfres)
 
 1665         T fdet = pf[0] * pf[3] - pf[1] * pf[2];
 
 1667         if( fabs(fdet) < 1e-16 ) 
return false;
 
 1673                 pfres[0] = fdet * pf[3];                pfres[1] = -fdet * pf[1];
 
 1674                 pfres[2] = -fdet * pf[2];               pfres[3] = fdet * pf[0];
 
 1679         pfres[0] = pf[3] * fdet;
 
 1682         pfres[3] = ftemp * pf[0];
 
 1687 template <
class T, 
class S>
 
 1690     T a, b, c, 
d, e, 
f, ell, q;
 
 1710         mat[0*3+0] = (S)1; mat[0*3+1] = (S)0; mat[0*3+2] = (T)0;
 
 1711         mat[1*3+0] = (S)0; mat[1*3+1] = b; mat[1*3+2] = c;
 
 1712         mat[2*3+0] = (S)0; mat[2*3+1] = c; mat[2*3+2] = -b;
 
 1719         mat[0*3+0] = (S)1; mat[0*3+1] = (S)0; mat[0*3+2] = (S)0;
 
 1720         mat[1*3+0] = (S)0; mat[1*3+1] = (S)1; mat[1*3+2] = (S)0;
 
 1721         mat[2*3+0] = (S)0; mat[2*3+1] = (S)0; mat[2*3+2] = (S)1;
 
 1726 int Min(T* pts, 
int stride, 
int numPts)
 
 1728     assert( pts != NULL && numPts > 0 && stride > 0 );
 
 1730     int best = pts[0]; pts += stride;
 
 1731     for(
int i = 1; i < numPts; ++i, pts += stride) {
 
 1740 int Max(T* pts, 
int stride, 
int numPts)
 
 1742     assert( pts != NULL && numPts > 0 && stride > 0 );
 
 1744     int best = pts[0]; pts += stride;
 
 1745     for(
int i = 1; i < numPts; ++i, pts += stride) {
 
 1756 template <
class T, 
class U>
 
 1759     return O << v.
x << 
" " << v.
y << 
" " << v.
z << 
" " << v.
w << 
" ";
 
 1762 template <
class T, 
class U>
 
 1765     return I >> v.
x >> v.
y >> v.
z >> v.
w;
 
 1768 template <
class T, 
class U>
 
 1771     return O << v.
rot.x << 
" " << v.
rot.y << 
" " << v.
rot.z << 
" " << v.
rot.w << 
" " 
 1775 template <
class T, 
class U>
 
 1782 template <
class T, 
class U>
 
 1785     return O << v.
m[0] << 
" " << v.
m[4] << 
" " << v.
m[8] << 
" " 
 1786              << v.
m[1] << 
" " << v.
m[5] << 
" " << v.
m[9] << 
" " 
 1787              << v.
m[2] << 
" " << v.
m[6] << 
" " << v.
m[10] << 
" " 
 1792 template <
class T, 
class U>
 
 1795     return I >> v.
m[0] >> v.
m[4] >> v.
m[8]
 
 1796              >> v.
m[1] >> v.
m[5] >> v.
m[9]
 
 1797              >> v.
m[2] >> v.
m[6] >> v.
m[10]