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

Comparing ray/src/common/face.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:34:31 1989 UTC vs.
Revision 2.4 by greg, Thu Aug 24 20:54:54 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1995 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 27 | Line 27 | static char SCCSid[] = "$SunId$ LBL";
27   *  The last vertex is automatically connected to the first.
28   */
29  
30 + #ifdef  SMLFLT
31 + #define  VERTEPS        1e-2            /* allowed vertex error */
32 + #else
33   #define  VERTEPS        1e-4            /* allowed vertex error */
34 + #endif
35  
36  
37   FACE *
38   getface(o)                      /* get arguments for a face */
39   OBJREC  *o;
40   {
37        double  fabs();
41          double  d1;
42          int  badvert;
43          FVECT  v1, v2, v3;
# Line 51 | Line 54 | OBJREC  *o;
54          if (o->oargs.nfargs < 9 || o->oargs.nfargs % 3)
55                  objerror(o, USER, "bad # arguments");
56  
57 +        o->os = (char *)f;                      /* save face */
58 +
59          f->va = o->oargs.farg;
60          f->nv = o->oargs.nfargs / 3;
61 +                                                /* check for last==first */
62 +        if (dist2(VERTEX(f,0),VERTEX(f,f->nv-1)) <= FTINY*FTINY)
63 +                f->nv--;
64                                                  /* compute area and normal */
65          f->norm[0] = f->norm[1] = f->norm[2] = 0.0;
66          v1[0] = v1[1] = v1[2] = 0.0;
# Line 69 | Line 77 | OBJREC  *o;
77          f->area = normalize(f->norm);
78          if (f->area == 0.0) {
79                  objerror(o, WARNING, "zero area");      /* used to be fatal */
80 <                f->const = 0.0;
80 >                f->offset = 0.0;
81                  f->ax = 0;
82                  return(f);
83          }
84          f->area *= 0.5;
85 <                                                /* compute constant */
85 >                                                /* compute offset */
86          badvert = 0;
87 <        f->const = DOT(f->norm, VERTEX(f,0));
87 >        f->offset = DOT(f->norm, VERTEX(f,0));
88          for (i = 1; i < f->nv; i++) {
89                  d1 = DOT(f->norm, VERTEX(f,i));
90 <                badvert += fabs(d1 - f->const/i) > VERTEPS;
91 <                f->const += d1;
90 >                badvert += fabs(d1 - f->offset/i) > VERTEPS;
91 >                f->offset += d1;
92          }
93 <        f->const /= f->nv;
93 >        f->offset /= (double)f->nv;
94          if (badvert)
95                  objerror(o, WARNING, "non-planar vertex");
96                                                  /* find axis */
# Line 90 | Line 98 | OBJREC  *o;
98          if (fabs(f->norm[2]) > fabs(f->norm[f->ax]))
99                  f->ax = 2;
100  
93        (FACE *)o->os = f;                      /* save face */
101          return(f);
102   }
103  
# Line 98 | Line 105 | OBJREC  *o;
105   freeface(o)                     /* free memory associated with face */
106   OBJREC  *o;
107   {
108 +        if (o->os == NULL)
109 +                return;
110          free(o->os);
111          o->os = NULL;
112   }
# Line 110 | Line 119 | FACE  *f;
119          int  ncross, n;
120          double  x, y;
121          register int  xi, yi;
122 <        register double  *p0, *p1;
122 >        register FLOAT  *p0, *p1;
123  
124          xi = (f->ax+1)%3;
125          yi = (f->ax+2)%3;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines