-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaffine.C
220 lines (187 loc) · 3.56 KB
/
affine.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* affine.c
*
* Draw de Rham curves by iteration of affine matrices
*
* Linas Vepstas may 2005, august 2006
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "brat.h"
typedef double affine[2][3];
affine d0;
affine d1;
affine result;
static inline void copy (affine r, affine a)
{
r[0][0] = a[0][0];
r[0][1] = a[0][1];
r[0][2] = a[0][2];
r[1][0] = a[1][0];
r[1][1] = a[1][1];
r[1][2] = a[1][2];
}
static inline void mult (affine r, affine a, affine b)
{
r[0][0] = a[0][0]*b[0][0] + a[0][1] * b[1][0];
r[0][1] = a[0][0]*b[0][1] + a[0][1] * b[1][1];
r[0][2] = a[0][0]*b[0][2] + a[0][1] * b[1][2] + a[0][2];
r[1][0] = a[1][0]*b[0][0] + a[1][1] * b[1][0];
r[1][1] = a[1][0]*b[0][1] + a[1][1] * b[1][1];
r[1][2] = a[1][0]*b[0][2] + a[1][1] * b[1][2] + a[1][2];
}
void fixpt (double val)
{
affine tmp;
int i = 0;
val *= (double) (1<<30);
unsigned int nt = (int) val;
if (nt & 0x1)
{
copy(result,d1);
}
else
{
copy(result,d0);
}
nt >>= 1;
for (i=1; i<30; i++)
{
if (nt & 0x1)
{
mult (tmp, d1, result);
copy(result,tmp);
}
else
{
mult (tmp, d0, result);
copy(result,tmp);
}
nt >>= 1;
}
#define MORE
#ifdef MORE
nt = rand();
for (i=1; i<30; i++)
{
if (nt & 0x1)
{
mult (tmp, d1, result);
copy(result,tmp);
}
else
{
mult (tmp, d0, result);
copy(result,tmp);
}
nt >>= 1;
}
#endif
}
/* Bounds checker, based on the idea of absolute convergence
* of the de Rham curve when parameters are bounded. Returns
* true if params allow for absolute convergence, else returns
* false.
*/
static int interior (double ax, double ay,
double d, double e, double f, double g)
{
int p=1;
double mo;
double re = 0.5*(ax+e);
double de = (ax-e)*(ax-e) + 4*ay*d;
if (de>=0.0) {
re += 0.5 *sqrt(de);
mo = re*re;
if (mo>1.0) p = 0;
re -= sqrt(de);
mo = re*re;
if (mo>1.0) p = 0;
} else {
mo = re*re - 0.25*de;
if (mo>1.0) p = 0;
}
re = 0.5*(1.0-ax+g);
de = (1.0-ax-g)*(1.0-ax-g) - 4*ay*f;
if (de>=0.0) {
re += 0.5 *sqrt(de);
mo = re*re;
if (mo>1.0) p = 0;
re -= sqrt(de);
mo = re*re;
if (mo>1.0) p = 0;
} else {
mo = re*re - 0.25*de;
if (mo>1.0) p = 0;
}
return p;
}
static double affine_iteration (double re_q, double im_q, int itermax, double param)
{
int p,q;
double ax, ay, d,e,f,g;
q = 23;
ax = 0.5;
ay = 1.0;
d = 0;
e = 0.6;
f = 0.18;
g = -0.5;
e = re_q;
f = im_q;
g = param;
d0[0][0] = ax;
d0[1][0] = ay;
d0[0][1] = d;
d0[1][1] = e;
d0[0][2] = 0.0;
d0[1][2] = 0.0;
d1[0][0] = 1.0-ax;
d1[1][0] = -ay;
d1[0][1] = f;
d1[1][1] = g;
d1[0][2] = ax;
d1[1][2] = ay;
q = itermax;
double dist = 0.0;
for (p=0; p<q; p++)
{
double val = (double) p / (double) q;
fixpt (val);
double x = result[0][2];
double y = result[1][2];
dist += sqrt (x*x+y*y);
}
dist /= itermax;
int i1 = interior (ax, ay, d,e,f,g);
int i2 = interior (ax, ay, d,e+4.0/600.0,f,g);
if (i1 && !i2) dist = 1e30;
if (!i1 && i2) dist = 1e30;
i1 = interior (ax, ay, d,e,f,g);
i2 = interior (ax, ay, d,e, f+4.0/600.0,g);
if (i1 && !i2) dist = 1e30;
if (!i1 && i2) dist = 1e30;
return dist;
}
#if UNUSED
static double affine_bound (double re_q, double im_q, int itermax, double param)
{
double ax, ay, d,e,f,g;
ax = 0.5;
ay = 1.0;
d = 0.0;
e = 0.6;
f = 0.18;
g = 0.5;
e = re_q;
f = im_q;
g = param;
double p = 1.0e30;
if (interior (ax, ay, d,e,f,g)) p = 0.0;
return p;
}
#endif
DECL_MAKE_HEIGHT(affine_iteration);
// DECL_MAKE_HEIGHT(affine_bound);
/* --------------------------- END OF LIFE ------------------------- */