--- ray/src/hd/sm_geom.h 1998/08/20 16:47:22 3.2 +++ ray/src/hd/sm_geom.h 1998/12/28 18:07:35 3.7 @@ -8,6 +8,12 @@ /* Assumes included after standard.h */ +#include + +#define F_TINY 1e-5 +#define FZERO(x) ((x) < F_TINY && (x) > -F_TINY) +#define FEQUAL(a,b) FZERO((a) - (b)) + #define ZERO(x) ((x) < FTINY && (x) > -FTINY) #define EQUAL(a,b) ZERO((a) - (b)) @@ -16,8 +22,34 @@ #define FALSE 0 #endif +typedef struct _FPEQ { + FVECT n; + double d; + char x,y,z; +}FPEQ; + +#define FP_N(f) ((f).n) +#define FP_D(f) ((f).d) +#define FP_X(f) ((f).x) +#define FP_Y(f) ((f).y) +#define FP_Z(f) ((f).z) + +typedef long BCOORD; +typedef long BDIR; +typedef long TINT; + +#define BITS_BCOORD (BITS(long)-2) +#define SHIFT_MAXBCOORD (BITS_BCOORD-1) +#define MAXBCOORD ((1L << BITS_BCOORD)-1) +#define MAXBCOORD2 (MAXBCOORD>>1) +#define MAXBCOORD4 (MAXBCOORD2>>1) + #define M_2_3_PI PI*2/3 +#ifndef INVALID +#define INVALID -1 +#endif + #define GT_INVALID 0 #define GT_VERTEX 1 #define GT_EDGE 2 @@ -29,21 +61,31 @@ #define ZERO_VEC3(v) (ZERO(v[0]) && ZERO(v[1]) && ZERO(v[2]) ) #define EQUAL_VEC3(a,b) (EQUAL(a[0],b[0])&&EQUAL(a[1],b[1])&&EQUAL(a[2],b[2])) +#define OPP_EQUAL_VEC3(a,b) (EQUAL(a[0],-b[0])&&EQUAL(a[1],-b[1])&&EQUAL(a[2],-b[2])) +#define FZERO_VEC3(v) (FZERO(v[0]) && FZERO(v[1]) && FZERO(v[2]) ) +#define FEQUAL_VEC3(a,b) (FEQUAL(a[0],b[0])&&FEQUAL(a[1],b[1])&&FEQUAL(a[2],b[2])) #define NEGATE_VEC3(v) ((v)[0] *= -1.0,(v)[1] *= -1.0,(v)[2] *= -1.0) #define COPY_VEC2(v1,v2) ((v1)[0]=(v2)[0],(v1)[1]=(v2)[1]) #define DIST(a,b) (sqrt(((a)[0]-(b)[0])*((a)[0]-(b)[0]) + \ ((a)[1]-(b)[1])*((a)[1]-(b)[1]) + \ ((a)[2]-(b)[2])*((a)[2]-(b)[2]))) +#define DIST_SQ(a,b) (((a)[0]-(b)[0])*((a)[0]-(b)[0]) + \ + ((a)[1]-(b)[1])*((a)[1]-(b)[1]) + \ + ((a)[2]-(b)[2])*((a)[2]-(b)[2])) +#define SIGN(x) ((x<0)?-1:1) #define CROSS_VEC2(v1,v2) (((v1)[0]*(v2)[1]) - ((v1)[1]*(v2)[0])) #define DOT_VEC2(v1,v2) ((v1)[0]*(v2)[0] + (v1)[1]*(v2)[1]) -#define EDGE_MIDPOINT_VEC3(a,v1,v2) ((a)[0]=((v1)[0]+(v2)[0])*0.5, \ +#define EDGE_MIDPOINT(a,v1,v2) ((a)[0]=((v1)[0]+(v2)[0])*0.5, \ (a)[1]=((v1)[1]+(v2)[1])*0.5,(a)[2] = ((v1)[2]+(v2)[2])*0.5) #define MIN_VEC3(v) ((v)[0]<(v)[1]?((v)[0]<(v)[2]?(v)[0]:v[2]): \ (v)[1]<(v)[2]?(v)[1]:(v)[2]) - +#define MAX3(a,b,c) (((b)>(a))?((b) > (c))?(b):(c):((a)>(c))?(a):(c)) +#define MIN3(a,b,c) (((b)<(a))?((b) < (c))?(b):(c):((a)<(c))?(a):(c)) +#define MAX(a,b) (((b)>(a))?(b):(a)) +#define MIN(a,b) (((b)<(a))?(b):(a)) #define SUM_3VEC3(r,a,b,c) ((r)[0]=(a)[0]+(b)[0]+(c)[0], \ (r)[1]=(a)[1]+(b)[1]+(c)[1],(r)[2]=(a)[2]+(b)[2]+(c)[2]) @@ -82,5 +124,10 @@ double tri_normal(); /* double spherical_edge_normal(FVECT v0,FVECT v1,FVECT n,char norm) */ double spherical_edge_normal(); +double point_on_sphere(); +#define point_in_stri_n(n0,n1,n2,p) \ + ((DOT(n0,p)<=FTINY)&&(DOT(n1,p)<=FTINY)&&(DOT(n2,p)<=FTINY)) + +#define PT_ON_PLANE(p,peq) (DOT(FP_N(peq),p)+FP_D(peq))