Import Geant4 10.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2017-12-08 12:52:30 +01:00
parent 98e455a940
commit fc6af9e721
2166 changed files with 276760 additions and 100873 deletions
+326 -87
View File
@@ -258,26 +258,25 @@ public:\
bool is_proportional_prec(const TOOLS_MAT_CLASS& a_right,const PREC& a_prec,PREC(*a_fabs)(const T&),T& a_factor) const {\
/* If true, then : a_right = a_factor * this.*/\
if(this==&a_right) {a_factor=T(1);return true;}\
T _zero = zero();\
a_factor = _zero;\
a_factor = zero();\
if(dimension()!=a_right.dimension()) return false;\
T* lp = (T*)m_vec;\
T* rp = (T*)a_right.m_vec;\
bool first = true;\
size_t _data_size = data_size();\
for(size_t i=0;i<_data_size;i++,lp++,rp++) {\
if( numbers_are_equals(*lp,_zero,a_prec,a_fabs) && numbers_are_equals(*rp,_zero,a_prec,a_fabs) ) {\
if( is_zero(*lp,a_prec,a_fabs) && is_zero(*rp,a_prec,a_fabs) ) {\
continue;\
} else if( !numbers_are_equals(*lp,_zero,a_prec,a_fabs) && numbers_are_equals(*rp,_zero,a_prec,a_fabs) ) {\
} else if( !is_zero(*lp,a_prec,a_fabs) && is_zero(*rp,a_prec,a_fabs) ) {\
return false;\
} else if( numbers_are_equals(*lp,_zero,a_prec,a_fabs) && !numbers_are_equals(*rp,_zero,a_prec,a_fabs) ) {\
} else if( is_zero(*lp,a_prec,a_fabs) && !is_zero(*rp,a_prec,a_fabs) ) {\
return false;\
} else {\
if(first) {\
a_factor = (*rp)/(*lp);\
first = false;\
} else {\
if(!numbers_are_equals((*lp)*a_factor,*rp,a_prec,a_fabs)) return false;\
if(!numbers_are_equal((*lp)*a_factor,*rp,a_prec,a_fabs)) return false;\
}\
}\
}\
@@ -286,11 +285,10 @@ public:\
\
template <class PREC>\
bool is_diagonal_prec(const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
T _zero = zero();\
unsigned int _D = dimension();\
for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=0;c<_D;c++) {\
if(c!=r) {if(!numbers_are_equals(value(r,c),_zero,a_prec,a_fabs)) return false;}\
if(c!=r) {if(!is_zero(value(r,c),a_prec,a_fabs)) return false;}\
}\
}\
return true;\
@@ -357,6 +355,21 @@ public:\
}\
return true;\
}\
\
template <class PREC>\
bool is_antisymmetric_prec(const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
unsigned int _D = dimension();\
{for(unsigned int r=0;r<_D;r++) {\
if(a_fabs(value(r,r))>=a_prec) return false;\
}}\
for(unsigned int r=0;r<_D;r++) {\
for(unsigned int c=(r+1);c<_D;c++) {\
T diff = value(r,c)-minus_one()*value(c,r);\
if(a_fabs(diff)>=a_prec) return false;\
}\
}\
return true;\
}\
\
void symmetric_part(TOOLS_MAT_CLASS& a_res) const {\
a_res = *this;\
@@ -373,7 +386,49 @@ public:\
a_res.multiply(one()/two());\
}\
\
T determinant(unsigned int a_tmp_rs[],unsigned int a_tmp_cs[]) const { /*[rord=dim-1]*/ \
template <class PREC>\
bool is_block_UL_DR(const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
/* Look if even dim matrix is of the form : |X 0|\
|0 Y|*/\
unsigned int _D = dimension();\
unsigned int _D_2 = _D/2;\
/*if(2*__D_2!=_D) return false;*/\
for(unsigned int r=0;r<_D_2;r++) {\
for(unsigned int c=_D_2;c<_D;c++) {\
if(a_fabs(value(r,c))>=a_prec) return false;\
}\
}\
for(unsigned int r=_D_2;r<_D;r++) {\
for(unsigned int c=0;c<_D_2;c++) {\
if(a_fabs(value(r,c))>=a_prec) return false;\
}\
}\
return true;\
}\
\
template <class PREC>\
bool is_block_UR_DL(const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
/* Look if even dim matrix is of the form : |0 X|\
|Y 0|*/\
unsigned int _D = dimension();\
unsigned int _D_2 = _D/2;\
/*if(2*__D_2!=_D) return false;*/\
for(unsigned int r=0;r<_D_2;r++) {\
for(unsigned int c=0;c<_D_2;c++) {\
if(a_fabs(value(r,c))>=a_prec) return false;\
}\
}\
for(unsigned int r=_D_2;r<_D;r++) {\
for(unsigned int c=_D_2;c<_D;c++) {\
if(a_fabs(value(r,c))>=a_prec) return false;\
}\
}\
return true;\
}\
\
template <class PREC>\
T determinant_prec(unsigned int a_tmp_rs[],unsigned int a_tmp_cs[], /*[rord=dim-1]*/\
const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
unsigned int ord = dimension();\
if(ord==0) {\
return zero();\
@@ -381,27 +436,27 @@ public:\
return *m_vec;\
} else if(ord==2) {\
T v00 = *m_vec;\
T v01 = *(m_vec+ord);\
T v10 = *(m_vec+1);\
T v11 = *(m_vec+1+ord);\
T v01 = *(m_vec+2);\
T v11 = *(m_vec+3);\
return (v00 * v11 - v10 * v01);\
} else if(ord==3) {\
/* 00 01 02 \
10 11 12 \
20 21 22 \
*/\
T v01 = *(m_vec+ord);\
T v02 = *(m_vec+2*ord);\
T v11 = *(m_vec+1+ord);\
T v12 = *(m_vec+1+2*ord);\
T v21 = *(m_vec+2+ord);\
T v22 = *(m_vec+2+2*ord);\
T cof_00 = v11 * v22 - v21 * v12;\
T cof_10 = v01 * v22 - v21 * v02;\
T cof_20 = v01 * v12 - v11 * v02;\
T v00 = *m_vec;\
T v10 = *(m_vec+1);\
T v20 = *(m_vec+2);\
T v01 = *(m_vec+3);\
T v11 = *(m_vec+4);\
T v21 = *(m_vec+5);\
T v02 = *(m_vec+6);\
T v12 = *(m_vec+7);\
T v22 = *(m_vec+8);\
T cof_00 = v11 * v22 - v21 * v12;\
T cof_10 = v01 * v22 - v21 * v02;\
T cof_20 = v01 * v12 - v11 * v02;\
return (v00*cof_00-v10*cof_10+v20*cof_20);\
}\
\
@@ -418,8 +473,8 @@ public:\
for(unsigned int r=0;r<ord;r++) {\
if(r>=1) a_tmp_rs[r-1] = r-1;\
v_rc = value(r,c);\
if(v_rc!=zero()) {\
T subdet = sub_determinant(rord,a_tmp_rs,a_tmp_cs);\
if(!is_zero(v_rc,a_prec,a_fabs)) {\
T subdet = sub_determinant_prec(rord,a_tmp_rs,a_tmp_cs,a_prec,a_fabs);\
if(sg) \
det += v_rc * subdet;\
else\
@@ -430,6 +485,10 @@ public:\
\
return det;\
}\
\
T determinant(unsigned int a_tmp_rs[],unsigned int a_tmp_cs[]) const { /*[rord=dim-1]*/ \
return determinant_prec<double>(a_tmp_rs,a_tmp_cs,0,zero_fabs);\
}\
\
T determinant() const {\
unsigned int ord = dimension();\
@@ -439,23 +498,27 @@ public:\
return *m_vec;\
} else if(ord==2) {\
T v00 = *m_vec;\
T v01 = *(m_vec+ord);\
T v10 = *(m_vec+1);\
T v11 = *(m_vec+1+ord);\
T v01 = *(m_vec+2);\
T v11 = *(m_vec+3);\
return (v00 * v11 - v10 * v01);\
} else if(ord==3) {\
T v01 = *(m_vec+ord);\
T v02 = *(m_vec+2*ord);\
T v11 = *(m_vec+1+ord);\
T v12 = *(m_vec+1+2*ord);\
T v21 = *(m_vec+2+ord);\
T v22 = *(m_vec+2+2*ord);\
T cof_00 = v11 * v22 - v21 * v12;\
T cof_10 = v01 * v22 - v21 * v02;\
T cof_20 = v01 * v12 - v11 * v02;\
/* 00 01 02 \
10 11 12 \
20 21 22 \
*/\
T v00 = *m_vec;\
T v10 = *(m_vec+1);\
T v20 = *(m_vec+2);\
T v01 = *(m_vec+3);\
T v11 = *(m_vec+4);\
T v21 = *(m_vec+5);\
T v02 = *(m_vec+6);\
T v12 = *(m_vec+7);\
T v22 = *(m_vec+8);\
T cof_00 = v11 * v22 - v21 * v12;\
T cof_10 = v01 * v22 - v21 * v02;\
T cof_20 = v01 * v12 - v11 * v02;\
return (v00*cof_00-v10*cof_10+v20*cof_20);\
}\
unsigned int rord = ord-1;\
@@ -467,73 +530,200 @@ public:\
return det;\
}\
\
bool invert(TOOLS_MAT_CLASS& a_res) const {\
/*Generic invertion method.*/\
template <class PREC>\
bool invert_prec(TOOLS_MAT_CLASS& a_res,\
unsigned int a_tmp_rs[],unsigned int a_tmp_cs[], /*[rord=dim-1]*/\
const PREC& a_prec,PREC(*a_fabs)(const T&) /*for det=?zero*/ \
) const { \
unsigned int ord = dimension();\
if(ord==0) return true;\
\
if(ord==1) {\
T v = value(0,0);\
if(v==zero()) return false;\
a_res.set_value(0,0,one()/v);\
T det = value(0,0);\
if(is_zero(det,a_prec,a_fabs)) return false;\
a_res.set_value(0,0,one()/det);\
return true;\
} else if(ord==2) {\
T v00 = *m_vec;\
T v10 = *(m_vec+1);\
T v01 = *(m_vec+2);\
T v11 = *(m_vec+3);\
T det = (v00 * v11 - v10 * v01);\
if(is_zero(det,a_prec,a_fabs)) return false;\
a_res.set_value(0,0,v11/det);\
a_res.set_value(1,1,v00/det);\
a_res.set_value(0,1,minus_one()*v01/det);\
a_res.set_value(1,0,minus_one()*v10/det);\
return true;\
} else if(ord==3) {\
/* 00 01 02 \
10 11 12 \
20 21 22 \
*/\
T v00 = *m_vec;\
T v10 = *(m_vec+1);\
T v20 = *(m_vec+2);\
T v01 = *(m_vec+3);\
T v11 = *(m_vec+4);\
T v21 = *(m_vec+5);\
T v02 = *(m_vec+6);\
T v12 = *(m_vec+7);\
T v22 = *(m_vec+8);\
T cof_00 = v11 * v22 - v21 * v12;\
T cof_10 = v01 * v22 - v21 * v02;\
T cof_20 = v01 * v12 - v11 * v02;\
T det = (v00*cof_00-v10*cof_10+v20*cof_20);\
if(is_zero(det,a_prec,a_fabs)) return false;\
T cof_01 = v10 * v22 - v20 * v12;\
T cof_11 = v00 * v22 - v20 * v02;\
T cof_21 = v00 * v12 - v10 * v02;\
T cof_02 = v10 * v21 - v20 * v11;\
T cof_12 = v00 * v21 - v20 * v01;\
T cof_22 = v00 * v11 - v10 * v01;\
a_res.set_value(0,0,cof_00/det);\
a_res.set_value(1,0,minus_one()*cof_01/det);\
a_res.set_value(2,0,cof_02/det);\
a_res.set_value(0,1,minus_one()*cof_10/det);\
a_res.set_value(1,1,cof_11/det);\
a_res.set_value(2,1,minus_one()*cof_12/det);\
a_res.set_value(0,2,cof_20/det);\
a_res.set_value(1,2,minus_one()*cof_21/det);\
a_res.set_value(2,2,cof_22/det);\
return true;\
}\
\
/*Generic invertion method.*/\
\
unsigned int rord = ord-1;\
unsigned int* cs = new unsigned int[rord];\
unsigned int* rs = new unsigned int[rord];\
\
/* Get det with r = 0;*/\
T det = zero();\
T subdet;\
{\
{for(unsigned int i=0;i<rord;i++) {rs[i] = i+1;}}\
{for(unsigned int i=0;i<rord;i++) {a_tmp_rs[i] = i+1;}}\
unsigned int r = 0;\
/*if(r>=1) rs[r-1] = r-1;*/\
/*if(r>=1) a_tmp_rs[r-1] = r-1;*/\
\
{for(unsigned int i=0;i<rord;i++) {cs[i] = i+1;}}\
{for(unsigned int i=0;i<rord;i++) {a_tmp_cs[i] = i+1;}}\
bool sg = true; /*r=0+c=0*/\
for(unsigned int c=0;c<ord;c++) {\
if(c>=1) cs[c-1] = c-1;\
T subdet = sub_determinant(rord,rs,cs);\
T sgn = sg ? one() : minus_one();\
det += value(r,c) * subdet * sgn;\
T _value = subdet * sgn;\
a_res.set_value(c,r,_value);\
sg = sg?false:true;\
if(c>=1) a_tmp_cs[c-1] = c-1;\
subdet = sub_determinant_prec(rord,a_tmp_rs,a_tmp_cs,a_prec,a_fabs);\
if(sg) {\
det += value(r,c) * subdet;\
a_res.set_value(c,r,subdet);\
sg = false;\
} else {\
det += value(r,c) * subdet * minus_one();\
a_res.set_value(c,r,subdet * minus_one());\
sg = true;\
}\
}}\
\
if(det==zero()) {\
delete [] cs;\
delete [] rs;\
return false;\
} \
\
if(is_zero(det,a_prec,a_fabs)) return false;\
\
{for(unsigned int c=0;c<ord;c++) {\
a_res.set_value(c,0,a_res.value(c,0)/det);\
}}\
\
{for(unsigned int i=0;i<rord;i++) {rs[i] = i+1;}}\
{for(unsigned int i=0;i<rord;i++) {a_tmp_rs[i] = i+1;}}\
bool sgr = false; /*r=1+c=0*/\
for(unsigned int r=1;r<ord;r++) {\
if(r>=1) rs[r-1] = r-1;\
{for(unsigned int i=0;i<rord;i++) {cs[i] = i+1;}}\
if(r>=1) a_tmp_rs[r-1] = r-1;\
{for(unsigned int i=0;i<rord;i++) {a_tmp_cs[i] = i+1;}}\
bool sg = sgr;\
for(unsigned int c=0;c<ord;c++) {\
if(c>=1) cs[c-1] = c-1;\
T subdet = sub_determinant(rord,rs,cs);\
T sgn = sg ? one() : minus_one();\
T _value = (subdet * sgn)/det;\
a_res.set_value(c,r,_value);\
sg = sg?false:true;\
if(c>=1) a_tmp_cs[c-1] = c-1;\
subdet = sub_determinant_prec(rord,a_tmp_rs,a_tmp_cs,a_prec,a_fabs);\
if(sg) {\
a_res.set_value(c,r,subdet/det);\
sg = false;\
} else {\
a_res.set_value(c,r,(subdet * minus_one())/det);\
sg = true;\
}\
}\
sgr = sgr?false:true;\
}\
\
delete [] cs;\
delete [] rs;\
\
return true;\
}\
\
template <class PREC>\
bool invert_prec(TOOLS_MAT_CLASS& a_res,const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
unsigned int ord = dimension();\
if(ord==0) return true;\
\
if(ord==1) {\
T det = value(0,0);\
if(is_zero(det,a_prec,a_fabs)) return false;\
a_res.set_value(0,0,one()/det);\
return true;\
} else if(ord==2) {\
T v00 = *m_vec;\
T v10 = *(m_vec+1);\
T v01 = *(m_vec+2);\
T v11 = *(m_vec+3);\
T det = (v00 * v11 - v10 * v01);\
if(is_zero(det,a_prec,a_fabs)) return false;\
a_res.set_value(0,0,v11/det);\
a_res.set_value(1,1,v00/det);\
a_res.set_value(0,1,minus_one()*v01/det);\
a_res.set_value(1,0,minus_one()*v10/det);\
return true;\
} else if(ord==3) {\
/* 00 01 02 \
10 11 12 \
20 21 22 \
*/\
T v00 = *m_vec;\
T v10 = *(m_vec+1);\
T v20 = *(m_vec+2);\
T v01 = *(m_vec+3);\
T v11 = *(m_vec+4);\
T v21 = *(m_vec+5);\
T v02 = *(m_vec+6);\
T v12 = *(m_vec+7);\
T v22 = *(m_vec+8);\
T cof_00 = v11 * v22 - v21 * v12;\
T cof_10 = v01 * v22 - v21 * v02;\
T cof_20 = v01 * v12 - v11 * v02;\
T det = (v00*cof_00-v10*cof_10+v20*cof_20);\
if(is_zero(det,a_prec,a_fabs)) return false;\
T cof_01 = v10 * v22 - v20 * v12;\
T cof_11 = v00 * v22 - v20 * v02;\
T cof_21 = v00 * v12 - v10 * v02;\
T cof_02 = v10 * v21 - v20 * v11;\
T cof_12 = v00 * v21 - v20 * v01;\
T cof_22 = v00 * v11 - v10 * v01;\
a_res.set_value(0,0,cof_00/det);\
a_res.set_value(1,0,minus_one()*cof_01/det);\
a_res.set_value(2,0,cof_02/det);\
a_res.set_value(0,1,minus_one()*cof_10/det);\
a_res.set_value(1,1,cof_11/det);\
a_res.set_value(2,1,minus_one()*cof_12/det);\
a_res.set_value(0,2,cof_20/det);\
a_res.set_value(1,2,minus_one()*cof_21/det);\
a_res.set_value(2,2,cof_22/det);\
return true;\
}\
\
unsigned int rord = ord-1;\
unsigned int* cs = new unsigned int[rord];\
unsigned int* rs = new unsigned int[rord];\
bool status = invert_prec(a_res,rs,cs,a_prec,a_fabs);\
delete [] cs;\
delete [] rs;\
return status;\
}\
\
bool invert(TOOLS_MAT_CLASS& a_res,unsigned int a_tmp_rs[],unsigned int a_tmp_cs[]) const { /*[rord=dim-1]*/ \
return invert_prec<double>(a_res,a_tmp_rs,a_tmp_cs,0,zero_fabs);\
}\
\
bool invert(TOOLS_MAT_CLASS& a_res) const {\
return invert_prec<double>(a_res,0,zero_fabs);\
}\
\
void power(unsigned int a_n,TOOLS_MAT_CLASS& a_res) const {\
a_res.set_identity();\
@@ -553,6 +743,36 @@ public:\
a_res += tmp;\
}\
}\
\
void cosh(unsigned int a_le,TOOLS_MAT_CLASS& a_res) const {\
/* result = I + M**2/2! + M**4/4! + .... */\
a_res.set_identity();\
TOOLS_MAT_CLASS M_2(*this);\
M_2._mul_mtx(m_vec);\
TOOLS_MAT_CLASS tmp(*this);\
tmp.set_identity();\
for(unsigned int i=1;i<=a_le;i+=2) {\
tmp *= M_2;\
tmp.multiply(one()/T(i+0)); \
tmp.multiply(one()/T(i+1)); \
a_res += tmp;\
}\
}\
\
void sinh(unsigned int a_le,TOOLS_MAT_CLASS& a_res) const {\
/* result = M + M**3/3! + .... */\
a_res._copy(m_vec);\
TOOLS_MAT_CLASS M_2(*this);\
M_2._mul_mtx(m_vec);\
TOOLS_MAT_CLASS tmp(*this);\
tmp._copy(m_vec);\
for(unsigned int i=1;i<=a_le;i+=2) {\
tmp *= M_2;\
tmp.multiply(one()/T(i+1)); \
tmp.multiply(one()/T(i+2)); \
a_res += tmp;\
}\
}\
\
void log(unsigned int a_le,TOOLS_MAT_CLASS& a_res) const {\
/* result = (M-I) - (M-I)**2/2 + (M-I)**3/3 +... */\
@@ -565,7 +785,7 @@ public:\
M_I._add_mtx(m_vec);\
\
TOOLS_MAT_CLASS M_Ip(M_I);\
T fact = -1;\
T fact = minus_one();\
\
TOOLS_MAT_CLASS tmp;\
\
@@ -633,22 +853,22 @@ public: /*operators*/\
}\
protected:\
void _copy(const T a_m[]) {\
{T* tp = (T*)m_vec;T* ap = (T*)a_m;\
for(unsigned int i=0;i<dim2();i++,tp++,ap++) *tp = *ap;}\
T* tp = (T*)m_vec;T* ap = (T*)a_m;\
for(unsigned int i=0;i<dim2();i++,tp++,ap++) *tp = *ap;\
/*{for(unsigned int i=0;i<dim2();i++) m_vec[i] = a_m[i];}*/\
/* memcpy does not work with std::complex<> and mat<symbol,4> see inlib/tests/symbolic.cpp */\
/*vec_copy(m_vec,a_m,dim2());*/\
}\
\
void _add_mtx(const T a_m[]) { /* this = this + a_m, */\
{T* tp = (T*)m_vec;T* ap = (T*)a_m;\
for(unsigned int i=0;i<dim2();i++,tp++,ap++) *tp += *ap;}\
T* tp = (T*)m_vec;T* ap = (T*)a_m;\
for(unsigned int i=0;i<dim2();i++,tp++,ap++) *tp += *ap;\
/*for(unsigned int i=0;i<dim2();i++) m_vec[i] += a_m[i];*/\
/*vec_add(m_vec,a_m,m_vec,dim2());*/\
}\
void _sub_mtx(const T a_m[]) { /* this = this - a_m, */\
{T* tp = (T*)m_vec;T* ap = (T*)a_m;\
for(unsigned int i=0;i<dim2();i++,tp++,ap++) *tp -= *ap;}\
T* tp = (T*)m_vec;T* ap = (T*)a_m;\
for(unsigned int i=0;i<dim2();i++,tp++,ap++) *tp -= *ap;\
/*for(unsigned int i=0;i<dim2();i++) m_vec[i] -= a_m[i];*/\
/*vec_sub(m_vec,a_m,m_vec,dim2());*/\
}\
@@ -716,7 +936,9 @@ protected:\
delete [] res;\
}\
\
T sub_determinant(unsigned int a_ord,unsigned int aRs[],unsigned int aCs[]) const {\
template <class PREC>\
T sub_determinant_prec(unsigned int a_ord,unsigned int aRs[],unsigned int aCs[],\
const PREC& a_prec,PREC(*a_fabs)(const T&)) const {\
/*WARNING : to optimize, we do not check the content of aRs, aCs.*/\
unsigned int ord = a_ord;\
if(ord==0) return zero();\
@@ -725,17 +947,32 @@ protected:\
/*return (value(aRs[0],aCs[0]) * value(aRs[1],aCs[1]) -\
value(aRs[1],aCs[0]) * value(aRs[0],aCs[1])); \
Optimize the upper :*/\
\
unsigned int r_0 = aRs[0];\
unsigned int r_1 = aRs[1];\
unsigned int c_0 = aCs[0];\
unsigned int c_1 = aCs[1];\
\
unsigned int _ord = dimension();\
const T* p = m_vec;\
\
return ( (*(p+r_0+c_0*_ord)) * (*(p+r_1+c_1*_ord)) -\
(*(p+r_1+c_0*_ord)) * (*(p+r_0+c_1*_ord)) );\
return ( (*(m_vec+aRs[0]+aCs[0]*_ord)) * (*(m_vec+aRs[1]+aCs[1]*_ord)) -\
(*(m_vec+aRs[1]+aCs[0]*_ord)) * (*(m_vec+aRs[0]+aCs[1]*_ord)) );\
\
} else if(ord==3) {\
/* 00 01 02 \
10 11 12 \
20 21 22 \
*/\
unsigned int _ord = dimension();\
\
T v00 = *(m_vec+aRs[0]+aCs[0]*_ord);\
T v10 = *(m_vec+aRs[1]+aCs[0]*_ord);\
T v20 = *(m_vec+aRs[2]+aCs[0]*_ord);\
T v01 = *(m_vec+aRs[0]+aCs[1]*_ord);\
T v11 = *(m_vec+aRs[1]+aCs[1]*_ord);\
T v21 = *(m_vec+aRs[2]+aCs[1]*_ord);\
T v02 = *(m_vec+aRs[0]+aCs[2]*_ord);\
T v12 = *(m_vec+aRs[1]+aCs[2]*_ord);\
T v22 = *(m_vec+aRs[2]+aCs[2]*_ord);\
T cof_00 = v11 * v22 - v21 * v12;\
T cof_10 = v01 * v22 - v21 * v02;\
T cof_20 = v01 * v12 - v11 * v02;\
return (v00*cof_00-v10*cof_10+v20*cof_20);\
}\
\
unsigned int rord = ord-1;\
@@ -754,8 +991,8 @@ protected:\
for(unsigned int r=0;r<ord;r++) {\
if(r>=1) rs[r-1] = aRs[r-1];\
v_rc = value(aRs[r],aCs[c]);\
if(v_rc!=zero()) {\
T subdet = sub_determinant(rord,rs,cs);\
if(!is_zero(v_rc,a_prec,a_fabs)) {\
T subdet = sub_determinant_prec(rord,rs,cs,a_prec,a_fabs);\
if(sg)\
det += v_rc * subdet;\
else\
@@ -768,6 +1005,8 @@ protected:\
delete [] rs;\
\
return det;\
}
}\
\
static double zero_fabs(const T& a_number) {return a_number==zero()?0:1000000;}
#endif
+12 -12
View File
@@ -97,12 +97,12 @@ public:
if(is_empty()) {
set_bounds(a_point,a_point);
} else {
m_min.set_value(tools::mn<T_t>(a_point[0],m_min[0]),
tools::mn<T_t>(a_point[1],m_min[1]),
tools::mn<T_t>(a_point[2],m_min[2]));
m_max.set_value(tools::mx<T_t>(a_point[0],m_max[0]),
tools::mx<T_t>(a_point[1],m_max[1]),
tools::mx<T_t>(a_point[2],m_max[2]));
m_min.set_value(min_of<T_t>(a_point[0],m_min[0]),
min_of<T_t>(a_point[1],m_min[1]),
min_of<T_t>(a_point[2],m_min[2]));
m_max.set_value(max_of<T_t>(a_point[0],m_max[0]),
max_of<T_t>(a_point[1],m_max[1]),
max_of<T_t>(a_point[2],m_max[2]));
}
}
@@ -112,12 +112,12 @@ public:
if(is_empty()) {
set_bounds(a_x,a_y,a_z,a_x,a_y,a_z);
} else {
m_min.set_value(tools::mn<T_t>(a_x,m_min[0]),
tools::mn<T_t>(a_y,m_min[1]),
tools::mn<T_t>(a_z,m_min[2]));
m_max.set_value(tools::mx<T_t>(a_x,m_max[0]),
tools::mx<T_t>(a_y,m_max[1]),
tools::mx<T_t>(a_z,m_max[2]));
m_min.set_value(min_of<T_t>(a_x,m_min[0]),
min_of<T_t>(a_y,m_min[1]),
min_of<T_t>(a_z,m_min[2]));
m_max.set_value(max_of<T_t>(a_x,m_max[0]),
max_of<T_t>(a_y,m_max[1]),
max_of<T_t>(a_z,m_max[2]));
}
}
+42 -1
View File
@@ -7,12 +7,53 @@
namespace tools {
template <class NUMBER,class PREC>
inline bool numbers_are_equals(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
inline bool numbers_are_equal(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
NUMBER diff = a_left - a_right;
if(a_fabs(diff)>=a_prec) return false;
return true;
}
template <class NUMBER,class PREC>
inline bool is_zero(const NUMBER& a_left,const PREC& a_prec,PREC(*a_fabs)(const NUMBER&)) {
if(a_fabs(a_left)>=a_prec) return false;
return true;
}
template <class NUMBER,class PREC>
inline bool numbers_are_equal(const NUMBER& a_left,const NUMBER& a_right,const PREC& a_prec,PREC(*a_fabs)(NUMBER)) {
NUMBER diff = a_left - a_right;
if(a_fabs(diff)>=a_prec) return false;
return true;
}
template <class VEC,class PREC>
inline bool vectors_are_equal(const VEC& a_1,const VEC& a_2,const PREC& a_prec,PREC(*a_fabs)(PREC)) {
if(a_1.size()!=a_2.size()) return false;
typedef typename VEC::size_type sz_t;
sz_t sz = a_1.size();
//bool status = true;
for(sz_t index=0;index<sz;index++) {
if(!numbers_are_equal(a_1[index],a_2[index],a_prec,a_fabs))
//{ ::printf("debug : vectors_are_equals : %lu : %g %g\n",index,a_1[index],a_2[index]);
return false;
//status = false;
//}
}
return true;
//return status;
}
template <class VECVEC,class PREC>
inline bool vecvecs_are_equal(const VECVEC& a_1,const VECVEC& a_2,const PREC& a_prec,PREC(*a_fabs)(PREC)) {
if(a_1.size()!=a_2.size()) return false;
typedef typename VECVEC::size_type sz_t;
sz_t sz = a_1.size();
for(sz_t index=0;index<sz;index++) {
if(!vectors_are_equal(a_1[index],a_2[index],a_prec,a_fabs)) return false;
}
return true;
}
}
#endif
@@ -89,6 +89,43 @@ inline bool inside(const std::pair<T,T>& a_P,const std::vector< std::pair<T,T> >
return ((wn!=0)?true:false);
}
template <class VEC2>
inline bool intersect(const VEC2& P1,const VEC2& Q1,const VEC2& P2,const VEC2& Q2,VEC2& a_out) {
// (P1,Q1) first line, (P2,Q2) second line and a_out intersection.
// return false if no intersection. (For exa, parallel lines).
// P1+(Q1-P1)*r = P2+(Q2-P2)*s
// (Q1-P1)*r - (Q2-P2)*s = P2-P1
// r*(Q1-P1).v0 - s*(Q2-P2).v0 = (P2-P1).v0 //x
// r*(Q1-P1).v1 - s*(Q2-P2).v1 = (P2-P1).v1 //y
// a*r + b*s = c
// d*r + e*s = f
// r = (c*e-f*b)/(a*e-d*b)
// s = (a*f-d*c)/(a*e-d*b)
typedef typename VEC2::elem_t T;
VEC2 A = Q1-P1;
VEC2 B = P2-Q2;
VEC2 C = P2-P1;
T a = A.v0();
T b = B.v0();
T c = C.v0();
T d = A.v1();
T e = B.v1();
T f = C.v1();
T det = a*e-d*b;
if(det==T()) return false;
T r = (c*e-f*b)/det;
a_out = P1+A*r;
return true;
}
}
#endif
@@ -116,9 +116,10 @@ protected:
namespace tools {
// not tested yet.
template <class T>
template <class VEC3>
class clip {
protected:
typedef typename VEC3::elem_t T;
public:
clip():m_cur(0){}
virtual ~clip() {}
@@ -132,41 +133,41 @@ public:
m_cur = 0;
}
void add(const vec3<T>& a_point) {m_data[m_cur].push_back(a_point);}
void add(const VEC3& a_point) {m_data[m_cur].push_back(a_point);}
void execute(const plane<T>& plane) {
void execute(const plane<VEC3>& plane) {
//Clip polygon against plane. This might change the number of
//vertices in the polygon.
unsigned int n = m_data[m_cur].size();
if (n == 0) return;
size_t n = m_data[m_cur].size();
if(!n) return;
// create a loop :
vec3<T> dummy = m_data[m_cur][0];
VEC3 dummy = m_data[m_cur][0];
m_data[m_cur].push_back(dummy);
const vec3<T>& planeN = plane.normal();
const VEC3& planeN = plane.normal();
for(unsigned int i = 0; i < n; i++) {
vec3<T> v0 = m_data[m_cur][i];
vec3<T> v1 = m_data[m_cur][i+1];
for(size_t i = 0; i < n; i++) {
VEC3 v0 = m_data[m_cur][i];
VEC3 v1 = m_data[m_cur][i+1];
T d0 = plane.distance(v0);
T d1 = plane.distance(v1);
if (d0 >= 0.0f && d1 < 0.0f) { // exit plane
vec3<T> dir = v1-v0;
VEC3 dir = v1-v0;
// we know that v0 != v1 since we got here
dir.normalize();
T dot = dir.dot(planeN);
vec3<T> newvertex = v0 - dir * (d0/dot);
VEC3 newvertex = v0 - dir * (d0/dot);
out_point(newvertex);
} else if (d0 < 0.0f && d1 >= 0.0f) { // enter plane
vec3<T> dir = v1-v0;
VEC3 dir = v1-v0;
// we know that v0 != v1 since we got here
dir.normalize();
T dot = dir.dot(planeN);
vec3<T> newvertex = v0 - dir * (d0/dot);
VEC3 newvertex = v0 - dir * (d0/dot);
out_point(newvertex);
out_point(v1);
} else if (d0 >= 0.0f && d1 >= 0.0f) { // in plane
@@ -177,13 +178,13 @@ public:
m_cur ^= 1;
}
const std::vector< vec3<T> >& result() const {return m_data[m_cur];}
const std::vector<VEC3>& result() const {return m_data[m_cur];}
protected:
void out_point(const vec3<T>& a_p) {m_data[m_cur ^ 1].push_back(a_p);}
void out_point(const VEC3& a_p) {m_data[m_cur ^ 1].push_back(a_p);}
protected:
std::vector< vec3<T> > m_data[2];
std::vector<VEC3> m_data[2];
unsigned int m_cur;
};
@@ -63,7 +63,7 @@ public:
const VEC3& direction() const {return m_dir;}
/* not tested :
VEC3 closest_point(const VEC3& a_point) const {
void closest_point(const VEC3& a_point,VEC& a_out) const {
//from coin3d/SbLine.cpp.
//
@@ -76,12 +76,11 @@ public:
// \|
// x a_point
return m_pos + m_dir * ((a_point - m_pos).dot(m_dir));
a_out = m_pos + m_dir * ((a_point - m_pos).dot(m_dir));
}
bool closest_points(const line<T>& a_line,
VEC3& a_on_this,VEC3& a_on_line) const {
bool closest_points(const line<T>& a_line,VEC3& a_on_this,VEC3& a_on_line) const {
//from coin3d/SbLine.cpp.
//WARNING : if ret false, a_on_this, a_on_line not set.
@@ -100,10 +99,8 @@ public:
T c[3], d[3];
for(unsigned int i=0;i<3;i++) {
d[i] =
D1[i] - D0N[i]*(D0[0]*D1[0] + D0[1]*D1[1] + D0[2]*D1[2]);
c[i] =
P1[i] - P0[i] + D0N[i]*(D0[0]*P0[0] + D0[1]*P0[1] + D0[2]*P0[2]);
d[i] = D1[i] - D0N[i]*(D0[0]*D1[0] + D0[1]*D1[1] + D0[2]*D1[2]);
c[i] = P1[i] - P0[i] + D0N[i]*(D0[0]*P0[0] + D0[1]*P0[1] + D0[2]*P0[2]);
}
T den = d[0]*d[0]+d[1]*d[1]+d[2]*d[2];
@@ -112,7 +109,7 @@ public:
T t = -(c[0]*d[0]+c[1]*d[1]+c[2]*d[2]) / den;
a_on_line = a_line.m_pos + a_line.m_dir * t;
a_on_this = closest_point(a_on_line);
closest_point(a_on_line,a_on_this);
return true;
}
+140 -4
View File
@@ -30,11 +30,13 @@ private:
}
#endif
public:
mat(bool a_inc = true) {
mat(
#ifdef TOOLS_MEM
bool a_inc = true
#endif
) {
#ifdef TOOLS_MEM
if(a_inc) mem::increment(s_class().c_str());
#else
(void)a_inc;
#endif
#ifdef TOOLS_MAT_NEW
m_vec = new T[D*D];
@@ -161,6 +163,25 @@ inline nmat<T> copy(const mat<T,D>& a_from) {
return v;
}
template <class VECTOR>
inline void multiply(VECTOR& a_vec,const typename VECTOR::value_type& a_mat) {
//typedef typename VECTOR::size_type sz_t;
//sz_t number = a_vec.size();
//for(sz_t index=0;index<number;index++) a_vec[index] *= a_mat;
typedef typename VECTOR::iterator it_t;
for(it_t it=a_vec.begin();it!=a_vec.end();++it) *it *= a_mat;
}
template <class VECTOR>
inline void multiply(VECTOR& a_vec,const typename VECTOR::value_type::elem_t& a_value) {
typedef typename VECTOR::iterator it_t;
for(it_t it=a_vec.begin();it!=a_vec.end();++it) (*it).multiply(a_value);
}
///////////////////////////////////////////////////////////////////////////////////////
/// related to complex numbers : //////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
template <class MAT>
inline void conjugate(MAT& a_m,typename MAT::elem_t (*a_conj)(const typename MAT::elem_t&)) {
typedef typename MAT::elem_t T;
@@ -171,12 +192,104 @@ inline void conjugate(MAT& a_m,typename MAT::elem_t (*a_conj)(const typename MAT
}
}
template <class MAT>
inline bool is_real(MAT& a_m,typename MAT::elem_t::value_type (*a_imag)(const typename MAT::elem_t&)) {
typedef typename MAT::elem_t T;
T* pos = const_cast<T*>(a_m.data());
unsigned int D2 = a_m.dimension()*a_m.dimension();
for(unsigned int i=0;i<D2;i++,pos++) {if(a_imag(*pos)) return false;}
return true;
}
template <class MAT,class PREC>
inline bool is_real_prec(MAT& a_m,typename MAT::elem_t::value_type (*a_imag)(const typename MAT::elem_t&),
const PREC& a_prec,PREC(*a_fabs)(const typename MAT::elem_t::value_type&)) {\
typedef typename MAT::elem_t T;
T* pos = const_cast<T*>(a_m.data());
unsigned int D2 = a_m.dimension()*a_m.dimension();
for(unsigned int i=0;i<D2;i++,pos++) {if(a_fabs(a_imag(*pos))>=a_prec) return false;}
return true;
}
template <class MAT>
inline bool is_imag(MAT& a_m,typename MAT::elem_t::value_type (*a_real)(const typename MAT::elem_t&)) {
typedef typename MAT::elem_t T;
T* pos = const_cast<T*>(a_m.data());
unsigned int D2 = a_m.dimension()*a_m.dimension();
for(unsigned int i=0;i<D2;i++,pos++) {if(a_real(*pos)) return false;}
return true;
}
template <class CMAT,class RMAT>
inline bool to_real(const CMAT& a_c,RMAT& a_r,typename CMAT::elem_t::value_type (*a_real)(const typename CMAT::elem_t&)) {
if(a_r.dimension()!=a_c.dimension()) return false;
typedef typename CMAT::elem_t CT;
const CT* cpos = a_c.data();
typedef typename RMAT::elem_t RT;
RT* rpos = const_cast<RT*>(a_r.data());
unsigned int D2 = a_c.dimension()*a_c.dimension();
for(unsigned int i=0;i<D2;i++,cpos++,rpos++) *rpos = a_real(*cpos);
return true;
}
template <class MAT>
inline void dagger(MAT& a_m,typename MAT::elem_t (*a_conj)(const typename MAT::elem_t&)) {
conjugate<MAT>(a_m,a_conj);
a_m.transpose();
}
template <class CMAT,class RMAT>
inline bool decomplex(const CMAT& a_c,RMAT& a_r,
typename CMAT::elem_t::value_type (*a_real)(const typename CMAT::elem_t&),
typename CMAT::elem_t::value_type (*a_imag)(const typename CMAT::elem_t&)) {
// CMAT = X+iY
// RMAT = | X Y |
// | -Y X |
typedef typename CMAT::elem_t CT; //std::complex<double>
typedef typename RMAT::elem_t RT; //double
unsigned int cdim = a_c.dimension();
if(a_r.dimension()!=2*cdim) {a_r.set_zero();return false;}
RT value;unsigned int r,c;
for(r=0;r<cdim;r++) {
for(c=0;c<cdim;c++) {
const CT& cvalue = a_c.value(r,c);
value = a_real(cvalue);
a_r.set_value(r,c,value);
a_r.set_value(r+cdim,c+cdim,value);
value = a_imag(cvalue);
a_r.set_value(r,c+cdim,value);
a_r.set_value(r+cdim,c,-value);
}
}
return true;
}
template <class VEC_CMAT,class VEC_RMAT>
inline bool decomplex(
const VEC_CMAT& a_vc,VEC_RMAT& a_vr
,typename VEC_CMAT::value_type::elem_t::value_type (*a_real)(const typename VEC_CMAT::value_type::elem_t&)
,typename VEC_CMAT::value_type::elem_t::value_type (*a_imag)(const typename VEC_CMAT::value_type::elem_t&)
) {
// CMAT = X+iY
// RMAT = | X Y |
// | -Y X |
typedef typename VEC_CMAT::size_type sz_t;
sz_t number = a_vc.size();
a_vr.resize(number);
for(sz_t index=0;index<number;index++) {
if(!decomplex(a_vc[index],a_vr[index],a_real,a_imag)) {
a_vr.clear();
return false;
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//for sf, mf :
//template <class T,unsigned int D>
//inline const T* get_data(const mat<T,D>& a_v) {return a_v.data();}
@@ -409,7 +522,7 @@ inline void matrix_set(MAT& a_m
,const typename MAT::elem_t& a_40,const typename MAT::elem_t& a_41,const typename MAT::elem_t& a_42,const typename MAT::elem_t& a_43,const typename MAT::elem_t& a_44 //5 row
){
//a_<R><C>
//vec[R + C * 4];
//vec[R + C * 5];
typename MAT::elem_t* vec = const_cast<typename MAT::elem_t*>(a_m.data());
vec[0] = a_00;vec[5] = a_01;vec[10] = a_02;vec[15] = a_03;vec[20] = a_04;
vec[1] = a_10;vec[6] = a_11;vec[11] = a_12;vec[16] = a_13;vec[21] = a_14;
@@ -418,6 +531,29 @@ inline void matrix_set(MAT& a_m
vec[4] = a_40;vec[9] = a_41;vec[14] = a_42;vec[19] = a_43;vec[24] = a_44;
}
////////////////////////////////////////////////
/// specific D=6 ///////////////////////////////
////////////////////////////////////////////////
template <class MAT>
inline void matrix_set(MAT& a_m
,const typename MAT::elem_t& a_00,const typename MAT::elem_t& a_01,const typename MAT::elem_t& a_02,const typename MAT::elem_t& a_03,const typename MAT::elem_t& a_04,const typename MAT::elem_t& a_05 //1 row
,const typename MAT::elem_t& a_10,const typename MAT::elem_t& a_11,const typename MAT::elem_t& a_12,const typename MAT::elem_t& a_13,const typename MAT::elem_t& a_14,const typename MAT::elem_t& a_15 //2 row
,const typename MAT::elem_t& a_20,const typename MAT::elem_t& a_21,const typename MAT::elem_t& a_22,const typename MAT::elem_t& a_23,const typename MAT::elem_t& a_24,const typename MAT::elem_t& a_25 //3 row
,const typename MAT::elem_t& a_30,const typename MAT::elem_t& a_31,const typename MAT::elem_t& a_32,const typename MAT::elem_t& a_33,const typename MAT::elem_t& a_34,const typename MAT::elem_t& a_35 //4 row
,const typename MAT::elem_t& a_40,const typename MAT::elem_t& a_41,const typename MAT::elem_t& a_42,const typename MAT::elem_t& a_43,const typename MAT::elem_t& a_44,const typename MAT::elem_t& a_45 //5 row
,const typename MAT::elem_t& a_50,const typename MAT::elem_t& a_51,const typename MAT::elem_t& a_52,const typename MAT::elem_t& a_53,const typename MAT::elem_t& a_54,const typename MAT::elem_t& a_55 //6 row
){
//a_<R><C>
//vec[R + C * 6];
typename MAT::elem_t* vec = const_cast<typename MAT::elem_t*>(a_m.data());
vec[0] = a_00;vec[ 6] = a_01;vec[12] = a_02;vec[18] = a_03;vec[24] = a_04;vec[30] = a_05;
vec[1] = a_10;vec[ 7] = a_11;vec[13] = a_12;vec[19] = a_13;vec[25] = a_14;vec[31] = a_15;
vec[2] = a_20;vec[ 8] = a_21;vec[14] = a_22;vec[20] = a_23;vec[26] = a_24;vec[32] = a_25;
vec[3] = a_30;vec[ 9] = a_31;vec[15] = a_32;vec[21] = a_33;vec[27] = a_34;vec[33] = a_35;
vec[4] = a_40;vec[10] = a_41;vec[16] = a_42;vec[22] = a_43;vec[28] = a_44;vec[34] = a_45;
vec[5] = a_50;vec[11] = a_51;vec[17] = a_52;vec[23] = a_53;vec[29] = a_54;vec[35] = a_55;
}
}
////////////////////////////////////////////////
@@ -15,7 +15,11 @@ class mat4 : public mat<T,4> {
typedef mat<T,4> parent;
typedef mat<T,4> pr;
public:
#ifdef TOOLS_MEM
mat4(bool a_inc = true):parent(a_inc) {}
#else
mat4():parent() {}
#endif
mat4(const mat<T,4>& a_from):parent(a_from){}
virtual ~mat4() {}
public:
@@ -465,11 +469,11 @@ private:static void check_instantiation() {mat4<float> dummy;}
/// common matrices : //////////////////////////
////////////////////////////////////////////////
template <class T>
inline const mat4<T>& mat4_zero() {
static const mat4<T> s_v(false); //inc mem count = false
return s_v;
}
#ifdef TOOLS_MEM
template <class T> inline const mat4<T>& mat4_zero() {static const mat4<T> s_v(false);return s_v;}
#else
template <class T> inline const mat4<T>& mat4_zero() {static const mat4<T> s_v;return s_v;}
#endif
/*
template <class T>
@@ -183,6 +183,7 @@ public:
return true;
}
/*
template <class MAT4>
void set_value(const MAT4& a_m,T(*a_sqrt)(T)) {
//WARNING : not tested.
@@ -220,6 +221,7 @@ public:
m_quat.multiply(one()/a_sqrt(a_m.v33()));
}
}
*/
template <class MAT4>
void value(MAT4& a_m) const {
@@ -48,7 +48,7 @@ public:
bool value(vec3f& a_from,float a_a) const {
return parent::value(a_from,a_a,::sinf,::acosf); //WARNING acos and not cos
}
void set_value(const mat4f& a_m) {parent::set_value(a_m,::sqrtf);}
//void set_value(const mat4f& a_m) {parent::set_value(a_m,::sqrtf);}
void value(mat4f& a_m) const {parent::value(a_m);}
//NOTE : don't handle a static object because of mem balance.
+18 -19
View File
@@ -40,11 +40,13 @@ public:
m_data[1] = a_vec[1];
m_data[2] = a_vec[2];
}
vec3(const T& a0,const T& a1,const T& a2,bool a_inc = true) {
vec3(const T& a0,const T& a1,const T& a2
#ifdef TOOLS_MEM
,bool a_inc = true
#endif
) {
#ifdef TOOLS_MEM
if(a_inc) mem::increment(s_class().c_str());
#else
(void)a_inc;
#endif
m_data[0] = a0;
m_data[1] = a1;
@@ -295,18 +297,15 @@ public: //for iv2sg
}
public:
static const vec3<T>& s_x() {
static const vec3<T> s_v(1,0,0,false);
return s_v;
}
static const vec3<T>& s_y() {
static const vec3<T> s_v(0,1,0,false);
return s_v;
}
static const vec3<T>& s_z() {
static const vec3<T> s_v(0,0,1,false);
return s_v;
}
#if defined(TOOLS_MEM) && !defined(TOOLS_MEM_ATEXIT)
static const vec3<T>& s_x() {static const vec3<T> s_v(1,0,0,false);return s_v;}
static const vec3<T>& s_y() {static const vec3<T> s_v(0,1,0,false);return s_v;}
static const vec3<T>& s_z() {static const vec3<T> s_v(0,0,1,false);return s_v;}
#else
static const vec3<T>& s_x() {static const vec3<T> s_v(1,0,0);return s_v;}
static const vec3<T>& s_y() {static const vec3<T> s_v(0,1,0);return s_v;}
static const vec3<T>& s_z() {static const vec3<T> s_v(0,0,1);return s_v;}
#endif
protected:
T m_data[3];
@@ -318,8 +317,8 @@ template <class T>
inline const T* get_data(const vec3<T>& a_v) {return a_v.data();}
template <class T>
inline void normal(const vec3<T>& a_p0,const vec3<T>& a_p1,const vec3<T>& a_p2,vec3<T>& a_nm,
vec3<T>& a_tmp_1,vec3<T>& a_tmp_2,T(*a_sqrt)(T)) {
inline void get_normal(const vec3<T>& a_p0,const vec3<T>& a_p1,const vec3<T>& a_p2,vec3<T>& a_nm,
vec3<T>& a_tmp_1,vec3<T>& a_tmp_2,T(*a_sqrt)(T)) {
// Used to optimize sg::bin().
//(a_p1-a_p0).cross(a_p2-a_p1,a_nm);
@@ -336,9 +335,9 @@ inline void normal(const vec3<T>& a_p0,const vec3<T>& a_p1,const vec3<T>& a_p2,v
/*
template <class VEC3>
inline void normal(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,VEC3& a_nm) {
inline void get_normal(const VEC3& a_p0,const VEC3& a_p1,const VEC3& a_p2,VEC3& a_nm) {
VEC3 tmp1,tmp2;
normal(a_p0,a_p1,a_p2,a_nm,tmp1,tmp2);
get_normal(a_p0,a_p1,a_p2,a_nm,tmp1,tmp2);
}
*/
template <class VEC3>
@@ -110,8 +110,8 @@ inline vec3f operator*(float a_f,const vec3f& a_v) {
#define TOOLS_VEC3F_MORE_PREC
#ifdef TOOLS_VEC3F_MORE_PREC
inline void normal(const vec3f& a_p0,const vec3f& a_p1,const vec3f& a_p2,vec3f& a_nm,
vec3f& a_tmp_1,vec3f& a_tmp_2) {
inline void get_normal(const vec3f& a_p0,const vec3f& a_p1,const vec3f& a_p2,vec3f& a_nm,
vec3f& a_tmp_1,vec3f& a_tmp_2) {
// Used to optimize sg::bin().
//(a_p1-a_p0).cross(a_p2-a_p1,a_nm);
@@ -126,9 +126,9 @@ inline void normal(const vec3f& a_p0,const vec3f& a_p1,const vec3f& a_p2,vec3f&
a_nm.normalize();
}
#else
inline void normal(const vec3f& a_p0,const vec3f& a_p1,const vec3f& a_p2,vec3f& a_nm,
vec3f& a_tmp_1,vec3f& a_tmp_2) {
normal<float>(a_p0,a_p1,a_p2,a_nm,a_tmp_1,a_tmp_2,::sqrtf);
inline void get_normal(const vec3f& a_p0,const vec3f& a_p1,const vec3f& a_p2,vec3f& a_nm,
vec3f& a_tmp_1,vec3f& a_tmp_2) {
get_normal<float>(a_p0,a_p1,a_p2,a_nm,a_tmp_1,a_tmp_2,::sqrtf);
}
#endif
@@ -46,11 +46,13 @@ public:
m_data[2] = a_vec[2];
m_data[3] = a_vec[3];
}
vec4(const T& a0,const T& a1,const T& a2,const T& a3,bool a_inc = true) {
vec4(const T& a0,const T& a1,const T& a2,const T& a3
#ifdef TOOLS_MEM
,bool a_inc = true
#endif
) {
#ifdef TOOLS_MEM
if(a_inc) mem::increment(s_class().c_str());
#else
(void)a_inc;
#endif
m_data[0] = a0;
m_data[1] = a1;
@@ -17,8 +17,11 @@ public:
public:
vec4f():parent() {}
vec4f(const float a_vec[4]):parent(a_vec) {}
vec4f(const float& a0,const float& a1,const float& a2,const float& a3,bool a_inc = true)
:parent(a0,a1,a2,a3,a_inc){}
#ifdef TOOLS_MEM
vec4f(const float& a0,const float& a1,const float& a2,const float& a3,bool a_inc = true):parent(a0,a1,a2,a3,a_inc){}
#else
vec4f(const float& a0,const float& a1,const float& a2,const float& a3):parent(a0,a1,a2,a3){}
#endif
virtual ~vec4f() {}
public:
vec4f(const vec4f& a_from):parent(a_from){}