--- ray/src/common/fvect.c 1991/03/19 13:14:19 1.5 +++ ray/src/common/fvect.c 1998/08/12 17:57:19 2.4 @@ -1,7 +1,7 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1998 Silicon Graphics, Inc. */ #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static char SCCSid[] = "$SunId$ SGI"; #endif /* @@ -10,11 +10,10 @@ static char SCCSid[] = "$SunId$ LBL"; * 8/14/85 */ +#include #include "fvect.h" -#define FTINY 1e-7 - double fdot(v1, v2) /* return the dot product of two vectors */ register FVECT v1, v2; @@ -27,7 +26,7 @@ double dist2(p1, p2) /* return square of distance between points */ register FVECT p1, p2; { - static FVECT delta; + FVECT delta; delta[0] = p2[0] - p1[0]; delta[1] = p2[1] - p1[1]; @@ -41,7 +40,7 @@ dist2line(p, ep1, ep2) /* return square of distance t FVECT p; /* the point */ FVECT ep1, ep2; /* points on the line */ { - static double d, d1, d2; + register double d, d1, d2; d = dist2(ep1, ep2); d1 = dist2(ep1, p); @@ -56,7 +55,7 @@ dist2lseg(p, ep1, ep2) /* return square of distance t FVECT p; /* the point */ FVECT ep1, ep2; /* the end points */ { - static double d, d1, d2; + register double d, d1, d2; d = dist2(ep1, ep2); d1 = dist2(ep1, p); @@ -97,23 +96,22 @@ double normalize(v) /* normalize a vector, return old magnitude */ register FVECT v; { - static double len; + register double len; len = DOT(v, v); if (len <= 0.0) return(0.0); - /****** problematic - if (len >= (1.0-FTINY)*(1.0-FTINY) && - len <= (1.0+FTINY)*(1.0+FTINY)) - return(1.0); - ******/ + if (len <= 1.0+FTINY && len >= 1.0-FTINY) + len = 0.5 + 0.5*len; /* first order approximation */ + else + len = sqrt(len); - len = sqrt(len); v[0] /= len; v[1] /= len; v[2] /= len; + return(len); } @@ -122,20 +120,19 @@ spinvector(vres, vorig, vnorm, theta) /* rotate vector FVECT vres, vorig, vnorm; double theta; { - extern double sin(), cos(); - double sint, cost, dotp; + double sint, cost, normprod; FVECT vperp; register int i; if (theta == 0.0) { - VCOPY(vres, vorig); + if (vres != vorig) + VCOPY(vres, vorig); return; } - sint = sin(theta); cost = cos(theta); - dotp = DOT(vorig, vnorm); + sint = sin(theta); + normprod = DOT(vorig, vnorm)*(1.-cost); fcross(vperp, vnorm, vorig); for (i = 0; i < 3; i++) - vres[i] = vnorm[i]*dotp*(1.-cost) + - vorig[i]*cost + vperp[i]*sint; + vres[i] = vorig[i]*cost + vnorm[i]*normprod + vperp[i]*sint; }