gCAD3D 2.40
ut_uti.h
Go to the documentation of this file.
1 /***************************************************************************
2  ut_uti.h - description
3  -------------------
4  begin : Fri Aug 25 2000
5  copyright : (C) 2017 by CADCAM-Services Franz Reiter
6  email : franz.reiter@cadcam.co.at
7 
8  ***************************************************************************
9 
10 
11 -------------------------------------------
12 Korr:
13 2018-01-15 extracted from ../ut/ut_geo.h. RF.
14 
15 
16 -------------------------------------------
17 */
25 //================================================================
26 // prototypes
27 
28 //----------------------------------------------------------------
29  int UTP_comp_0 (double);
30  int UTP_compdb0 (double, double);
31  int UTP_comp2db (double, double, double);
32  int UTP_comp2x2db (double d11,double d12,double d21,double d22,double tol);
33  int UTP_db_ck_in2db (double v, double v1, double v2);
34  int UTP_db_ck_in2dbTol (double v, double v1, double v2, double tol);
35  int UTP_db_cknear_2db (double *db, double *d1, double *d2);
36  int UTP_db_cknear_ndb (double db1, int dbNr, double *dbTab);
37  double UTP_min_d3 (double *d1, double *d2, double *d3);
38  double UTP_max_d3 (double *d1, double *d2, double *d3);
39  double UTP_db_rnd1sig (double);
40  double UTP_db_rnd2sig (double);
41 
42 
43 //================================================================
44 // inline functions
45 
46 #define IABS(i) (((i)<0)?-(i):(i))
47 #define ISIGN(i) ((i>=0)?(1):(-1))
48 
49 #define ICHG01(i) (((i)>0)?(0):(1))
51 
52 // ICHG0-1 change 0 > -1, 1 > -2, 2 > -3
53 #define ICHG0x1(ii) ((ii * -1) - 1)
54 
55 
58 int IMOD (int *iNr, int *iRem, int ival, int idiv);
59 #define IMOD(iNr,iRem,ival,idiv){\
60  *(iNr) = ival / idiv;\
61  *(iRem) = ival - *(iNr) * idiv;}\
62 
63 
66 #define IMIN(x,y) (((x)<(y))?(x):(y))
67 
70 #define IMAX(x,y) (((x)>(y))?(x):(y))
71 
72 
74 #define ILIM01(ii) (((ii) > 0)?1:0)
75 
76 
78 #define ILIMm10(ii) (((ii) < 0)?-1:0)
79 
80 
82 #define ILIM0X(x,hi) (((x)>(hi))?(hi):(((x)<0)?0:(x)))
83 
88 
90 #define ILIM2(x,lo,hi) (((x)>(hi))?(hi):(((x)<(lo))?(lo):(x)))
91 
96 
102 #define ILIMCK1(x,lim) (((x)>(lim))?(1):(((x)<(0))?(1):(0)))
103 
104 
111 #define ILIMCK2(x,lo,hi) (((x)>(hi))?(1):(((x)<(lo))?(1):(0)))
112 
113 
121 #define I_XOR_2I(i1,i2)i1 ^ i2
122 
123 
130 // ? for ascending; : for descending.
131 #define UTN_LIMCK__(x,v1,v2) (((v1)<(v2))\
132 ?(((x)>(v2))?(1):(((x)<(v1))?(1):(0)))\
133 :(((x)>(v1))?(1):(((x)<(v2))?(1):(0))))
134 
135 
138 #define ICHAR(x) ((x) & 15)
139 
140 
141 // UTI_round_32up round integer up to 32
142 // eg 2 -> 32; 14 -> 32; 60 -> 64; 1036 -> 1056
143 #define UTI_round_32up(ii) ii + 32 & ~31
144 
145 
146 // UTI_I32_2I16 get int from 2 shorts
147 int UTI_I32_2I16 (short hi, short lo);
148 #define UTI_I32_2I16(hi,lo) ((hi<<16)+lo)
149 
150 
151 // UTI_hiI16_I32 get hi (left) short out of 32-bit-int
152 int UTI_hiI16_I32 (int i32);
153 #define UTI_hiI16_I32(i32) (i32>>16)
154 
155 
156 // UTI_loI16_I32 get lo (right) short out of 32-bit-int
157 int UTI_loI16_I32 (int i32);
158 #define UTI_loI16_I32(i32) (i32&65535)
159 
160 
161 // UTI_i2_sort sort 2 integers
162 void UTI_i2_sort (int*,int*);
163 #define UTI_i2_sort(i1,i2)if(*i1>*i2){\
164  int _i3 = *i1; *i1 = *i2; *i2 = _i3;}
165 
166 
171 #define UTI_iNr_chrNr(i1) (((i1) >> 2) + 1) // (((i1) + 4) / 4)
172 
174 #define FDABS(df) ((df>=0.f)?(df):(-df))
175 
176 #define DMIN(x,y) (((x)<(y))?(x):(y))
177 #define DMAX(x,y) (((x)>(y))?(x):(y))
178 
179 
182 double DMOD (int *iNr, double *dRem, double dval, double ddiv);
183 #define DMOD(iNr,dRem,dval,ddiv){\
184  *(dRem) = dval / ddiv;\
185  *(iNr) = *(dRem);\
186  *(dRem) -= *(iNr) * ddiv;}
187 // *(dRem) = remquo (dval, ddiv, iNr);} DOES ROUNDING !
188 
189 
191 #define DLIM01(dd) ((dd >= 0.)?0:1)
192 
198 #define DLIM2(x,lo,hi) (((x)>(hi))?(hi):(((x)<(lo))?(lo):(x)))
199 
204 
205 #define DSIGN(d) ((d>=0.)?(1):(-1))
206 
207 #define DSIGTOL(dd,tol) ((dd>tol)?(1):((dd<-(tol))?(-1):(0)))
209 
216 #define ACOS(dCos) ((dCos>=1.)?(0.):((dCos<=-1.)?(RAD_180):acos(dCos)))
217 
218 
219 //----------------------------------------------------------------
228 #define UTP_comp_0(db) (fabs(db) < UT_TOL_min1)
229 
230 
236 #define UTP_comp2db(d1,d2,tol) (fabs(d2-d1) < (tol))
237 
238 
244 #define UTP_px_paramp0p1px(p0,p1,par)\
245  ((p1) - (p0)) * (par) + (p0);
246 
247 
248 double UTP_db_comp_0 (double);
250 #define UTP_db_comp_0(d1) ((fabs(d1) < UT_TOL_min1) ? 0.0 : d1)
251 
252 
253 
254 //----------------------------------------------------------------
255 // set/clr/get bits in byte|short|int|long; see also ../ut/ut_BitTab.h
256 
260 #define BIT_SET(i,b) (i)|=(b)
261 
266 #define BIT_CLR(i,b) (i)&=~(b)
267 
272 #define BIT_GET(i,b) ((i)&(b))
273 
274 
275 // EOF
int UTP_compdb0(double db, double tol)
Definition: ut_uti.c:672
#define UTI_loI16_I32(i32)
Definition: ut_uti.h:158
int UTP_db_cknear_ndb(double db1, int dbNr, double *dbTab)
Definition: ut_uti.c:1223
double UTP_db_rnd2sig(double d1)
Definition: ut_uti.c:1048
#define DMOD(iNr, dRem, dval, ddiv)
Definition: ut_uti.h:183
int UTP_comp2x2db(double d11, double d12, double d21, double d22, double tol)
Definition: ut_uti.c:1249
#define UTI_i2_sort(i1, i2)
Definition: ut_uti.h:163
#define UTP_comp_0(db)
UTP_comp_0 compare double (double == 0.0 + - UT_TOL_min1)
Definition: ut_uti.h:228
#define UTI_hiI16_I32(i32)
Definition: ut_uti.h:153
double UTP_max_d3(double *d1, double *d2, double *d3)
Definition: ut_uti.c:1457
int UTP_db_ck_in2db(double v, double v1, double v2)
Definition: ut_uti.c:695
#define IMOD(iNr, iRem, ival, idiv)
Definition: ut_uti.h:59
int UTP_db_cknear_2db(double *db, double *d1, double *d2)
Definition: ut_uti.c:1207
double UTP_min_d3(double *d1, double *d2, double *d3)
Definition: ut_uti.c:1289
#define UTP_comp2db(d1, d2, tol)
UTP_comp2db compare 2 doubles (with tolerance)
Definition: ut_uti.h:236
double UTP_db_rnd1sig(double d1)
Definition: ut_uti.c:996
int UTP_db_ck_in2dbTol(double v, double v1, double v2, double tol)
Definition: ut_uti.c:725
#define UTP_db_comp_0(d1)
UTP_db_comp_0 if fabs(d1) &lt; UT_TOL_min1) d1 = 0.;.
Definition: ut_uti.h:250
#define UTI_I32_2I16(hi, lo)
Definition: ut_uti.h:148