ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/gen/genprism.c
(Generate patch)

Comparing ray/src/gen/genprism.c (file contents):
Revision 2.14 by greg, Sat Jun 7 05:09:45 2025 UTC vs.
Revision 2.15 by greg, Thu Aug 14 19:32:00 2025 UTC

# Line 35 | Line 35 | int  do_ends = 1;              /* include end caps */
35   int  iscomplete = 0;            /* polygon is already completed */
36   double  crad = 0.0;             /* radius for corners (sign from lvdir) */
37  
38 static double  compute_rounding(void);
38  
39 <
41 < static void
39 > void
40   readverts(char *fname)          /* read vertices from a file */
41   {
42          FILE  *fp;
43  
44 <        if (fname == NULL)
44 >        if (fname == NULL) {
45                  fp = stdin;
46 <        else if ((fp = fopen(fname, "r")) == NULL) {
46 >                fname = "<stdin>";
47 >        } else if ((fp = fopen(fname, "r")) == NULL) {
48                  fprintf(stderr, "%s: cannot open\n", fname);
49                  exit(1);
50          }
51          while (fscanf(fp, "%lf %lf", &vert[nverts][0], &vert[nverts][1]) == 2)
52 <                nverts++;
52 >                if (++nverts >= MAXVERT)
53 >                        break;
54 >
55 >        if (!feof(fp)) {
56 >                if (nverts < MAXVERT) {
57 >                        fprintf(stderr, "%s: warning - non-numerical data\n", fname);
58 >                } else {
59 >                        fprintf(stderr, "%s: too many vertices\n", fname);
60 >                        exit(1);
61 >                }
62 >        }
63          fclose(fp);
64   }
65  
66  
67 < static void
67 > void
68   side(int n0, int n1)                    /* print single side */
69   {
70          printf("\n%s polygon %s.%d\n", pmtype, pname, n0+1);
# Line 71 | Line 80 | side(int n0, int n1)                   /* print single side */
80   }
81  
82  
83 < static void
83 > void
84   rside(int n0, int n1)                   /* print side with rounded edge */
85   {
86          double  s, c, t[3];
# Line 121 | Line 130 | rside(int n0, int n1)                  /* print side with rounded edg
130   }
131  
132  
133 < static double
134 < compute_rounding(void)          /* compute vectors for rounding operations */
133 > double
134 > compute_rounding()              /* compute vectors for rounding operations */
135   {
136          int  i;
137          double  *v0, *v1;
# Line 165 | Line 174 | compute_rounding(void)         /* compute vectors for roundin
174   }
175  
176  
177 < static void
178 < printends(void)                 /* print ends of prism */
177 > void
178 > printends()                     /* print ends of prism */
179   {
180          int  i;
181                                                  /* bottom face */
# Line 184 | Line 193 | printends(void)                        /* print ends of prism */
193   }
194  
195  
196 < static void
197 < printrends(void)                /* print ends of prism with rounding */
196 > void
197 > printrends()            /* print ends of prism with rounding */
198   {
199          int  i;
200          double  c0[3], c1[3], cl[3];
# Line 264 | Line 273 | printrends(void)               /* print ends of prism with rounding
273   }
274  
275  
276 < static void
276 > void
277   printsides(int round)           /* print prism sides */
278   {
279          int  i;
# Line 301 | Line 310 | main(int argc, char **argv)
310                  nverts = atoi(argv[3]);
311                  if (argc-3 < 2*nverts)
312                          goto userr;
313 +                if (nverts > MAXVERT) {
314 +                        fprintf(stderr, "%s: too many vertices\n", argv[0]);
315 +                        return(1);
316 +                }
317                  for (an = 0; an < nverts; an++) {
318                          vert[an][0] = atof(argv[2*an+4]);
319                          vert[an][1] = atof(argv[2*an+5]);
# Line 312 | Line 325 | main(int argc, char **argv)
325          }
326          if (nverts < 3) {
327                  fprintf(stderr, "%s: not enough vertices\n", argv[0]);
328 <                exit(1);
328 >                return(1);
329          }
330  
331          for ( ; an < argc; an++) {
# Line 331 | Line 344 | main(int argc, char **argv)
344                                  fprintf(stderr,
345                                          "%s: illegal extrusion vector\n",
346                                                  argv[0]);
347 <                                exit(1);
347 >                                return(1);
348                          }
349                          llen = sqrt(lvect[0]*lvect[0] + lvect[1]*lvect[1] +
350                                          lvect[2]*lvect[2]);
# Line 353 | Line 366 | main(int argc, char **argv)
366                  if (crad > lvdir*lvect[2]) {
367                          fprintf(stderr, "%s: rounding greater than height\n",
368                                          argv[0]);
369 <                        exit(1);
369 >                        return(1);
370                  }
371                  crad *= lvdir;          /* simplifies formulas */
372                  compute_rounding();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines