gCAD3D 2.40
ut_uti.h File Reference

Go to the source code of this file.

Macros

#define IABS(i)   (((i)<0)?-(i):(i))
 abs(int); always positive More...
 
#define ISIGN(i)   ((i>=0)?(1):(-1))
 sign of int; +1 or -1 More...
 
#define ICHG01(i)   (((i)>0)?(0):(1))
 change 0 -> 1, 1 -> 0; i1 = ICHG01 (i1); More...
 
#define ICHG0x1(ii)   ((ii * -1) - 1)
 
#define IMOD(iNr, iRem, ival, idiv)
 
#define IMIN(x, y)   (((x)<(y))?(x):(y))
 
#define IMAX(x, y)   (((x)>(y))?(x):(y))
 
#define ILIM01(ii)   (((ii) > 0)?1:0)
 ILIM01 returns 0 (ii <= 0) or 1 (ii >= 1) More...
 
#define ILIMm10(ii)   (((ii) < 0)?-1:0)
 ILIM0x1 returns 0 (ii >= 0) or -1 (ii <= -1) More...
 
#define ILIM0X(x, hi)   (((x)>(hi))?(hi):(((x)<0)?0:(x)))
 ILIM0X returns x = between 0 and hi. More...
 
#define ILIM2(x, lo, hi)   (((x)>(hi))?(hi):(((x)<(lo))?(lo):(x)))
 ILIM2 returns x = between lo and hi. More...
 
#define ILIMCK1(x, lim)   (((x)>(lim))?(1):(((x)<(0))?(1):(0)))
 
#define ILIMCK2(x, lo, hi)   (((x)>(hi))?(1):(((x)<(lo))?(1):(0)))
 
#define I_XOR_2I(i1, i2)   i1 ^ i2
 
#define UTN_LIMCK__(x, v1, v2)
 
#define ICHAR(x)   ((x) & 15)
 
#define UTI_round_32up(ii)   ii + 32 & ~31
 
#define UTI_I32_2I16(hi, lo)   ((hi<<16)+lo)
 
#define UTI_hiI16_I32(i32)   (i32>>16)
 
#define UTI_loI16_I32(i32)   (i32&65535)
 
#define UTI_i2_sort(i1, i2)
 
#define UTI_iNr_chrNr(i1)   (((i1) >> 2) + 1)
 UTI_iNr_chrNr give nr of ints for n characters (not including \0) More...
 
#define FDABS(df)   ((df>=0.f)?(df):(-df))
 FDABS absolute value of float. More...
 
#define DMIN(x, y)   (((x)<(y))?(x):(y))
 
#define DMAX(x, y)   (((x)>(y))?(x):(y))
 
#define DMOD(iNr, dRem, dval, ddiv)
 
#define DLIM01(dd)   ((dd >= 0.)?0:1)
 DLIM01 0 if (d1 >= 0.); 1 if (d1 < 0.) More...
 
#define DLIM2(x, lo, hi)   (((x)>(hi))?(hi):(((x)<(lo))?(lo):(x)))
 DLIM2 returns x = between lo and hi. More...
 
#define DSIGN(d)   ((d>=0.)?(1):(-1))
 sign of double; +1 or -1 More...
 
#define DSIGTOL(dd, tol)   ((dd>tol)?(1):((dd<-(tol))?(-1):(0)))
 DSIGTOL sign of double with tolerance (-1|0|1) More...
 
#define ACOS(dCos)   ((dCos>=1.)?(0.):((dCos<=-1.)?(RAD_180):acos(dCos)))
 
#define UTP_comp_0(db)   (fabs(db) < UT_TOL_min1)
 UTP_comp_0 compare double (double == 0.0 + - UT_TOL_min1) More...
 
#define UTP_comp2db(d1, d2, tol)   (fabs(d2-d1) < (tol))
 UTP_comp2db compare 2 doubles (with tolerance) More...
 
#define UTP_px_paramp0p1px(p0, p1, par)   ((p1) - (p0)) * (par) + (p0);
 UTP_px_paramp0p1px Zahl aus p0, p1 und Parameterwert. More...
 
#define UTP_db_comp_0(d1)   ((fabs(d1) < UT_TOL_min1) ? 0.0 : d1)
 UTP_db_comp_0 if fabs(d1) < UT_TOL_min1) d1 = 0.;. More...
 
#define BIT_SET(i, b)   (i)|=(b)
 
#define BIT_CLR(i, b)   (i)&=~(b)
 
#define BIT_GET(i, b)   ((i)&(b))
 

Functions

int UTP_comp_0 (double)
 
int UTP_compdb0 (double, double)
 
int UTP_comp2db (double, double, double)
 
int UTP_comp2x2db (double d11, double d12, double d21, double d22, double tol)
 
int UTP_db_ck_in2db (double v, double v1, double v2)
 
int UTP_db_ck_in2dbTol (double v, double v1, double v2, double tol)
 
int UTP_db_cknear_2db (double *db, double *d1, double *d2)
 
int UTP_db_cknear_ndb (double db1, int dbNr, double *dbTab)
 
double UTP_min_d3 (double *d1, double *d2, double *d3)
 
double UTP_max_d3 (double *d1, double *d2, double *d3)
 
double UTP_db_rnd1sig (double)
 
double UTP_db_rnd2sig (double)
 
int IMOD (int *iNr, int *iRem, int ival, int idiv)
 
int UTI_I32_2I16 (short hi, short lo)
 
int UTI_hiI16_I32 (int i32)
 
int UTI_loI16_I32 (int i32)
 
void UTI_i2_sort (int *, int *)
 
double DMOD (int *iNr, double *dRem, double dval, double ddiv)
 
double UTP_db_comp_0 (double)
 

Macro Definition Documentation

#define IABS (   i)    (((i)<0)?-(i):(i))

abs(int); always positive

#define ISIGN (   i)    ((i>=0)?(1):(-1))

sign of int; +1 or -1

#define ICHG01 (   i)    (((i)>0)?(0):(1))

change 0 -> 1, 1 -> 0; i1 = ICHG01 (i1);

#define ICHG0x1 (   ii)    ((ii * -1) - 1)
#define IMOD (   iNr,
  iRem,
  ival,
  idiv 
)
Value:
{\
*(iNr) = ival / idiv;\
*(iRem) = ival - *(iNr) * idiv;}\
#define IMIN (   x,
 
)    (((x)<(y))?(x):(y))

IMIN: return the smaller of 2 values IMIN (val2,val2) return val1 if val1<val2 else return val2

#define IMAX (   x,
 
)    (((x)>(y))?(x):(y))

IMAX: return the bigger of 2 values IMAX (val1,val2) return val1 if val1>val2 else return val2

#define ILIM01 (   ii)    (((ii) > 0)?1:0)

ILIM01 returns 0 (ii <= 0) or 1 (ii >= 1)

#define ILIMm10 (   ii)    (((ii) < 0)?-1:0)

ILIM0x1 returns 0 (ii >= 0) or -1 (ii <= -1)

#define ILIM0X (   x,
  hi 
)    (((x)>(hi))?(hi):(((x)<0)?0:(x)))

ILIM0X returns x = between 0 and hi.

#define ILIM2 (   x,
  lo,
  hi 
)    (((x)>(hi))?(hi):(((x)<(lo))?(lo):(x)))

ILIM2 returns x = between lo and hi.

* ii = ILIM2 (i1, 10, 20);
* returns 10 if i1<10; else returns 20 if i1>20; else returns i1.
*
#define ILIMCK1 (   x,
  lim 
)    (((x)>(lim))?(1):(((x)<(0))?(1):(0)))
* ii = ILIM2 (i1, 10, 20);
* returns 10 if i1<10; else returns 20 if i1>20; else returns i1.
*

ILIMCK1 check if x is between 0 and lim

* returns 0 if ix is between 0 and lim; else 1.
* ii = ILIMCK1 (x, 10);
*
#define ILIMCK2 (   x,
  lo,
  hi 
)    (((x)>(hi))?(1):(((x)<(lo))?(1):(0)))

ILIMCK2 check if x is between hi and lo

* returns 0 if ix is between iHi and iLo; else 1.
* lo hi must be ascending. For int and double.
* ii = ILIMCK2 (x, 10, 20);
*
#define I_XOR_2I (   i1,
  i2 
)    i1 ^ i2

I_XOR_2I XOR exclusive or;

* 0,0 -> 0; printf(" %d\n",I_XOR_2I(0,0));
* 0,1 -> 1;
* 1,0 -> 1;
* 1,1 -> 0;
*
#define UTN_LIMCK__ (   x,
  v1,
  v2 
)
Value:
(((v1)<(v2))\
?(((x)>(v2))?(1):(((x)<(v1))?(1):(0)))\
:(((x)>(v1))?(1):(((x)<(v2))?(1):(0))))
double v1
Definition: ut_geo.h:478

UTN_LIMCK__ check if x is between v1 and v2

* returns 0 if x is between v1 and v2; else 1 (not between v1 and v2).
* lo hi can be ascending or descending. For int and double.
* d1 = UTN_LIMCK__ (x, 1., 2.);
*
#define ICHAR (   x)    ((x) & 15)

char –> int; eg get 1 from '1' same as (int = charDig - 48) or (int = charDig - '0')

#define UTI_round_32up (   ii)    ii + 32 & ~31
#define UTI_I32_2I16 (   hi,
  lo 
)    ((hi<<16)+lo)
#define UTI_hiI16_I32 (   i32)    (i32>>16)
#define UTI_loI16_I32 (   i32)    (i32&65535)
#define UTI_i2_sort (   i1,
  i2 
)
Value:
if(*i1>*i2){\
int _i3 = *i1; *i1 = *i2; *i2 = _i3;}
#define UTI_iNr_chrNr (   i1)    (((i1) >> 2) + 1)

UTI_iNr_chrNr give nr of ints for n characters (not including \0)

* makes 2 from 4 (4 chars + \0 needs 2 ints to store in int-words)
*
#define FDABS (   df)    ((df>=0.f)?(df):(-df))

FDABS absolute value of float.

#define DMIN (   x,
 
)    (((x)<(y))?(x):(y))
#define DMAX (   x,
 
)    (((x)>(y))?(x):(y))
#define DMOD (   iNr,
  dRem,
  dval,
  ddiv 
)
Value:
{\
*(dRem) = dval / ddiv;\
*(iNr) = *(dRem);\
*(dRem) -= *(iNr) * ddiv;}
#define DLIM01 (   dd)    ((dd >= 0.)?0:1)

DLIM01 0 if (d1 >= 0.); 1 if (d1 < 0.)

#define DLIM2 (   x,
  lo,
  hi 
)    (((x)>(hi))?(hi):(((x)<(lo))?(lo):(x)))

DLIM2 returns x = between lo and hi.

* i1 = DLIM01 (d1);
* returns 0 if (d1 >= 0.); else returns 1 if (d1 < 0.)
*
#define DSIGN (   d)    ((d>=0.)?(1):(-1))

sign of double; +1 or -1

* di = DLIM2 (d1, 0., 10.);
* returns 0 if d1<0; else returns 10 if d1>10; else returns d1.
*
#define DSIGTOL (   dd,
  tol 
)    ((dd>tol)?(1):((dd<-(tol))?(-1):(0)))

DSIGTOL sign of double with tolerance (-1|0|1)

#define ACOS (   dCos)    ((dCos>=1.)?(0.):((dCos<=-1.)?(RAD_180):acos(dCos)))
* replacing code:
* if (fabs(dd) < tol) rc = 0;
* else if (dd < 0.) rc = 1;
* else rc = -1;
*
#define UTP_comp_0 (   db)    (fabs(db) < UT_TOL_min1)

UTP_comp_0 compare double (double == 0.0 + - UT_TOL_min1)

* Retcode 0: db <> 0.0
* 1: db = 0.0
* UTP_comp_0 (1.); // returns 0 (false, not equal to 0.0)
* UTP_comp_0 (0.); // returns 1 (true, is equal 0)
* see also UTP_db_comp_0
*
#define UTP_comp2db (   d1,
  d2,
  tol 
)    (fabs(d2-d1) < (tol))

UTP_comp2db compare 2 doubles (with tolerance)

* Retcode 0 = Differenz der Werte > tol - different
* Retcode 1 = Differenz der Werte < tol - ident
*
#define UTP_px_paramp0p1px (   p0,
  p1,
  par 
)    ((p1) - (p0)) * (par) + (p0);

UTP_px_paramp0p1px Zahl aus p0, p1 und Parameterwert.

* see also UTP_param_p0p1px
* Example: p0=5, p1=10, par=0.5; retVal=7.5.
*
#define UTP_db_comp_0 (   d1)    ((fabs(d1) < UT_TOL_min1) ? 0.0 : d1)

UTP_db_comp_0 if fabs(d1) < UT_TOL_min1) d1 = 0.;.

#define BIT_SET (   i,
 
)    (i)|=(b)

BIT_SET set bits; BITSET(data,value) data: byte|short|int|long data,value: value of bit to set (1|2|4..)

#define BIT_CLR (   i,
 
)    (i)&=~(b)

BIT_CLR clear bits; BITCLR(data,value) data: byte|short|int|long data,value: value of bit to test (1|2|4..) Example: BITCLR(i1,3); // clear bit-0 and bit-1 of i1

#define BIT_GET (   i,
 
)    ((i)&(b))

BIT_GET filter bits; BITGET(data,value) data: byte|short|int|long to test data,value: value of bit to test (1|2|4..) RetCod: 0 (not set) or value (set)

Function Documentation

int UTP_comp_0 ( double  )
int UTP_compdb0 ( double  ,
double   
)
* UTP_compdb0 compare double mit 0.0 mit Tol.
*
* Retcode 0: db <> 0.0 (gr. oder kl. tol)
* 1: db = 0.0 (innerhalb tol)
*
int UTP_comp2db ( double  ,
double  ,
double   
)
int UTP_comp2x2db ( double  d11,
double  d12,
double  d21,
double  d22,
double  tol 
)
* UTP_comp2x2db compare 2 * 2 doubles (with tolerance)
* 2 * 2 Zahlen vergleichen; gleich=0; verkehrt=1; else=-1.
* RetCod:
* 0 d11 == d21; d12 == d22; beide Paare gleich.
* 1 d11 == d22; d12 == d21; beide Paare gleich, aber verkehrt.
* -1 d11 == d21; d21 != d22;
* -2 d11 == d22; d12 != d21
* ACHTUNG: d12 == d22 wird nicht getestet !
* -3 beide Paare ungleich.
*
int UTP_db_ck_in2db ( double  v,
double  v1,
double  v2 
)
* test if value of v is between v1 / v2
* RC = 0: YES, v is between v1 / v2
* RC = 1: NO, v is outside near v1; v2 > v1.
* RC = 2: NO, v is outside near v2; v2 > v1.
* RC = -1: NO, v is outside near v1; v2 < v1.
* RC = -2: NO, v is outside near v2; v2 < v1.
*
int UTP_db_ck_in2dbTol ( double  v,
double  v1,
double  v2,
double  tol 
)
* test if value of v is between v1 / v2
* RC = 0: YES, v is between v1 / v2
* RC = 1: NO, v is outside v1 / v2
*
int UTP_db_cknear_2db ( double *  db,
double *  d1,
double *  d2 
)
* UTP_db_cknear_2db find nearest double out of 2 doubles
* RetCod 0 = db-d1 ist smaller than db-d2
* RetCod 1 = db-d2 ist smaller than db-d1
*
int UTP_db_cknear_ndb ( double  db1,
int  dbNr,
double *  dbTab 
)

UTP_db_cknear_ndb find nearest double out of dbTab

double UTP_min_d3 ( double *  d1,
double *  d2,
double *  d3 
)

UTP_min_d3 find minimum double of 3; returns double.

double UTP_max_d3 ( double *  d1,
double *  d2,
double *  d3 
)

UTP_max_d3 find maximum double of 3; returns double.

double UTP_db_rnd1sig ( double  )
* auf 1 sig. Stelle bringen:
*
* (0.00579, 1) -> 0.006
* (0.19500, 1) -> 0.2 (gerundet !!)
* (1.00500, 1) -> 1.
* (167.500, 1) -> 200.
*
double UTP_db_rnd2sig ( double  )
* auf 2 sig. Stellen runden
*
* (0.00579, 1) -> 0.0058
* (0.19500, 1) -> 0.19 (gerundet !!)
* (1.00500, 1) -> 1.
* (167.500, 1) -> 170.
*
int IMOD ( int *  iNr,
int *  iRem,
int  ival,
int  idiv 
)

IMOD int - division with remainder Example: IMOD(&in, &ir, 43, 10); // returns in=4, ir=3

int UTI_I32_2I16 ( short  hi,
short  lo 
)
int UTI_hiI16_I32 ( int  i32)
int UTI_loI16_I32 ( int  i32)
void UTI_i2_sort ( int *  ,
int *   
)
double DMOD ( int *  iNr,
double *  dRem,
double  dval,
double  ddiv 
)

DMOD double - division with remainder Example: DMOD(&in, &dr, 43., 10.); // returns in=4, dr=3.

double UTP_db_comp_0 ( double  )