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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
/*****
* runpath3.in
*
* Runtime functions for path3 operations.
*
*****/
pair => primPair()
triple => primTriple()
path3 => primPath3()
boolarray* => booleanArray()
realarray* => realArray()
realarray2* => realArray2()
triplearray* => tripleArray()
triplearray2* => tripleArray2()
#include "path3.h"
#include "array.h"
#include "drawsurface.h"
using namespace camp;
using namespace vm;
typedef array boolarray;
typedef array realarray;
typedef array realarray2;
typedef array triplearray;
typedef array triplearray2;
using types::booleanArray;
using types::realArray;
using types::realArray2;
using types::tripleArray;
using types::tripleArray2;
// Autogenerated routines:
path3 path3(triplearray *pre, triplearray *point, triplearray *post,
boolarray *straight, bool cyclic)
{
size_t n=checkArrays(pre,point);
checkEqual(n,checkArray(post));
checkEqual(n,checkArray(straight));
mem::vector<solvedKnot3> nodes(n);
for(size_t i=0; i < n; ++i) {
nodes[i].pre=read<triple>(pre,i);
nodes[i].point=read<triple>(point,i);
nodes[i].post=read<triple>(post,i);
nodes[i].straight=read<bool>(straight,i);
}
return path3(nodes,(Int) n,cyclic);
}
path3 :nullPath3()
{
return nullpath3;
}
bool ==(path3 a, path3 b)
{
return a == b;
}
bool !=(path3 a, path3 b)
{
return !(a == b);
}
triple point(path3 p, Int t)
{
return p.point((Int) t);
}
triple point(path3 p, real t)
{
return p.point(t);
}
triple precontrol(path3 p, Int t)
{
return p.precontrol((Int) t);
}
triple precontrol(path3 p, real t)
{
return p.precontrol(t);
}
triple postcontrol(path3 p, Int t)
{
return p.postcontrol((Int) t);
}
triple postcontrol(path3 p, real t)
{
return p.postcontrol(t);
}
triple dir(path3 p, Int t, Int sign=0, bool normalize=true)
{
return p.dir(t,sign,normalize);
}
triple dir(path3 p, real t, bool normalize=true)
{
return p.dir(t,normalize);
}
triple accel(path3 p, Int t, Int sign=0)
{
return p.accel(t,sign);
}
triple accel(path3 p, real t)
{
return p.accel(t);
}
real radius(path3 p, real t)
{
triple v=p.dir(t,false);
triple a=p.accel(t);
real d=dot(a,v);
real v2=v.abs2();
real a2=a.abs2();
real denom=v2*a2-d*d;
real r=v2*sqrt(v2);
return denom > 0 ? r/sqrt(denom) : 0.0;
}
real radius(triple z0, triple c0, triple c1, triple z1, real t)
{
triple v=(3.0*(z1-z0)+9.0*(c0-c1))*t*t+(6.0*(z0+c1)-12.0*c0)*t+3.0*(c0-z0);
triple a=6.0*(z1-z0+3.0*(c0-c1))*t+6.0*(z0+c1)-12.0*c0;
real d=dot(a,v);
real v2=v.abs2();
real a2=a.abs2();
real denom=v2*a2-d*d;
real r=v2*sqrt(v2);
return denom > 0 ? r/sqrt(denom) : 0.0;
}
path3 reverse(path3 p)
{
return p.reverse();
}
path3 subpath(path3 p, Int a, Int b)
{
return p.subpath((Int) a, (Int) b);
}
path3 subpath(path3 p, real a, real b)
{
return p.subpath(a,b);
}
Int length(path3 p)
{
return p.length();
}
bool cyclic(path3 p)
{
return p.cyclic();
}
bool straight(path3 p, Int t)
{
return p.straight(t);
}
path3 unstraighten(path3 p)
{
return p.unstraighten();
}
// Return the maximum perpendicular deviation of segment i of path3 g
// from a straight line.
real straightness(path3 p, Int t)
{
if(p.straight(t)) return 0;
triple z0=p.point(t);
triple u=unit(p.point(t+1)-z0);
return ::max(length(perp(p.postcontrol(t)-z0,u)),
length(perp(p.precontrol(t+1)-z0,u)));
}
// Return the maximum perpendicular deviation of z0..controls c0 and c1..z1
// from a straight line.
real straightness(triple z0, triple c0, triple c1, triple z1)
{
triple u=unit(z1-z0);
return ::max(length(perp(c0-z0,u)),length(perp(c1-z0,u)));
}
bool piecewisestraight(path3 p)
{
return p.piecewisestraight();
}
real arclength(path3 p)
{
return p.arclength();
}
real arctime(path3 p, real dval)
{
return p.arctime(dval);
}
realarray* intersect(path3 p, path3 q, real fuzz=-1)
{
bool exact=fuzz <= 0.0;
if(fuzz < 0)
fuzz=BigFuzz*::max(::max(length(p.max()),length(p.min())),
::max(length(q.max()),length(q.min())));
std::vector<real> S,T;
real s,t;
if(intersections(s,t,S,T,p,q,fuzz,true,exact)) {
array *V=new array(2);
(*V)[0]=s;
(*V)[1]=t;
return V;
} else
return new array(0);
}
realarray2* intersections(path3 p, path3 q, real fuzz=-1)
{
bool exact=fuzz <= 0.0;
if(fuzz < 0)
fuzz=BigFuzz*::max(::max(length(p.max()),length(p.min())),
::max(length(q.max()),length(q.min())));
bool single=!exact;
real s,t;
std::vector<real> S,T;
bool found=intersections(s,t,S,T,p,q,fuzz,single,exact);
if(!found) return new array(0);
array *V;
if(single) {
V=new array(1);
array *Vi=new array(2);
(*V)[0]=Vi;
(*Vi)[0]=s;
(*Vi)[1]=t;
} else {
size_t n=S.size();
V=new array(n);
for(size_t i=0; i < n; ++i) {
array *Vi=new array(2);
(*V)[i]=Vi;
(*Vi)[0]=S[i];
(*Vi)[1]=T[i];
}
}
stable_sort(V->begin(),V->end(),run::compare2<real>());
return V;
}
realarray2* intersections(path3 p, triplearray2 *P, real fuzz=-1)
{
triple *A=copyTripleArray2C(P,true,4);
if(fuzz <= 0) fuzz=BigFuzz*::max(::max(length(p.max()),length(p.min())),
norm(A,16));
std::vector<real> T,U,V;
intersections(T,U,V,p,A,fuzz);
delete[] A;
size_t n=T.size();
array *W=new array(n);
for(size_t i=0; i < n; ++i) {
array *Wi=new array(3);
(*W)[i]=Wi;
(*Wi)[0]=T[i];
(*Wi)[1]=U[i];
(*Wi)[2]=V[i];
}
return W; // Sorting will done in asy.
}
Int size(path3 p)
{
return p.size();
}
path3 &(path3 p, path3 q)
{
return camp::concat(p,q);
}
triple min(path3 p)
{
return p.min();
}
triple max(path3 p)
{
return p.max();
}
realarray *mintimes(path3 p)
{
array *V=new array(3);
triple v=p.mintimes();
(*V)[0]=v.getx();
(*V)[1]=v.gety();
(*V)[2]=v.getz();
return V;
}
realarray *maxtimes(path3 p)
{
array *V=new array(3);
triple v=p.maxtimes();
(*V)[0]=v.getx();
(*V)[1]=v.gety();
(*V)[2]=v.getz();
return V;
}
path3 Operator *(realarray2 *t, path3 g)
{
return transformed(*t,g);
}
pair minratio(path3 g)
{
return g.ratio(::min);
}
pair maxratio(path3 g)
{
return g.ratio(::max);
}
|