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

Comparing ray/src/common/image.c (file contents):
Revision 2.46 by greg, Fri Apr 27 05:00:29 2018 UTC vs.
Revision 2.52 by greg, Fri Feb 12 00:47:08 2021 UTC

# Line 15 | Line 15 | static const char      RCSid[] = "$Id$";
15   #include  "paths.h"
16   #include  "view.h"
17  
18
19 #define  FEQ(x,y)       (fabs((x)-(y)) <= FTINY)
20 #define  VEQ(v,w)       (FEQ((v)[0],(w)[0]) && FEQ((v)[1],(w)[1]) \
21                                && FEQ((v)[2],(w)[2]))
22
18   VIEW  stdview = STDVIEW;                /* default view parameters */
19  
20   static gethfunc gethview;
# Line 245 | Line 240 | FVECT  p
240                  break;
241          case VT_PER:                    /* perspective view */
242                  d = DOT(disp,v->vdir);
243 <                if ((v->vaft > FTINY) & (d > v->vaft))
243 >                if ((v->vaft > FTINY) & (d >= v->vaft))
244                          rflags |= VL_BEYOND;
245                  ip[2] = VLEN(disp);
246                  if (d < -FTINY) {       /* fold pyramid */
# Line 272 | Line 267 | FVECT  p
267                  d = DOT(disp,v->hvec);
268                  d2 = DOT(disp,v->vdir);
269                  ip[0] = 180.0/PI * atan2(d,d2) / v->horiz + 0.5 - v->hoff;
270 <                d = d*d + d2*d2;
271 <                if (d <= FTINY*FTINY)
270 >                d2 = d*d + d2*d2;
271 >                if (d2 <= FTINY*FTINY)
272                          return(VL_BAD); /* at pole */
273 <                if ((v->vaft > FTINY) & (d > v->vaft*v->vaft))
273 >                if ((v->vaft > FTINY) & (d2 >= v->vaft*v->vaft))
274                          rflags |= VL_BEYOND;
275 <                d = 1.0/sqrt(d);
275 >                d = 1.0/sqrt(d2);
276                  ip[1] = DOT(disp,v->vvec)*d/v->vn2 + 0.5 - v->voff;
277                  ip[2] = VLEN(disp);
278                  ip[2] *= (1.0 - v->vfore*d);
# Line 315 | Line 310 | FVECT  p
310          ip[0] = DOT(disp,v->hvec)/v->hn2 + 0.5 - v->hoff;
311          ip[1] = DOT(disp,v->vvec)/v->vn2 + 0.5 - v->voff;
312   gotall:                                 /* add appropriate return flags */
313 <        rflags |= VL_BEHIND*(ip[2] <= 0.0);
313 >        if (ip[2] <= 0.0)
314 >                rflags |= VL_BEHIND;
315 >        else if ((v->type != VT_PER) & (v->type != VT_CYL))
316 >                rflags |= VL_BEYOND*((v->vaft > FTINY) &
317 >                                        (ip[2] >= v->vaft - v->vfore));
318          rflags |= VL_OUTSIDE*((0.0 >= ip[0]) | (ip[0] >= 1.0) |
319                                  (0.0 >= ip[1]) | (ip[1] >= 1.0));
321        if ((v->vaft > FTINY) & !(rflags & (VL_BEHIND|VL_BEYOND)))
322                rflags |= VL_BEYOND*(ip[2] > v->vaft - v->vfore);
320          return(rflags);
321   }
322  
# Line 384 | Line 381 | int  ac,
381   char  *av[]
382   )
383   {
384 < #define check(c,l)      if ((av[0][c]&&av[0][c]!=' ') || \
384 > #define check(c,l)      if ((av[0][c]&&!isspace(av[0][c])) || \
385                          badarg(ac-1,av+1,l)) return(-1)
386  
387          if (ac <= 0 || av[0][0] != '-' || av[0][1] != 'v')
388                  return(-1);
389          switch (av[0][2]) {
390          case 't':                       /* type */
391 <                if (!av[0][3] || av[0][3]==' ')
391 >                if (!av[0][3] || isspace(av[0][3]))
392                          return(-1);
393                  check(4,"");
394                  v->type = av[0][3];
# Line 512 | Line 509 | VIEW  *vp
509                  sprintf(cp, " -vt%c", vp->type);
510                  cp += strlen(cp);
511          }
512 <        if (!VEQ(vp->vp,stdview.vp)) {
512 >        if (!VABSEQ(vp->vp,stdview.vp)) {
513                  sprintf(cp, " -vp %.6g %.6g %.6g",
514                                  vp->vp[0], vp->vp[1], vp->vp[2]);
515                  cp += strlen(cp);
516          }
517 <        if (!FEQ(vp->vdist,stdview.vdist) || !VEQ(vp->vdir,stdview.vdir)) {
517 >        if (!FABSEQ(vp->vdist,stdview.vdist) || !VABSEQ(vp->vdir,stdview.vdir)) {
518                  sprintf(cp, " -vd %.6g %.6g %.6g",
519                                  vp->vdir[0]*vp->vdist,
520                                  vp->vdir[1]*vp->vdist,
521                                  vp->vdir[2]*vp->vdist);
522                  cp += strlen(cp);
523          }
524 <        if (!VEQ(vp->vup,stdview.vup)) {
524 >        if (!VABSEQ(vp->vup,stdview.vup)) {
525                  sprintf(cp, " -vu %.6g %.6g %.6g",
526                                  vp->vup[0], vp->vup[1], vp->vup[2]);
527                  cp += strlen(cp);
528          }
529 <        if (!FEQ(vp->horiz,stdview.horiz)) {
529 >        if (!FABSEQ(vp->horiz,stdview.horiz)) {
530                  sprintf(cp, " -vh %.6g", vp->horiz);
531                  cp += strlen(cp);
532          }
533 <        if (!FEQ(vp->vert,stdview.vert)) {
533 >        if (!FABSEQ(vp->vert,stdview.vert)) {
534                  sprintf(cp, " -vv %.6g", vp->vert);
535                  cp += strlen(cp);
536          }
537 <        if (!FEQ(vp->vfore,stdview.vfore)) {
537 >        if (!FABSEQ(vp->vfore,stdview.vfore)) {
538                  sprintf(cp, " -vo %.6g", vp->vfore);
539                  cp += strlen(cp);
540          }
541 <        if (!FEQ(vp->vaft,stdview.vaft)) {
541 >        if (!FABSEQ(vp->vaft,stdview.vaft)) {
542                  sprintf(cp, " -va %.6g", vp->vaft);
543                  cp += strlen(cp);
544          }
545 <        if (!FEQ(vp->hoff,stdview.hoff)) {
545 >        if (!FABSEQ(vp->hoff,stdview.hoff)) {
546                  sprintf(cp, " -vs %.6g", vp->hoff);
547                  cp += strlen(cp);
548          }
549 <        if (!FEQ(vp->voff,stdview.voff)) {
549 >        if (!FABSEQ(vp->voff,stdview.voff)) {
550                  sprintf(cp, " -vl %.6g", vp->voff);
551                  cp += strlen(cp);
552          }
# Line 576 | Line 573 | char  *s
573          }
574                                          /* skip leading path */
575          cp = s;
576 <        while (*cp && *cp != ' ')
576 >        while (*cp && !isspace(*cp))
577                  cp++;
578          while (cp > s && !ISDIRSEP(cp[-1]))
579                  cp--;
# Line 628 | Line 625 | RESOLU  *rp
625          if (rp != NULL && !fgetsresolu(rp, fp))
626                  mvs.ok = 0;
627  
628 <        fclose(fp);
628 >        if (fp != stdin)
629 >                fclose(fp);
630  
631          return(mvs.ok);
632   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines