ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/peano.c
Revision: 1.1
Committed: Mon Aug 12 13:06:13 1991 UTC (32 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1991 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Generate an N-dimensional Peano space-filling curve
9     * on the interval [0,1).
10     *
11     * 12 Aug 91 Greg Ward
12     */
13    
14     extern double floor();
15    
16    
17     static double
18     peanoC(n, t, e) /* compute Peano coordinate */
19     int n;
20     double t, e;
21     {
22     register int i;
23     double d;
24    
25     if (e >= 1./3.)
26     return(t);
27     d = 0.;
28     while (t-d >= 1./3.)
29     d += 1./3.;
30     i = n;
31     while (--i > 0)
32     t *= 3.;
33     t = 3.*(t - floor(t));
34     i = 0;
35     while (t >= 1.) {
36     t -= 1.;
37     i ^= 1;
38     }
39     t = peanoC(n, t, 3.*e);
40     if (i)
41     t = 1. - t;
42     return(d + t/3.);
43     }
44    
45    
46     peano(p, n, t, e) /* compute Peano point */
47     double p[];
48     int n;
49     double t, e;
50     {
51     register int i;
52     int neg = 0;
53    
54     i = n;
55     while (i-- > 0) {
56     p[i] = peanoC(n, t, e);
57     if (neg)
58     p[i] = 1. - p[i];
59     t *= 3.;
60     while (t >= 1.) {
61     t -= 1.;
62     neg ^= 1;
63     }
64     }
65     }