ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fvect.c
(Generate patch)

Comparing ray/src/common/fvect.c (file contents):
Revision 2.4 by gwlarson, Wed Aug 12 17:57:19 1998 UTC vs.
Revision 2.7 by greg, Tue Feb 25 02:47:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5 < *  fvect.c - routines for float vector calculations
9 < *
10 < *     8/14/85
5 > *  fvect.c - routines for floating-point vector calculations
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  <math.h>
11   #include  "fvect.h"
12  
# Line 31 | Line 28 | register FVECT  p1, p2;
28          delta[0] = p2[0] - p1[0];
29          delta[1] = p2[1] - p1[1];
30          delta[2] = p2[2] - p1[2];
31 +
32          return(DOT(delta, delta));
33   }
34  
# Line 44 | Line 42 | FVECT  ep1, ep2;       /* points on the line */
42  
43          d = dist2(ep1, ep2);
44          d1 = dist2(ep1, p);
45 <        d2 = dist2(ep2, p);
45 >        d2 = d + d1 - dist2(ep2, p);
46  
47 <        return(d1 - (d+d1-d2)*(d+d1-d2)/d/4);
47 >        return(d1 - 0.25*d2*d2/d);
48   }
49  
50  
# Line 68 | Line 66 | FVECT  ep1, ep2;       /* the end points */
66                  if (d1 - d2 > d)
67                          return(d2);
68          }
69 +        d2 = d + d1 - d2;
70  
71 <        return(d1 - (d+d1-d2)*(d+d1-d2)/d/4);   /* distance to line */
71 >        return(d1 - 0.25*d2*d2/d);      /* distance to line */
72   }
73  
74  
75 + void
76   fcross(vres, v1, v2)            /* vres = v1 X v2 */
77   register FVECT  vres, v1, v2;
78   {
# Line 82 | Line 82 | register FVECT  vres, v1, v2;
82   }
83  
84  
85 + void
86   fvsum(vres, v0, v1, f)          /* vres = v0 + f*v1 */
87 < FVECT  vres, v0, v1;
88 < double  f;
87 > register FVECT  vres, v0, v1;
88 > register double  f;
89   {
90          vres[0] = v0[0] + f*v1[0];
91          vres[1] = v0[1] + f*v1[1];
# Line 96 | Line 97 | double
97   normalize(v)                    /* normalize a vector, return old magnitude */
98   register FVECT  v;
99   {
100 <        register double  len;
100 >        register double  len, d;
101          
102 <        len = DOT(v, v);
102 >        d = DOT(v, v);
103          
104 <        if (len <= 0.0)
104 >        if (d <= 0.0)
105                  return(0.0);
106          
107 <        if (len <= 1.0+FTINY && len >= 1.0-FTINY)
108 <                len = 0.5 + 0.5*len;    /* first order approximation */
107 >        if (d <= 1.0+FTINY && d >= 1.0-FTINY)
108 >                len = 0.5 + 0.5*d;      /* first order approximation */
109          else
110 <                len = sqrt(len);
110 >                len = sqrt(d);
111  
112 <        v[0] /= len;
113 <        v[1] /= len;
114 <        v[2] /= len;
112 >        v[0] *= d = 1.0/len;
113 >        v[1] *= d;
114 >        v[2] *= d;
115  
116          return(len);
117   }
118  
119  
120 + void
121   spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
122   FVECT  vres, vorig, vnorm;
123   double  theta;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines