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

Comparing ray/src/rt/func.c (file contents):
Revision 2.27 by greg, Wed Jun 27 16:29:26 2012 UTC vs.
Revision 2.32 by greg, Wed Apr 27 21:11:32 2016 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11   #include  "paths.h"
12   #include  "otypes.h"
13   #include  "func.h"
14 + #include <ctype.h>
15  
16  
17   #define  INITFILE       "rayinit.cal"
# Line 36 | Line 37 | static double  l_erf(char *), l_erfc(char *), l_arg(ch
37  
38  
39   void
40 < initfunc()      /* initialize function evaluation */
40 > initfunc(void)  /* initialize function evaluation */
41   {
42          if (!rayinitcal[0])     /* already done? */
43                  return;
# Line 62 | Line 63 | initfunc()     /* initialize function evaluation */
63   }
64  
65  
66 + /* Set parameters for current evaluation */
67 + void
68 + set_eparams(char *prms)
69 + {
70 +        static char     *last_params;
71 +        static int      lplen = 0;
72 +        int             len;
73 +        char            vname[RMAXWORD];
74 +        double          value;
75 +        char            *cpd;
76 +                                        /* check if already set */
77 +        if (prms == NULL || !*prms)
78 +                return;
79 +        if (lplen && !strcmp(prms, last_params))
80 +                return;
81 +        len = strlen(prms);             /* record new settings */
82 +        if ((lplen != 0) & (lplen <= len)) {
83 +                free(last_params);
84 +                lplen = 0;
85 +        }
86 +        if (!lplen) {
87 +                lplen = len + 100;
88 +                last_params = (char *)malloc(lplen);
89 +                if (last_params == NULL)
90 +                        error(SYSTEM, "out of memory in set_eparams()");
91 +        }
92 +        strcpy(last_params, prms);
93 +                                        /* assign each variable */
94 +        while (*prms) {
95 +                if (isspace(*prms)) {
96 +                        ++prms; continue;
97 +                }
98 +                if (!isalpha(*prms))
99 +                        goto bad_params;
100 +                cpd = vname;
101 +                while (*prms && (*prms != '=') & !isspace(*prms)) {
102 +                        if (!isid(*prms) | (cpd-vname >= RMAXWORD-1))
103 +                                goto bad_params;
104 +                        *cpd++ = *prms++;
105 +                }
106 +                if (cpd == vname)
107 +                        goto bad_params;
108 +                *cpd = '\0';
109 +                while (isspace(*prms)) prms++;
110 +                if (*prms++ != '=')
111 +                        goto bad_params;
112 +                value = atof(prms);
113 +                if ((prms = fskip(prms)) == NULL)
114 +                        goto bad_params;
115 +                while (isspace(*prms)) prms++;
116 +                prms += (*prms == ',') | (*prms == ';');
117 +                varset(vname, '=', value);
118 +        }
119 +        return;
120 + bad_params:
121 +        sprintf(errmsg, "bad parameter list '%s'", last_params);
122 +        error(USER, errmsg);
123 + }
124 +
125 +
126   MFUNC *
127   getfunc(        /* get function for this modifier */
128          OBJREC  *m,
# Line 239 | Line 300 | loadfunc(                      /* load definition file */
300  
301          if ((ffname = getpath(fname, getrlibpath(), R_OK)) == NULL) {
302                  sprintf(errmsg, "cannot find function file \"%s\"", fname);
303 <                error(USER, errmsg);
303 >                error(SYSTEM, errmsg);
304          }
305          fcompile(ffname);
306   }
# Line 251 | Line 312 | l_arg(char *nm)                        /* return nth real argument */
312          int  n;
313  
314          if (fobj == NULL)
315 <                error(USER, "arg(n) called without a context");
315 >                error(INTERNAL, "arg(n) called without a modifier context");
316  
317          n = argument(1) + .5;           /* round to integer */
318  
# Line 305 | Line 366 | chanvalue(                     /* return channel n to calcomp */
366                                  fray->ron[2]*funcxf.xfm[2][n-3] )
367                           / funcxf.sca );
368  
369 <        if (n <= 8)                     /* intersection */
369 >        if (n <= 8) {                   /* intersection point */
370 >                if (fray->rot >= FHUGE)
371 >                        return(0.0);    /* XXX should be runtime error? */
372  
373                  return( fray->rop[0]*funcxf.xfm[0][n-6] +
374                                  fray->rop[1]*funcxf.xfm[1][n-6] +
375                                  fray->rop[2]*funcxf.xfm[2][n-6] +
376                                               funcxf.xfm[3][n-6] );
377 +        }
378  
379          if (n == 9)                     /* total distance */
380                  return(raydist(fray,PRIMARY) * funcxf.sca);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines