gCAD3D 2.40
ut_uti.c File Reference

auxiliary functions for integers, doubles (UTI_ UTP_ UTN_) More...

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "../ut/ut_geo.h"

Functions

int UTI_ni_ind_CB_sort (void **i1, void **i2)
 
int UTP_sort_npar_npt (int iNr, double *da, Point *pa)
 
int UTP_param_p0p1px (double *parx, double p0, double p1, double px)
 
int UTA_reallTab (char **startAdr, int offset, int recNr, char *oldAdr, char *newAdr)
 
int UTI_dump__ (void *pv, int oSiz)
 
int UTI_add_uniq (int *iNr, int *ia, int iNew)
 
int UTI_deleq (int *i1Nr, int *i1Tab, int *i2Nr, int *i2Tab)
 
int UTI_ni_sort (int *iTab, int iNr)
 
int UTI_ni_ind_sort (int *iia, int *ia, int iNr)
 
int UTI_findeq (int *if1, int *if2, int *iTab1, int iNr1, int *iTab2, int iNr2)
 
int UTI_ind_iTab_i (int ii, int *iTab, int tabSiz)
 
int UTI_div4up (int ii)
 
int UTI_div4diff (int ii)
 
int UTI_round_i2b (int ii)
 
int UTI_round_b2i (int i1)
 
int UTI_sum_row (int iend)
 
int UTI_ndig_int (int *digTab, int digNr, int ii)
 
int UTP_compdb0 (double db, 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_2db_ck_in4db (int *ii1, int *ii2, double *dbTab)
 
 UTP_2db_ck_in2db (double r1Start, double r1End, double r2Start, double r2End)
 
double UTP_db_rnd1sig (double d1)
 
double UTP_db_rnd2sig (double d1)
 
int UTP_db_rnd10 (double d1)
 
int UTP_db_rnd5 (double d1)
 
int UTP_dbsiz (int *i5, double d1)
 
int UTP_dbqsiz (double d1)
 
int UTP_db_cknear_2db (double *db, double *d1, double *d2)
 
int UTP_db_cknear_ndb (double db1, int dbNr, double *dbTab)
 
int UTP_comp2x2db (double d11, double d12, double d21, double d22, double tol)
 
double UTP_min_d3 (double *d1, double *d2, double *d3)
 
int UTP_min_3 (double *d1, double *d2, double *d3)
 
int UTP_min_4 (double *d1, double *d2, double *d3, double *d4)
 
int UTP_min (int dbNr, double *dbTab)
 
int UTP_dbRec_min (int dbNr, double *dTab, int recSiz)
 
double UTP_max_d3 (double *d1, double *d2, double *d3)
 
int UTP_max_3 (double *d1, double *d2, double *d3)
 
int UTP_dbRec_max (int dbNr, double *dTab, int recSiz)
 
int UTP_max (int dbNr, double *dbTab)
 
int UTP_sincosTab_circ (double *sa, double *ca, int dNr)
 

Detailed Description

auxiliary functions for integers, doubles (UTI_ UTP_ UTN_)

=====================================================
List_functions_start:
--------- Addresses (Pointers)
UTA_reallTab reallocate a table of pointers UNFERTIG !
--------- integers
IMAX INLINE
IMIN INLINE
IABS INLINE
IMOD int - division with remainder (modul0) INLINE
ISIGN get sign of int; +1 or -1 INLINE
ICHAR get integer from character-digit INLINE
UTI_I32_2I16 get int from 2 shorts INLINE
UTI_hiI16_I32 get hi (left) short out of 32-bit-int INLINE
UTI_loI16_I32 get lo (right) short out of 32-bit-int INLINE
ICHG01 change 0 > 1, 1 > 0. INLINE
ICHG0x1 change 0 > -1,-1 > 0, 1 > -2, -2 > 1 INLINE
ILIM01 returns 0 (ii <= 0) or 1 (ii >= 1) INLINE
ILIM0x1 returns 0 (ii >= 0) or -1 (ii < 0) INLINE
ILIM2 returns x = between lo and hi INLINE
ILIM0X returns x = between 0 and hi INLINE
I_XOR_2I XOR exclusive or 2 ints INLINE
UTI_add_uniq add int uniq to list
UTI_deleq delete equal records form 2 intLists
UTI_findeq find 2 gleiche Elemente in 2 IntegerListen
UTI_i2_sort sort 2 integers INLINE
UTI_ni_sort sort integerList
UTI_ni_ind_sort return sorted indexarray for integerarray
UTI_ind_iTab_i get index of int in iTab
UTI_iNr_chrNr give nr of ints for n characters (not including \0) INL
UTI_div4up change nr to modulo(4)=0; increase (1|2|3|4 -> 4)
UTI_div4diff get nr of missing bytes for modulo-4.
UTI_round_32up round integer up to 32 INLINE
UTI_round_i2b round integer to byte (back: UTI_round_b2i)
UTI_round_b2i make integer from byte (back from UTI_round_i2b)
UTI_sum_row sum up row from 1 to iend
UTI_ndig_int split integer into digits
--------- integers and doubles
ILIMCK1 check if x is between 0 and lim INLINE
ILIMCK2 check if x is between hi and lo INLINE
UTN_LIMCK__ check if x is between v1 and v2 INLINE
--------- floats;
FDABS absolute value of float
--------- doubles; see also UT1D_
DMAX INLINE
DMIN INLINE
DMOD double - division with remainder (module) INLINE
DSIGN sign of double; +1 or -1 INLINE
DSIGTOL sign of double with tolerance; +1 or -1 INLINE
DLIM01 0 if (d1 >= 0.); 1 if (d1 < 0.) INLINE
DLIM2 limits double between hi and lo-value INLINE
ACOS cos INLINE
UTP_min_3 find minimum double of 3; returns 0|1|2
UTP_min_d3 find minimum double of 3; returns double.
UTP_min_4 find minimum double of 4; returns 0|1|2|3
UTP_min find index of minimum double out of dbTab
UTP_dbRec_min find minimum double out of dbRecords
UTP_max_3 find maximum double of 3
UTP_max_d3 find maximum double of 3; returns double.
UTP_max find minimum double out of dbTab
UTP_dbRec_max find maximum double out of dbRecords
UTP_db_cknear_2db find nearest double out of 2 doubles
UTP_db_cknear_ndb find nearest double out of dbTab
UTP_db_ck_in2db test if value of v is between v1 / v2
UTP_db_ck_in2dbTol test if value of v is between v1 / v2
UTP_2db_ck_in4db die beiden inneren Werte aus 4 Zahlen finden
UTP_2db_ck_in2db test if range2 overlaps range1
UTP_db_comp_0 if fabs(d1) < UT_TOL_min1) d1 = 0.;
UTP_comp_0 compare double (double == 0.0 + - UT_TOL_min1) INLINE
UTP_compdb0 compare double mit 0.0 mit Tol.
UTP_comp2db compare 2 doubles (with tolerance) INLINE
UTP_comp2x2db compare 2 * 2 doubles (with tolerance)
UTP_sort_npar_npt sort ascending parameters, points
UTP_param_p0p1px Parameterwert von Zahl (Parameterwerte fuer 0 u 1)
UTP_px_paramp0p1px Zahl aus p0, p1 und Parameterwert INLINE
UTP_db_rnd1sig Zahl auf 1 signifikante Stelle runden
UTP_db_rnd2sig Zahl auf 2 signifikante Stellen runden
UTP_db_rnd10 round dound double to next 10
UTP_db_rnd5 round dound double to next 5
UTP_dbsiz get size of double; (number of pos. digits);
UTP_dbqsiz get quadr. size (estim.)
UTP_sincosTab_circ sinus- und cosinuswerte fuer einen Vollkreis.
--------- binary
BIT_SET einzelne Bits setzen in einem int INLINE
BIT_CLR einzelne Bits loeschen in einem int INLINE
BIT_GET einzelne Bits filtern in einem int INLINE
UTI_dump__ disp. hex
List_functions_end:
=====================================================
see also:
../ut/ut_mem.c memory-funcs

Function Documentation

int UTI_ni_ind_CB_sort ( void **  i1,
void **  i2 
)
int UTP_sort_npar_npt ( int  iNr,
double *  da,
Point pa 
)
int UTP_param_p0p1px ( double *  parx,
double  p0,
double  p1,
double  px 
)
* UTP_param_p0p1px Parameterwert von Zahl (ex parameterwerte fuer 0 u 1)
* Input: p0 - der Zahlenwert beim Parameterwert 0.
* p1 - der Zahlenwert beim Parameterwert 1.
* px - ein Zahlenwert, von dem der Parameterwert gesucht ist.
* Output: parx der Parameterwert von px.
* retCod 0 = OK;
* -1 = Error (p0==p1)
* Beispiel:
* p0=5.; p1=10.; px=7.5; parx = 0.5
* p0=0.; p1=-1.; px=0.5; parx = -0.5
*
int UTA_reallTab ( char **  startAdr,
int  offset,
int  recNr,
char *  oldAdr,
char *  newAdr 
)
* reallocate a table of pointers
* startAdr is the first address to be modified.
* offset is the distance to the next adress (the recordsize)
*
int UTI_dump__ ( void *  pv,
int  oSiz 
)
int UTI_add_uniq ( int *  iNr,
int *  ia,
int  iNew 
)
* UTI_add_uniq add int uniq to list
* NO CHECK FOR SIZE OF IA
*
int UTI_deleq ( int *  i1Nr,
int *  i1Tab,
int *  i2Nr,
int *  i2Tab 
)

delete equal records form 2 intLists

int UTI_ni_sort ( int *  iTab,
int  iNr 
)

int-tabelle sortieren

int UTI_ni_ind_sort ( int *  iia,
int *  ia,
int  iNr 
)
* UTI_ni_ind_sort return sorted indexarray for integerarray
* Input: integerarray ia with iNr elements.
* Output: indexarray iia with iNr elements.
* Retcod: 0=OK; -1=out of memory
* Example:
* int ia[]={2,6,3,3,4}; int iia[5];
* UTI_ni_ind_sort (iia, ia, 5);
* for(i1=0;i1<5;++i1)printf(" ia[iia[%d]]=%d\n",i1,ia[iia[i1]]);
*
int UTI_findeq ( int *  if1,
int *  if2,
int *  iTab1,
int  iNr1,
int *  iTab2,
int  iNr2 
)
* find 2 gleiche Elemente in den Listen iTab1 / iTab1
* if1, if2 Indices der gleichen Elemente
* RetCode:
* 0 gleiche Elemente gefunden; Indices out in if1, if2
* -1 keine gleichen Elemente gefunden.
*
int UTI_ind_iTab_i ( int  ii,
int *  iTab,
int  tabSiz 
)
* UTI_ind_iTab_i get index of int <ii> in iTab
* RetCod: index into iTab or -1 (not found)
*
int UTI_div4up ( int  ii)
* UTI_div4up change nr to modulo(4)=0; increase (1|2|3|4 -> 4)
* returns ii as a multiple of 4.
*
int UTI_div4diff ( int  ii)
* UTI_div4diff get nr of missing bytes for modulo-4.
* 1|5 returns 3; 2|6 returns 2 ..
*
int UTI_round_i2b ( int  ii)
* UTI_round_i2b round integer to byte (back: UTI_round_b2i)
* 0,1 -> 0; 2 -> 1; 3,4 -> 2; 5-8 -> 3; 9-16 -> 4; 17-32 -> 5; ..
* Purpose: save Integers in a single byte, rounding up.
* UTI_round_i2b(20) -> 5; // all values from 17 to 32 give 5;
* UTI_round_b2i(5) -> 32
*
int UTI_round_b2i ( int  i1)
* UTI_round_b2i make integer from byte (back from UTI_round_i2b)
* 0 -> 0; 1 -> 2; 2 -> 4; 3 -> 8; 4 -> 16; 5 -> 32; .. 8=256; .. 10=1024 ..
*
int UTI_sum_row ( int  iend)
int UTI_ndig_int ( int *  digTab,
int  digNr,
int  ii 
)
* UTI_ndig_int split integer into digits
* Example:
* ii=123 returns digTab[0]=3; digTab[2]=2; digTab[2]=1;
*
int UTP_compdb0 ( double  db,
double  tol 
)
* 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_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_2db_ck_in4db ( int *  ii1,
int *  ii2,
double *  dbTab 
)

UTP_2db_ck_in4db die beiden inneren Werte aus 4 Zahlen finden

UTP_2db_ck_in2db ( double  r1Start,
double  r1End,
double  r2Start,
double  r2End 
)
double UTP_db_rnd1sig ( double  d1)
* 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  d1)
* 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 UTP_db_rnd10 ( double  d1)
* 2 gives 10
* 40 gives 100
* 777 gives 1000
*
int UTP_db_rnd5 ( double  d1)

================================================================

* 2 gives 5
* 7 gives 10
* 40 gives 50
* 77 gives 100
* 777 gives 1000
*
int UTP_dbsiz ( int *  i5,
double  d1 
)
* UTP_dbsiz get size of double; (number of pos. digits);
* 5 gives 1, 12 gives 2 ...
* i5 gives if d1 is over(+1) or under(-1) 5.
* d1=22 gives i5=-1;
* d1=777 gives i5=+1;
*
int UTP_dbqsiz ( double  d1)

UTP_dbqsiz get quadr. size (estim.)

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

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.
*
double UTP_min_d3 ( double *  d1,
double *  d2,
double *  d3 
)

UTP_min_d3 find minimum double of 3; returns double.

int UTP_min_3 ( double *  d1,
double *  d2,
double *  d3 
)
* UTP_min_3 find minimum double of 3
* returns 0|1|2
*
int UTP_min_4 ( double *  d1,
double *  d2,
double *  d3,
double *  d4 
)
* UTP_min_4 find minimum double of 4
* returns 0|1|2|3
*
int UTP_min ( int  dbNr,
double *  dbTab 
)
* UTP_min find minimum double out of dbTab
* returns index of min. double.
*
int UTP_dbRec_min ( int  dbNr,
double *  dTab,
int  recSiz 
)
* UTP_dbRec_min find minimum double out of dbRecords
* dbNr records of size recSiz; first obj is a double; find index of min
*
double UTP_max_d3 ( double *  d1,
double *  d2,
double *  d3 
)

UTP_max_d3 find maximum double of 3; returns double.

int UTP_max_3 ( double *  d1,
double *  d2,
double *  d3 
)
* UTP_max_3 find maximum double of 3
* returns 0|1|2
*
int UTP_dbRec_max ( int  dbNr,
double *  dTab,
int  recSiz 
)
* UTP_dbRec_max find maximum double out of dbRecords
* dbNr records of size recSiz; first obj is a double; find index of min
*
int UTP_max ( int  dbNr,
double *  dbTab 
)

UTP_min find minimum double out of dbTab

int UTP_sincosTab_circ ( double *  sa,
double *  ca,
int  dNr 
)
* die sinus- und cosinuswerte fuer einen Vollkreis.
* insgesamt dNr Werte; erster und letzter sind gleich.
* sa = sin-Tabelle;
* ca = cos-Tabelle
*
* xxxx
* | xxx
* | x
* | r / | x
* | / | x
* | / sin x
* --x-------|---x-------------
* cos x
*