-
Notifications
You must be signed in to change notification settings - Fork 6
/
h3du_min.js
271 lines (271 loc) · 135 KB
/
h3du_min.js
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
/*
Unlicense
*/
(function(D,y){"object"===typeof exports&&"undefined"!==typeof module?y(exports):"function"===typeof define&&define.amd?define(["exports"],y):(D="undefined"!==typeof globalThis?globalThis:D||self,y(D.H3DU={}))})(this,function(D){function y(a,b){this.curve=a;this.curveParam=b}function da(a,b,c,d,e){var f=.5*(c-b),h=b+f,g=0,k=0,m;for(m=0;m<ba.length;m+=3){var p=ba[m+2],l=ba[m+1],q=ba[m],t=a(f*q+h);g+=p*t;k+=l*t;0<q&&(t=a(-f*q+h),g+=p*t,k+=l*t)}g=g*f*d;k=k*f*d;return 1E-6>Math.abs(g-k)?k+(k-g)/8191:
10<=e?k+(k-g)/8191:da(a,b,h,d,e+1)+da(a,h,c,d,e+1)}function ha(a){return 1===a.length?{x:a[0]}:2===a.length?{x:a[0],y:a[1]}:3===a.length?{x:a[0],y:a[1],z:a[2]}:4===a.length?{x:a[0],y:a[1],z:a[2],w:a[3]}:{}}function w(a,b,c){if(0>=a.length)throw Error();if(!b)throw Error("no knots");this.bits=c||0;this.controlPoints=a;a=b.length-this.controlPoints.length;if(1>a)throw Error("degree 0 or less");if(a>this.controlPoints.length)throw Error();w._checkKnots(b,a-1);c=this.controlPoints[0].length;var d=1;0!==
(this.bits&w.DIVIDE_BIT)&&(d=2);if(c<d)throw Error();this.fastBezier=!1;if(a===this.controlPoints.length&&4>=a){this.fastBezier=!0;for(c=0;c<a;c++)if(0!==b[c]){this.fastBezier=!1;break}for(c=a;this.fastBezier&&c<b.length;c++)if(1!==b[c]){this.fastBezier=!1;break}}this.knots=b;this.buffer=[]}function L(a,b,c,d){this.bits=d||0;d=a.length;if(0>=d)throw Error();var e=a[0].length;if(0>=e)throw Error();var f=a[0][0].length,h=1;0!==(this.bits&w.DIVIDE_BIT)&&(h=2);if(f<h)throw Error();if(!b||!c)throw Error();
this.degreeU=b.length-e-1;this.degreeV=c.length-d-1;this.vcplen=d;this.ucplen=e;if(1>this.degreeU||this.degreeU+1>e)throw Error();if(1>this.degreeV||this.degreeV+1>d)throw Error();w._checkKnots(b,this.degreeU);w._checkKnots(c,this.degreeV);this.knotsU=b;this.knotsV=c;this.bufferU=[];this.bufferV=[];this.controlPoints=a}function R(a,b,c,d){this.x1=a;this.x2=c;this.y1=b;this.y2=d}function W(a,b,c,d,e,f,h,g,k,m,p){this.x1=a;this.x2=c;this.y1=b;this.y2=d;this.rx=e;this.ry=f;a=Math.cos(h);h=0<=h&&6.283185307179586>
h?3.141592653589793>=h?Math.sqrt(1-a*a):-Math.sqrt(1-a*a):Math.sin(h);this.cr=a;this.sr=h;this.cx=g;this.cy=k;this.theta=m;this.delta=p}function V(a,b,c){var d=(a[0]-c[0])*(b[1]-c[1]);b=(a[1]-c[1])*(b[0]-c[0]);a=d-b;if(0<d){if(0>=b)return 0>a?-1:0===a?0:1;d+=b}else if(0>d){if(0<=b)return 0>a?-1:0===a?0:1;d=-d-b}else return 0>a?-1:0===a?0:1;d*=3.3306690738754716E-16;return a>=d||-a>=d?0>a?-1:0===a?0:1:0}function ea(){this.openPolygons=new ca;this.closedPolygons=new ca;this.clear=function(){this.openPolygons.clear();
this.closedPolygons.clear()};this.size=function(){return this.closedPolygons.size()}}function ia(a,b,c,d,e){if(!a.BufferGeometry)return null;if(!c){c=[];for(var f=0;f<b.length/6|0;f++)c[f]=f}f=new a.BufferGeometry;var h=new a.InterleavedBuffer(new Float32Array(b),6);b=new a.InterleavedBufferAttribute(h,3,0);f.setAttribute(d,b);b=new a.InterleavedBufferAttribute(h,3,3);f.setAttribute(e,b);f.index=new a.BufferAttribute(new Uint32Array(c),1);return f}function X(a,b,c,d){var e=[],f;for(f=0;f<d-1;f++){var h;
for(h=0;h<c-1;h++){var g=f*c+h,k=g+c,m=g+1,p=k+1;e.push(g,k,m);e.push(m,k,p)}}return A.fromPositionsNormalsUV(a,b,e)}function ub(a,b){var c=new a.Matrix4;c.set(b[0],b[4],b[8],b[12],b[1],b[5],b[9],b[13],b[2],b[6],b[10],b[14],b[3],b[7],b[11],b[15]);return c}var ja=function(a,b,c){function d(a,b,c){return function(d){a&&a(d);b.successes[c]=d;return!0}}function e(a,b,c){return function(d){a&&a(d);b.failures[c]=d;return!0}}if(!a||0===a.length)return Promise.resolve({successes:[],failures:[],results:[]});
var f={successes:[],failures:[],results:[]},h=[],g;for(g=0;g<a.length;g++){var k=g;h.push(a[g].then(d(b,f,k),e(c,f,k)))}return Promise.all(h).then(function(a){var b;for(b=0;b<f.successes.length;b++)"undefined"===typeof f.successes[b]&&(f.successes.splice(b,1),--b);for(b=0;b<f.failures.length;b++)"undefined"===typeof f.failures[b]&&(f.failures.splice(b,1),--b);f.results=a;return Promise.resolve(f)})},ka=function(){throw Error();};(function(a){a.skipWhite=function(a,c,d){for(;c<d;){var b=a.charCodeAt(c);
if(32===b||13===b||12===b||9===b||10===b)++c;else break}return c};a.parseComma=function(b,c,d){var e=c;c=a.skipWhite(b,c,d);return c<d&&44===b.charCodeAt(c)?a.skipWhite(b,c+1,d):e};a.parseEndparen=function(b,c,d){var e=c;c=a.skipWhite(b,c,d);return c<d&&41===b.charCodeAt(c)?c+1:e};a.hsl=function(b,c,d,e){var f,h=c;if((f=a.parseHue(b,c,d,e,0))===c)return h;c=f;if((f=a.sepPct(b,c,d,e,1))===c)return h;c=f;if((f=a.sepPct(b,c,d,e,2))===c)return h;c=f;f=a.parseEndparen(b,c,d);if(f===c)return h;c=f;b=a.hlsToRgb(e[0],
e[2],e[1]);e[0]=b[0];e[1]=b[1];e[2]=b[2];e[3]=255;return c};a.pct=function(b,c,d,e,f){var h=a.parseNumber(b,c,d);if(h!==c){if(h>=d||37!==b.charAt(h))return c;e[f]=255*a.stringToPercent(b,c,h)/100;return h+1}return h};a.parseByte=function(b,c,d,e,f){d=a.parseInteger(b,c,d,!0);d!==c&&(e[f]=a.stringToByte(b,c,d));return d};a.parseHue=function(b,c,d,e,f){var h=c;c=a.skipWhite(b,c,d);d=a.parseNumber(b,c,d);return d!==c?(e[f]=a.stringToHue(b,c,d),d):h};a.sepByte=function(b,c,d,e,f){var h=a.parseComma(b,
c,d);return h!==c?a.parseByte(b,h,d,e,f):h};a.sepPct=function(b,c,d,e,f){var h=a.parseComma(b,c,d);return h!==c?a.pct(b,h,d,e,f):h};a.sepAlpha=function(b,c,d,e,f){var h=a.parseComma(b,c,d);h!==c&&(c=h,h=a.parseNumber(b,c,d),h!==c&&(e[f]=a.stringToAlpha(b,c,h)));return h};a.hsla=function(b,c,d,e){var f,h=c;if((f=a.parseHue(b,c,d,e,0))===c)return h;c=f;if((f=a.sepPct(b,c,d,e,1))===c)return h;c=f;if((f=a.sepPct(b,c,d,e,2))===c)return h;c=f;if((f=a.sepAlpha(b,c,d,e,3))===c)return h;c=f;f=a.hlsToRgb(e[0],
e[2],e[1]);e[0]=f[0];e[1]=f[1];e[2]=f[2];f=a.parseEndparen(b,c,d);return f===c?h:f};a.rgba=function(b,c,d,e){var f=c,h,g=c=a.skipWhite(b,c,d),k=!0;(h=a.pct(b,c,d,e,0))===c?k=!1:c=h;k&&(h=a.sepPct(b,c,d,e,1))===c?k=!1:c=h;k&&(h=a.sepPct(b,c,d,e,2))===c?k=!1:c=h;k&&(h=a.sepAlpha(b,c,d,e,3))===c?k=!1:c=h;k||(c=g,k=!0,(h=a.parseByte(b,c,d,e,0))===c?k=!1:c=h,k&&(h=a.sepByte(b,c,d,e,1))===c?k=!1:c=h,k&&(h=a.sepByte(b,c,d,e,2))===c?k=!1:c=h,k&&(h=a.sepAlpha(b,c,d,e,3))===c?k=!1:c=h);if(!k)return f;h=a.parseEndparen(b,
c,d);return h===c?f:h};a.rgb=function(b,c,d,e){var f,h=c,g=c=a.skipWhite(b,c,d),k=!0;(f=a.pct(b,c,d,e,0))===c?k=!1:c=f;k&&(f=a.sepPct(b,c,d,e,1))===c?k=!1:c=f;k&&(f=a.sepPct(b,c,d,e,2))===c?k=!1:c=f;k||(c=g,k=!0,(f=a.parseByte(b,c,d,e,0))===c?k=!1:c=f,k&&(f=a.sepByte(b,c,d,e,1))===c?k=!1:c=f,k&&(f=a.sepByte(b,c,d,e,2))===c?k=!1:c=f);if(!k)return h;e[3]=255;f=a.parseEndparen(b,c,d);return f===c?h:f};a.stringToNumber=function(a,c,d){a=a.substring(c,c+(d-c));return parseFloat(a)};a.stringToPercent=function(b,
c,d){b=a.stringToNumber(b,c,d);return Number.isNaN(b)?-1:0>b?0:100<b?100:b};a.stringToAlpha=function(b,c,d){b=a.stringToNumber(b,c,d);return 0>b?0:1<b?255:255*b};a.stringToHue=function(b,c,d){b=a.stringToNumber(b,c,d);return Number.isNaN(b)||b===Number.POSITIVE_INFINITY||b===Number.NEGATIVE_INFINITY?0:(b%360+360)%360};a.stringToByte=function(b,c,d){b=a.stringToNumber(b,c,d);return 0>b?0:255<b?255:b};a.parseInteger=function(a,c,d,e){var b=!1,h=c;for(e&&c<d&&(43===a.charCodeAt(c)||45===a.charCodeAt(c))&&
++c;c<d&&48<=a.charCodeAt(c)&&57>=a.charCodeAt(c);)++c,b=!0;return b?c:h};a.parseNumber=function(b,c,d){var e=c,f,h=0;if((f=a.parseInteger(b,c,d,!0))!==e)return c=f,c<d&&46===b.charCodeAt(c)?(++c,(f=a.parseInteger(b,c,d,!1))!==c?c<d&&(69===b.charCodeAt(c)||101===b.charCodeAt(c))&&(h=a.parseInteger(b,c+1,d,!0))!==c+1?h:f:c-1):c;c<d&&(43===b.charCodeAt(c)||45===b.charCodeAt(c))&&++c;return c<d&&46===b.charCodeAt(c)&&(++c,(f=a.parseInteger(b,c,d,!1))!==c)?c<d&&(69===b.charCodeAt(c)||101===b.charCodeAt(c))&&
(h=a.parseInteger(b,c+1,d,!0))!==c+1?h:f:e};a.hlsToRgb=a.HlsToRgb=function(a,c,d){c=0>c?0:255<c?255:c;d=0>d?0:255<d?255:d;if(0===d)return[c,c,c];d=127.5>=c?c*(255+d)/255:c+d-c*d/255;var b=2*c-d;if(0>a||360<=a)a=(a%360+360)%360;var f=a+120;360<=f&&(f-=360);c=60>f?b+(d-b)*f/60:180>f?d:240>f?b+(d-b)*(240-f)/60:b;f=a;var h=60>f?b+(d-b)*f/60:180>f?d:240>f?b+(d-b)*(240-f)/60:b;f=a-120;0>f&&(f+=360);a=60>f?b+(d-b)*f/60:180>f?d:240>f?b+(d-b)*(240-f)/60:b;return[0>c?0:255<c?255:c,0>h?0:255<h?255:h,0>a?0:255<
a?255:a]};a.dehexchar=function(a){return 48<=a&&57>=a?a-48:65<=a&&70>=a?a+10-65:97<=a&&102>=a?a+10-97:-1};a.rgbHex=function(b,c,d){if("undefined"===typeof b||null===b||0===b.length)return!1;var e=b.length,f=[0,0,0,0,0,0,0,0],h=0,g=0;if("#"===b.charAt(0))--e,++h;else if(d)return!1;if(3!==e&&4!==e&&6!==e&&8!==e)return!1;for(d=h;d<b.length;++d){h=a.dehexchar(b.charCodeAt(d));if(0>h)return!1;f[g++]=h}c[3]=4===e?f[3]|f[3]<<4:8===e?f[7]|f[6]<<4:255;3===e||4===e?(c[0]=f[0]|f[0]<<4,c[1]=f[1]|f[1]<<4,c[2]=
f[2]|f[2]<<4):6<=e&&(c[0]=f[1]|f[0]<<4,c[1]=f[3]|f[2]<<4,c[2]=f[5]|f[4]<<4);return!0};a.colorToRgba=a.colorToRgba=function(b){if("undefined"===typeof b||null===b||0===b.length)return null;for(var c=0,d=b.length;c<b.length;)if(32===b.charAt(c)||10===b.charAt(c)||9===b.charAt(c)||12===b.charAt(c)||13===b.charAt(c))c++;else break;for(;0<d;)if(32===b.charAt(d-1)||10===b.charAt(d-1)||9===b.charAt(d-1)||12===b.charAt(d-1)||13===b.charAt(d-1))d--;else break;b=b.substring(c,d).toLowerCase();if("transparent"===
b)return[0,0,0,0];if("undefined"===typeof b||null===b||0===b.length)return null;c=[0,0,0,0];if("#"===b.charAt(0)&&a.rgbHex(b,c,!0))return c;if(4<b.length&&"rgb("===b.substring(0,4))return a.rgb(b,4,b.length,c)===b.length?c:null;if(5<b.length&&"rgba("===b.substring(0,5))return a.rgba(b,5,b.length,c)===b.length?c:null;if(4<b.length&&"hsl("===b.substring(0,4))return a.hsl(b,4,b.length,c)===b.length?c:null;if(5<b.length&&"hsla("===b.substring(0,5))return a.hsla(b,5,b.length,c)===b.length?c:null;d=a.colorToRgbaSetUpNamedColors();
return"undefined"!==typeof d[b]&&null!==d[b]?(a.rgbHex(d[b],c,!1),c):null};a.namedColorMap=a.namedColorMap=null;a.nc="aliceblue f0f8ff antiquewhite faebd7 aqua 00ffff aquamarine 7fffd4 azure f0ffff beige f5f5dc bisque ffe4c4 black 000000 blanchedalmond ffebcd blue 0000ff blueviolet 8a2be2 brown a52a2a burlywood deb887 cadetblue 5f9ea0 chartreuse 7fff00 chocolate d2691e coral ff7f50 cornflowerblue 6495ed cornsilk fff8dc crimson dc143c cyan 00ffff darkblue 00008b darkcyan 008b8b darkgoldenrod b8860b darkgray a9a9a9 darkgreen 006400 darkkhaki bdb76b darkmagenta 8b008b darkolivegreen 556b2f darkorange ff8c00 darkorchid 9932cc darkred 8b0000 darksalmon e9967a darkseagreen 8fbc8f darkslateblue 483d8b darkslategray 2f4f4f darkturquoise 00ced1 darkviolet 9400d3 deeppink ff1493 deepskyblue 00bfff dimgray 696969 dodgerblue 1e90ff firebrick b22222 floralwhite fffaf0 forestgreen 228b22 fuchsia ff00ff gainsboro dcdcdc ghostwhite f8f8ff gold ffd700 goldenrod daa520 gray 808080 green 008000 greenyellow adff2f honeydew f0fff0 hotpink ff69b4 indianred cd5c5c indigo 4b0082 ivory fffff0 khaki f0e68c lavender e6e6fa lavenderblush fff0f5 lawngreen 7cfc00 lemonchiffon fffacd lightblue add8e6 lightcoral f08080 lightcyan e0ffff lightgoldenrodyellow fafad2 lightgray d3d3d3 lightgreen 90ee90 lightpink ffb6c1 lightsalmon ffa07a lightseagreen 20b2aa lightskyblue 87cefa lightslategray 778899 lightsteelblue b0c4de lightyellow ffffe0 lime 00ff00 limegreen 32cd32 linen faf0e6 magenta ff00ff maroon 800000 mediumaquamarine 66cdaa mediumblue 0000cd mediumorchid ba55d3 mediumpurple 9370d8 mediumseagreen 3cb371 mediumslateblue 7b68ee mediumspringgreen 00fa9a mediumturquoise 48d1cc mediumvioletred c71585 midnightblue 191970 mintcream f5fffa mistyrose ffe4e1 moccasin ffe4b5 navajowhite ffdead navy 000080 oldlace fdf5e6 olive 808000 olivedrab 6b8e23 orange ffa500 orangered ff4500 orchid da70d6 palegoldenrod eee8aa palegreen 98fb98 paleturquoise afeeee palevioletred d87093 papayawhip ffefd5 peachpuff ffdab9 peru cd853f pink ffc0cb plum dda0dd powderblue b0e0e6 purple 800080 rebeccapurple 663399 red ff0000 rosybrown bc8f8f royalblue 4169e1 saddlebrown 8b4513 salmon fa8072 sandybrown f4a460 seagreen 2e8b57 seashell fff5ee sienna a0522d silver c0c0c0 skyblue 87ceeb slateblue 6a5acd slategray 708090 snow fffafa springgreen 00ff7f steelblue 4682b4 tan d2b48c teal 008080 thistle d8bfd8 tomato ff6347 turquoise 40e0d0 violet ee82ee wheat f5deb3 white ffffff whitesmoke f5f5f5 yellow ffff00 yellowgreen 9acd32".split(" ");
a.colorToRgbaSetUpNamedColors=function(){if("undefined"===typeof a.namedColorMap||null===a.namedColorMap){var b={},c;for(c=0;c<a.nc.length;c+=2)b[a.nc[c]]=a.nc[c+1];var d="grey gray darkgrey darkgray darkslategrey darkslategray dimgrey dimgray lightgrey lightgray lightslategrey lightslategray slategrey slategray".split(" ");for(c=0;c<d.length;c+=2)b[d[c]]=b[d[c+1]];a.namedColorMap=b}return a.namedColorMap}})(ka);var fa=function(a){a[0]=0>a[0]?0:Math.min(a[0],1);a[1]=0>a[1]?0:Math.min(a[1],1);a[2]=
0>a[2]?0:Math.min(a[2],1);a[3]=0>a[3]?0:Math.min(a[3],1);return a},Y=function(a,b,c,d){return"undefined"===typeof a||null===a?[0,0,0,0]:"string"===typeof a?(a=ka.colorToRgba(a)||[0,0,0,0],b=1/255,a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b,fa(a)):"number"===typeof a&&"number"===typeof b&&"number"===typeof c?[a,b,c,"number"!==typeof d?1:d]:a.constructor===Array?fa([a[0]||0,a[1]||0,a[2]||0,"number"!==typeof a[3]?1:a[3]]):fa(a||[0,0,0,0])},n={_frustumPoints:function(a){var b=a[0],c=a[1],d=a[2],e=a[3],f=a[4],h=a[5],
g=[],k=d[1]*f[2],m=d[2]*f[1],p=k-m,l=d[2]*f[0],q=d[0]*f[2],t=l-q,n=d[0]*f[1],v=d[1]*f[0],x=n-v,P=b[2]*d[0],w=b[0]*d[2],r=b[0]*d[1],y=b[1]*d[0],A=f[2]*b[0],B=f[0]*b[2],C=f[0]*b[1],z=f[1]*b[0],D=1/(b[0]*p+b[1]*t+b[2]*x),sa=f[1]*b[2],G=f[2]*b[1],F=b[1]*d[2],H=b[2]*d[1],M=-b[3],Q=-d[3],E=-f[3];g[0]=(p*M+(sa-G)*Q+(F-H)*E)*D;g[1]=(t*M+(A-B)*Q+(P-w)*E)*D;g[2]=(x*M+(C-z)*Q+(r-y)*E)*D;var K=e[1]*f[2],I=e[2]*f[1],L=K-I,J=e[2]*f[0],N=e[0]*f[2],R=J-N,V=e[0]*f[1],W=e[1]*f[0],X=V-W,Z=b[2]*e[0],aa=b[0]*e[2],ba=
b[0]*e[1],ca=b[1]*e[0],Y=1/(b[0]*L+b[1]*R+b[2]*X),da=b[1]*e[2],ea=b[2]*e[1],S=-e[3];g[3]=(L*M+(sa-G)*S+(da-ea)*E)*Y;g[4]=(R*M+(A-B)*S+(Z-aa)*E)*Y;g[5]=(X*M+(C-z)*S+(ba-ca)*E)*Y;var fa=k-m,ha=l-q,ia=n-v,ja=c[2]*d[0],ka=c[0]*d[2],la=c[0]*d[1],ta=c[1]*d[0],ua=f[2]*c[0],va=f[0]*c[2],wa=f[0]*c[1],xa=f[1]*c[0],ma=1/(c[0]*fa+c[1]*ha+c[2]*ia),ya=f[1]*c[2],za=f[2]*c[1],Aa=c[1]*d[2],Ba=c[2]*d[1],T=-c[3];g[6]=(fa*T+(ya-za)*Q+(Aa-Ba)*E)*ma;g[7]=(ha*T+(ua-va)*Q+(ja-ka)*E)*ma;g[8]=(ia*T+(wa-xa)*Q+(la-ta)*E)*ma;
var Ca=K-I,Da=J-N,Ea=V-W,Fa=c[2]*e[0],Ga=c[0]*e[2],Ha=c[0]*e[1],Ia=c[1]*e[0],na=1/(c[0]*Ca+c[1]*Da+c[2]*Ea),Ja=c[1]*e[2],Ka=c[2]*e[1];g[9]=(Ca*T+(ya-za)*S+(Ja-Ka)*E)*na;g[10]=(Da*T+(ua-va)*S+(Fa-Ga)*E)*na;g[11]=(Ea*T+(wa-xa)*S+(Ha-Ia)*E)*na;var La=d[1]*h[2],Ma=d[2]*h[1],Na=La-Ma,Oa=d[2]*h[0],Pa=d[0]*h[2],Qa=Oa-Pa,Ra=d[0]*h[1],Sa=d[1]*h[0],Ta=Ra-Sa,Ua=h[2]*b[0],Va=h[0]*b[2],Wa=h[0]*b[1],Xa=h[1]*b[0],oa=1/(b[0]*Na+b[1]*Qa+b[2]*Ta),Ya=h[1]*b[2],Za=h[2]*b[1],U=-h[3];g[12]=(Na*M+(Ya-Za)*Q+(F-H)*U)*oa;
g[13]=(Qa*M+(Ua-Va)*Q+(P-w)*U)*oa;g[14]=(Ta*M+(Wa-Xa)*Q+(r-y)*U)*oa;var $a=e[1]*h[2],ab=e[2]*h[1],bb=$a-ab,cb=e[2]*h[0],db=e[0]*h[2],eb=cb-db,fb=e[0]*h[1],gb=e[1]*h[0],hb=fb-gb,pa=1/(b[0]*bb+b[1]*eb+b[2]*hb);g[15]=(bb*M+(Ya-Za)*S+(da-ea)*U)*pa;g[16]=(eb*M+(Ua-Va)*S+(Z-aa)*U)*pa;g[17]=(hb*M+(Wa-Xa)*S+(ba-ca)*U)*pa;var ib=La-Ma,jb=Oa-Pa,kb=Ra-Sa,lb=h[2]*c[0],mb=h[0]*c[2],nb=h[0]*c[1],ob=h[1]*c[0],qa=1/(c[0]*ib+c[1]*jb+c[2]*kb),pb=h[1]*c[2],qb=h[2]*c[1];g[18]=(ib*T+(pb-qb)*Q+(Aa-Ba)*U)*qa;g[19]=(jb*
T+(lb-mb)*Q+(ja-ka)*U)*qa;g[20]=(kb*T+(nb-ob)*Q+(la-ta)*U)*qa;var rb=$a-ab,sb=cb-db,tb=fb-gb,ra=1/(c[0]*rb+c[1]*sb+c[2]*tb);g[21]=(rb*T+(pb-qb)*S+(Ja-Ka)*U)*ra;g[22]=(sb*T+(lb-mb)*S+(Fa-Ga)*U)*ra;g[23]=(tb*T+(nb-ob)*S+(Ha-Ia)*U)*ra;return g},boxCenter:function(a){return[a[0]+.5*(a[3]-a[0]),a[1]+.5*(a[4]-a[1]),a[2]+.5*(a[5]-a[2])]},boxDimensions:function(a){return[a[3]-a[0],a[4]-a[1],a[5]-a[2]]},boxIsEmpty:function(a){return a[0]>a[3]||a[1]>a[4]||a[2]>a[5]},colorToLinear:function(a){return[.04045>=
a[0]?a[0]/12.92:Math.pow((.055+a[0])/1.055,2.4),.04045>=a[1]?a[1]/12.92:Math.pow((.055+a[1])/1.055,2.4),.04045>=a[2]?a[2]/12.92:Math.pow((.055+a[2])/1.055,2.4),3>=a.length?1:a[3]]},colorTosRGB:function(a){return[.0031308>=a[0]?12.92*a[0]:1.055*Math.pow(a[0],1/2.4)-.055,.0031308>=a[1]?12.92*a[1]:1.055*Math.pow(a[1],1/2.4)-.055,.0031308>=a[2]?12.92*a[2]:1.055*Math.pow(a[2],1/2.4)-.055,3>=a.length?1:a[3]]},frustumHasBox:function(a,b){if(n.boxIsEmpty(b))return!1;var c;for(c=0;6>c;c++){var d=a[c],e=d[3],
f=d[0]*b[0],h=d[2]*b[2],g=d[1]*b[1];if(0>=f+g+h+e&&0>=d[0]*b[3]+d[1]*b[4]+d[2]*b[5]+e&&0>=f+d[1]*b[4]+h+e&&0>=f+d[1]*b[4]+d[2]*b[5]+e&&0>=f+g+d[2]*b[5]+e&&0>=d[0]*b[3]+d[1]*b[4]+h+e&&0>=d[0]*b[3]+g+h+e&&0>=d[0]*b[3]+g+d[2]*b[5]+e)return!1}d=n._frustumPoints(a);for(c=0;3>c;c++){e=b[c];if(d[c]<e&&d[3+c]<e&&d[6+c]<e&&d[9+c]<e&&d[12+c]<e&&d[15+c]<e&&d[18+c]<e&&d[21+c]<e)return!1;e=b[c+3];if(d[c]>e&&d[3+c]>e&&d[6+c]>e&&d[9+c]>e&&d[12+c]>e&&d[15+c]>e&&d[18+c]>e&&d[21+c]>e)return!1}return!0},frustumHasPoint:function(a,
b,c,d){var e;for(e=0;6>e;e++)if(0>=a[e][0]*b+a[e][1]*c+a[e][2]*d+a[e][3])return!1;return!0},frustumHasSphere:function(a,b,c,d,e){if(0>e)throw Error("radius is negative");var f;for(f=0;6>f;f++){var h=a[f];if(h[3]+h[0]*b+h[1]*c+h[2]*d<-e)return!1}return!0},mat3copy:function(a){return[a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]]},mat3identity:function(){return[1,0,0,0,1,0,0,0,1]},mat3invert:function(a){var b=[],c=a[4]*a[8]-a[5]*a[7],d=a[5]*a[6]-a[3]*a[8],e=a[3]*a[7]-a[4]*a[6],f=1/(a[0]*c+a[1]*d+a[2]*
e);if(0===f)return n.mat3identity();b[0]=c*f;b[1]=(a[2]*a[7]-a[1]*a[8])*f;b[2]=(a[1]*a[5]-a[2]*a[4])*f;b[3]=d*f;b[4]=(a[0]*a[8]-a[2]*a[6])*f;b[5]=(a[2]*a[3]-a[0]*a[5])*f;b[6]=e*f;b[7]=(a[1]*a[6]-a[0]*a[7])*f;b[8]=(a[0]*a[4]-a[1]*a[3])*f;return b},mat3multiply:function(a,b){var c=[];c[0]=b[0]*a[0]+b[1]*a[3]+b[2]*a[6];c[1]=b[0]*a[1]+b[1]*a[4]+b[2]*a[7];c[2]=b[0]*a[2]+b[1]*a[5]+b[2]*a[8];c[3]=b[3]*a[0]+b[4]*a[3]+b[5]*a[6];c[4]=b[3]*a[1]+b[4]*a[4]+b[5]*a[7];c[5]=b[3]*a[2]+b[4]*a[5]+b[5]*a[8];c[6]=b[6]*
a[0]+b[7]*a[3]+b[8]*a[6];c[7]=b[6]*a[1]+b[7]*a[4]+b[8]*a[7];c[8]=b[6]*a[2]+b[7]*a[5]+b[8]*a[8];return c},mat3transform:function(a,b,c,d){if("undefined"!==typeof c&&"undefined"!==typeof d){var e=b;b=d}else e=b[0],c=b[1],b=b[2];return[e*a[0]+c*a[3]+b*a[6],e*a[1]+c*a[4]+b*a[7],e*a[2]+c*a[5]+b*a[8]]},mat3transpose:function(a){return n.mat3transposeInPlace(n.mat3copy(a))},mat3transposeInPlace:function(a){var b=a[1];a[1]=a[3];a[3]=b;b=a[2];a[2]=a[6];a[6]=b;b=a[5];a[5]=a[7];a[7]=b;return a},mat4copy:function(a){return[a[0],
a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]]},mat4frustum:function(a,b,c,d,e,f){var h=2*e,g=1/(b-a),k=1/(d-c),m=1/(f-e);return[h*g,0,0,0,0,h*k,0,0,(a+b)*g,(d+c)*k,-(f+e)*m,-1,0,0,-(h*f)*m,0]},mat4identity:function(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},mat4inverseTranspose3:function(a){if(0===a[1]&&0===a[2]&&0===a[4]&&0===a[6]&&0===a[8]&&0===a[9])return 1===a[0]&&1===a[5]&&1===a[10]?[1,0,0,0,1,0,0,0,1]:0!==a[0]*a[5]*a[10]?[1/a[0],0,0,0,1/a[5],0,0,0,1/a[10]]:
[1,0,0,0,1,0,0,0,1];a=[a[0],a[1],a[2],a[4],a[5],a[6],a[8],a[9],a[10]];var b=a[0]*a[4]*a[8]+a[3]*a[7]*a[2]+a[6]*a[1]*a[5]-a[6]*a[4]*a[2]-a[3]*a[1]*a[8]-a[0]*a[7]*a[5];if(0===b)return[1,0,0,0,1,0,0,0,1];b=1/b;return[(-a[5]*a[7]+a[4]*a[8])*b,(a[5]*a[6]-a[3]*a[8])*b,(-a[4]*a[6]+a[3]*a[7])*b,(a[2]*a[7]-a[1]*a[8])*b,(-a[2]*a[6]+a[0]*a[8])*b,(a[1]*a[6]-a[0]*a[7])*b,(-a[2]*a[4]+a[1]*a[5])*b,(a[2]*a[3]-a[0]*a[5])*b,(-a[1]*a[3]+a[0]*a[4])*b]},mat4invert:function(a){var b=a[0]*a[10],c=a[0]*a[11],d=a[0]*a[5],
e=a[0]*a[6],f=a[0]*a[7],h=a[0]*a[9],g=a[10]*a[12],k=a[10]*a[13],m=a[10]*a[15],p=a[11]*a[12],l=a[11]*a[13],q=a[11]*a[14],t=a[1]*a[4],u=a[1]*a[6],v=a[1]*a[7],x=a[1]*a[8],P=a[2]*a[4],w=a[2]*a[5],r=a[2]*a[7],y=a[2]*a[8],A=a[2]*a[9],B=a[3]*a[4],C=a[3]*a[5],z=a[3]*a[6],E=a[3]*a[8],D=a[3]*a[9],G=a[4]*a[9],F=a[5]*a[8],H=a[6]*a[8],M=a[6]*a[9],Q=a[7]*a[8],K=a[7]*a[9],I=t-d,L=u-w,J=v-C,N=P-e;d-=t;u=w-u;w=r-z;t=B-f;v=C-v;r=z-r;e-=P;P=f-B;f=a[9]*a[12]*r+g*J+p*u+a[8]*a[13]*w+k*t+l*e+a[8]*a[14]*v+a[9]*a[14]*P+q*
I+a[8]*a[15]*L+a[9]*a[15]*N+m*d;if(0===f)return n.mat4identity();f=1/f;B=[];B[0]=a[6]*l-a[7]*k+K*a[14]-a[5]*q-M*a[15]+a[5]*m;B[1]=a[3]*k-a[2]*l-D*a[14]+a[1]*q+A*a[15]-a[1]*m;B[2]=a[13]*w+a[14]*v+a[15]*L;B[3]=a[9]*r+a[10]*J+a[11]*u;B[4]=a[7]*g-a[6]*p-Q*a[14]+a[4]*q+H*a[15]-a[4]*m;B[5]=a[2]*p-a[3]*g+a[14]*(E-c)+a[15]*(b-y);B[6]=a[12]*r+a[14]*P+a[15]*N;B[7]=a[8]*w+a[10]*t+a[11]*e;B[8]=a[5]*p-K*a[12]+Q*a[13]-a[4]*l+a[15]*(G-F);B[9]=D*a[12]-a[1]*p+a[13]*(c-E)+a[15]*(x-h);B[10]=a[12]*J+a[13]*t+a[15]*d;
B[11]=a[8]*v+a[9]*P+a[11]*I;B[12]=M*a[12]-a[5]*g-H*a[13]+a[4]*k+a[14]*(F-G);B[13]=a[1]*g-A*a[12]+a[13]*(y-b)+a[14]*(h-x);B[14]=a[12]*u+a[13]*e+a[14]*I;B[15]=a[8]*L+a[9]*N+a[10]*d;for(a=0;16>a;a++)B[a]*=f;return B},mat4isIdentity:function(a){return 1===a[0]&&0===a[1]&&0===a[2]&&0===a[3]&&0===a[4]&&1===a[5]&&0===a[6]&&0===a[7]&&0===a[8]&&0===a[9]&&1===a[10]&&0===a[11]&&0===a[12]&&0===a[13]&&0===a[14]&&1===a[15]},mat4lookat:function(a,b,c){if("undefined"===typeof c||null===c)c=[0,1,0];if("undefined"===
typeof b||null===b)b=[0,0,0];b=n.vec3sub(b,a);var d=n.vec3length(b);if(1E-6>d)return n.mat4identity();n.vec3scaleInPlace(b,1/d);c=n.vec3normalize(c);c=n.vec3cross(b,c);n.vec3normalizeInPlace(c);d=n.vec3cross(c,b);n.vec3normalizeInPlace(d);n.vec3negateInPlace(b);return[c[0],d[0],b[0],0,c[1],d[1],b[1],0,c[2],d[2],b[2],0,-n.vec3dot(a,c),-n.vec3dot(a,d),-n.vec3dot(a,b),1]},mat4multiply:function(a,b){var c=[],d;for(d=0;16>d;d+=4){var e;for(e=0;4>e;e++)c[d+e]=b[d]*a[e]+b[d+1]*a[e+4]+b[d+2]*a[e+8]+b[d+3]*
a[e+12]}return c},mat4oblique:function(a,b){var c=(0<=a&&360>a?a:a%360+(0>a?360:0))*n.PiDividedBy180,d=(0<=b&&360>b?b:b%360+(0>b?360:0))*n.PiDividedBy180,e=Math.cos(c),f=Math.cos(d);c=e/(0<=c&&6.283185307179586>c?3.141592653589793>=c?Math.sqrt(1-e*e):-Math.sqrt(1-e*e):Math.sin(c));return[1,0,0,0,0,1,0,0,-f*c,-(0<=d&&6.283185307179586>d?3.141592653589793>=d?Math.sqrt(1-f*f):-Math.sqrt(1-f*f):Math.sin(d))*c,1,0,0,0,0,1]},mat4ortho:function(a,b,c,d,e,f){var h=1/(b-a),g=1/(d-c),k=1/(f-e);return[2*h,0,
0,0,0,2*g,0,0,0,0,-2*k,0,-(a+b)*h,-(d+c)*g,-(e+f)*k,1]},mat4ortho2d:function(a,b,c,d){return n.mat4ortho(a,b,c,d,-1,1)},mat4ortho2dAspect:function(a,b,c,d,e){return n.mat4orthoAspect(a,b,c,d,-1,1,e)},mat4orthoAspect:function(a,b,c,d,e,f,h){h/=Math.abs((b-a)/(d-c));var g=Math.abs(b-a),k=Math.abs(d-c);1>h?(h=k/h,d>c?(c-=.5*(h-k),d+=.5*(h-k)):(d-=.5*(h-k),c+=.5*(h-k))):(h*=g,b>a?(a-=.5*(h-g),b+=.5*(h-g)):(b-=.5*(h-g),a+=.5*(h-g)));return n.mat4ortho(a,b,c,d,e,f)},mat4perspective:function(a,b,c,d){a=
1/Math.tan((0<=a&&360>a?a:a%360+(0>a?360:0))*n.PiDividedBy360);var e=1/(c-d);return[a/b,0,0,0,0,a,0,0,0,0,e*(c+d),-1,0,0,e*c*d*2,0]},mat4perspectiveHorizontal:function(a,b,c,d){return n.mat4perspective(n.Num360DividedByPi*Math.atan2(Math.tan((0<=a&&360>a?a:a%360+(0>a?360:0))*n.PiDividedBy360),b),b,c,d)},mat4pickMatrix:function(a,b,c,d,e){c=1/c;d=1/d;var f=e[2]*c*2,h=2*-(e[3]*d);return[.5*f,0,0,0,0,-.5*h,0,0,0,0,1,0,.5*f+2*-(a-e[0])*c,-.5*h+2*-(b-e[1])*d,0,1]},mat4projectVec3:function(a,b,c,d){if("undefined"!==
typeof c&&"undefined"!==typeof d){var e=b;b=d}else e=b[0],c=b[1],b=b[2];d=1/(e*a[3]+c*a[7]+b*a[11]+a[15]);return[(e*a[0]+c*a[4]+b*a[8]+a[12])*d,(e*a[1]+c*a[5]+b*a[9]+a[13])*d,(e*a[2]+c*a[6]+b*a[10]+a[14])*d]},mat4rotate:function(a,b,c,d,e){if("undefined"!==typeof d&&"undefined"!==typeof e){var f=c;var h=d;c=e;e=b}else"undefined"===typeof c?(f=b[0],h=b[1],c=b[2],e=b[3]):(f=c[0],h=c[1],c=c[2],e=b);e=(0<=e&&360>e?e:e%360+(0>e?360:0))*n.PiDividedBy180;b=Math.cos(e);var g=3.141592653589793>=e?Math.sqrt(1-
b*b):-Math.sqrt(1-b*b);if(1===f&&0===h&&0===c)return[a[0],a[1],a[2],a[3],b*a[4]+a[8]*g,b*a[5]+a[9]*g,b*a[6]+a[10]*g,b*a[7]+a[11]*g,b*a[8]-g*a[4],b*a[9]-g*a[5],b*a[10]-g*a[6],b*a[11]-g*a[7],a[12],a[13],a[14],a[15]];if(0===f&&1===h&&0===c)return[b*a[0]-g*a[8],b*a[1]-g*a[9],b*a[2]-g*a[10],b*a[3]-g*a[11],a[4],a[5],a[6],a[7],b*a[8]+a[0]*g,b*a[9]+a[1]*g,b*a[10]+a[2]*g,b*a[11]+a[3]*g,a[12],a[13],a[14],a[15]];if(0===f&&0===h&&1===c)return[b*a[0]+a[4]*g,b*a[1]+a[5]*g,b*a[2]+a[6]*g,b*a[3]+a[7]*g,b*a[4]-g*a[0],
b*a[5]-g*a[1],b*a[6]-g*a[2],b*a[7]-g*a[3],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]];if(0===f&&0===h&&0===c)return n.mat4copy(a);e=1/Math.sqrt(f*f+h*h+c*c);f*=e;h*=e;c*=e;var k=h*h;d=1-b;var m=f*h,p=h*c;e=f*g;h*=g;var l=c*g;g=d*p;var q=d*m,t=d*f*c;f=b+d*f*f;m=q+l;p=t-h;k=b+d*k;l=q-l;q=g+e;c=b+d*c*c;b=t+h;e=g-e;return[a[0]*f+a[4]*m+a[8]*p,a[1]*f+a[5]*m+a[9]*p,a[10]*p+a[2]*f+a[6]*m,a[11]*p+a[3]*f+a[7]*m,a[0]*l+a[4]*k+a[8]*q,a[1]*l+a[5]*k+a[9]*q,a[10]*q+a[2]*l+a[6]*k,a[11]*q+a[3]*l+a[7]*k,a[0]*b+
a[4]*e+a[8]*c,a[1]*b+a[5]*e+a[9]*c,a[10]*c+a[2]*b+a[6]*e,a[11]*c+a[3]*b+a[7]*e,a[12],a[13],a[14],a[15]]},mat4rotated:function(a,b,c,d){if("undefined"!==typeof c&&"undefined"!==typeof d){var e=b;b=d;d=a}else"undefined"===typeof b?(e=a[0],c=a[1],b=a[2],d=a[3]):(e=b[0],c=b[1],b=b[2],d=a);d=(0<=d&&360>d?d:d%360+(0>d?360:0))*n.PiDividedBy180;if(90===d||-270===d)return d=1/Math.sqrt(e*e+c*c+b*b),e*=d,c*=d,b*=d,[e*e,e*c+b,e*b-c,0,c*e-b,c*c,c*b+e,0,b*e+c,b*c-e,b*b,0,0,0,0,1];if(-90===d||270===d)return d=
1/Math.sqrt(e*e+c*c+b*b),e*=d,c*=d,b*=d,[e*e,e*c-b,e*b+c,0,c*e+b,c*c,c*b-e,0,b*e-c,b*c+e,b*b,0,0,0,0,1];if(180===d||-180===d)return d=1/Math.sqrt(e*e+c*c+b*b),e*=d,c*=d,b*=d,[e*e*2-1,e*c*2,e*b*2,0,c*e*2,c*c*2-1,c*b*2,0,b*e*2,b*c*2,b*b*2-1,0,0,0,0,1];a=Math.cos(d);var f=0<=d&&6.283185307179586>d?3.141592653589793>=d?Math.sqrt(1-a*a):-Math.sqrt(1-a*a):Math.sin(d);if(1===e&&0===c&&0===b)return[1,0,0,0,0,a,f,0,0,-f,a,0,0,0,0,1];if(0===e&&1===c&&0===b)return[a,0,-f,0,0,1,0,0,f,0,a,0,0,0,0,1];if(0===e&&
0===c&&1===b)return[a,f,0,0,-f,a,0,0,0,0,1,0,0,0,0,1];if(0===e&&0===c&&0===b)return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];d=1/Math.sqrt(e*e+c*c+b*b);e*=d;c*=d;b*=d;d=e*e;var h=c*c,g=b*b,k=e*b,m=c*b,p=e*f,l=c*f;f*=b;var q=1-a;e=q*e*c;c=q*k;b=q*m;return[a+q*d,e+f,c-l,0,e-f,a+q*h,b+p,0,c+l,b-p,a+q*g,0,0,0,0,1]},mat4scale:function(a,b,c,d){if("undefined"!==typeof c&&"undefined"!==typeof d){var e=b;b=d}else e=b[0],c=b[1],b=b[2];return[a[0]*e,a[1]*e,a[2]*e,a[3]*e,a[4]*c,a[5]*c,a[6]*c,a[7]*c,a[8]*b,a[9]*b,a[10]*
b,a[11]*b,a[12],a[13],a[14],a[15]]},mat4scaleInPlace:function(a,b,c,d){if("undefined"!==typeof c&&"undefined"!==typeof d){var e=b;b=d}else e=b[0],c=b[1],b=b[2];a[0]*=e;a[1]*=e;a[2]*=e;a[3]*=e;a[4]*=c;a[5]*=c;a[6]*=c;a[7]*=c;a[8]*=b;a[9]*=b;a[10]*=b;a[11]*=b;return a},mat4scaled:function(a,b,c){return"undefined"!==typeof b&&"undefined"!==typeof c?[a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1]:[a[0],0,0,0,0,a[1],0,0,0,0,a[2],0,0,0,0,1]},mat4toFrustumPlanes:function(a){var b=[[],[],[],[],[],[]];b[0]=n.planeNormalizeInPlace([a[3]+
a[0],a[7]+a[4],a[11]+a[8],a[15]+a[12]]);b[1]=n.planeNormalizeInPlace([a[3]-a[0],a[7]-a[4],a[11]-a[8],a[15]-a[12]]);b[2]=n.planeNormalizeInPlace([a[3]-a[1],a[7]-a[5],a[11]-a[9],a[15]-a[13]]);b[3]=n.planeNormalizeInPlace([a[3]+a[1],a[7]+a[5],a[11]+a[9],a[15]+a[13]]);b[4]=n.planeNormalizeInPlace([a[3]+a[2],a[7]+a[6],a[11]+a[10],a[15]+a[14]]);b[5]=n.planeNormalizeInPlace([a[3]-a[2],a[7]-a[6],a[11]-a[10],a[15]-a[14]]);return b},mat4toMat3:function(a){return[a[0],a[1],a[2],a[4],a[5],a[6],a[8],a[9],a[10]]},
mat4transform:function(a,b,c,d,e){if("undefined"!==typeof c&&"undefined"!==typeof d&&"undefined"!==typeof e){var f=b;b=e}else f=b[0],c=b[1],d=b[2],b=b[3];return[f*a[0]+c*a[4]+d*a[8]+b*a[12],f*a[1]+c*a[5]+d*a[9]+b*a[13],f*a[2]+c*a[6]+d*a[10]+b*a[14],f*a[3]+c*a[7]+d*a[11]+b*a[15]]},mat4transformVec3:function(a,b,c,d){if("undefined"!==typeof c&&"undefined"!==typeof d){var e=b;b=d}else e=b[0],c=b[1],b=b[2];return[e*a[0]+c*a[4]+b*a[8]+a[12],e*a[1]+c*a[5]+b*a[9]+a[13],e*a[2]+c*a[6]+b*a[10]+a[14]]},mat4translate:function(a,
b,c,d){if("undefined"!==typeof c&&"undefined"!==typeof d){var e=b;b=d}else e=b[0],c=b[1],b=b[2];return[a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[0]*e+a[4]*c+a[8]*b+a[12],a[1]*e+a[5]*c+a[9]*b+a[13],a[2]*e+a[6]*c+a[10]*b+a[14],a[3]*e+a[7]*c+a[11]*b+a[15]]},mat4translated:function(a,b,c){if("undefined"!==typeof b&&"undefined"!==typeof c){var d=a;a=c}else d=a[0],b=a[1],a=a[2];return[1,0,0,0,0,1,0,0,0,0,1,0,d,b,a,1]},mat4transpose:function(a){return n.mat4transposeInPlace(n.mat4copy(a))},
mat4transposeInPlace:function(a){var b=a[1];a[1]=a[4];a[4]=b;b=a[2];a[2]=a[8];a[8]=b;b=a[3];a[3]=a[12];a[12]=b;b=a[6];a[6]=a[9];a[9]=b;b=a[7];a[7]=a[13];a[13]=b;b=a[11];a[11]=a[14];a[14]=b;return a},planeFromNormalAndPoint:function(a,b){return[a[0],a[1],a[2],-(a[0]*b[0]+a[1]*b[1]+a[2]*b[2])]},planeNormalize:function(a){return n.planeNormalizeInPlace(n.vec4copy(a))},planeNormalizeInPlace:function(a){var b=a[0],c=a[1],d=a[2];b=Math.sqrt(b*b+c*c+d*d);0!==b&&(b=1/b,a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b);return a},
quatConjugate:function(a){return[-a[0],-a[1],-a[2],a[3]]},quatFromAxisAngle:function(a,b,c,d){if("undefined"!==typeof c&&"undefined"!==typeof d){var e=b;b=d}else"undefined"===typeof b?(e=a[0],c=a[1],b=a[2]):(e=b[0],c=b[1],b=b[2]);d=(0<=a&&360>a?a:a%360+(0>a?360:0))*n.PiDividedBy360;a=Math.cos(d);d=0<=d&&6.283185307179586>d?3.141592653589793>=d?Math.sqrt(1-a*a):-Math.sqrt(1-a*a):Math.sin(d);e=n.vec3normalizeInPlace([e,c,b]);e=[e[0],e[1],e[2],a];e[0]*=d;e[1]*=d;e[2]*=d;return e},quatFromMat4:function(a){var b=
[],c=a[1],d=a[2],e=a[4],f=a[6],h=a[8],g=a[9],k=a[0]+a[5]+a[10];0<=k?(a=.5*Math.sqrt(k+1),k=.25/a,b[0]=(f-g)*k,b[1]=(h-d)*k,b[2]=(c-e)*k,b[3]=a):a[0]>a[5]&&a[0]>a[10]?(a=.5*Math.sqrt(1+a[0]-a[5]-a[10]),k=.25/a,b[0]=a,b[1]=(e+c)*k,b[2]=(d+h)*k,b[3]=(f-g)*k):a[5]>a[10]?(a=.5*Math.sqrt(1+a[5]-a[0]-a[10]),k=.25/a,b[0]=(e+c)*k,b[1]=a,b[2]=(g+f)*k,b[3]=(h-d)*k):(a=.5*Math.sqrt(1+a[10]-a[0]-a[5]),k=.25/a,b[0]=(h+d)*k,b[1]=(g+f)*k,b[2]=a,b[3]=(c-e)*k);return b},quatFromTaitBryan:function(a,b,c,d){if("undefined"===
typeof d||null===d)d=n.GlobalRollPitchYaw;if(0>d||6<=d)throw Error("invalid mode");if(a.constructor===Array){c=(0<=a[2]&&360>a[2]?a[2]:a[2]%360+(0>a[2]?360:0))*n.PiDividedBy360;var e=(0<=a[0]&&360>a[0]?a[0]:a[0]%360+(0>a[0]?360:0))*n.PiDividedBy360;var f=(0<=a[1]&&360>a[1]?a[1]:a[1]%360+(0>a[1]?360:0))*n.PiDividedBy360}else c=(0<=c&&360>c?c:c%360+(0>c?360:0))*n.PiDividedBy360,e=(0<=a&&360>a?a:a%360+(0>a?360:0))*n.PiDividedBy360,f=(0<=b&&360>b?b:b%360+(0>b?360:0))*n.PiDividedBy360;a=Math.cos(e);e=
0<=e&&6.283185307179586>e?3.141592653589793>=e?Math.sqrt(1-a*a):-Math.sqrt(1-a*a):Math.sin(e);b=Math.cos(f);f=0<=f&&6.283185307179586>f?3.141592653589793>=f?Math.sqrt(1-b*b):-Math.sqrt(1-b*b):Math.sin(f);var h=Math.cos(c);c=0<=c&&6.283185307179586>c?3.141592653589793>=c?Math.sqrt(1-h*h):-Math.sqrt(1-h*h):Math.sin(c);if(d===n.GlobalPitchYawRoll||d===n.GlobalPitchRollYaw){var g=[c*f,h*f,c*b,h*b];d===n.GlobalPitchYawRoll&&(g[0]=-g[0]);d=[g[3]*e+g[0]*a,g[1]*a+g[2]*e,g[2]*a-g[1]*e,g[3]*a-g[0]*e]}else d===
n.GlobalYawPitchRoll||d===n.GlobalYawRollPitch?(g=[h*e,c*e,c*a,h*a],d===n.GlobalYawRollPitch&&(g[1]=-g[1]),d=[g[0]*b-g[2]*f,g[3]*f+g[1]*b,g[2]*b+g[0]*f,g[3]*b-g[1]*f]):(g=[b*e,f*a,f*e,b*a],d===n.GlobalRollPitchYaw&&(g[2]=-g[2]),d=[g[0]*h+g[1]*c,g[1]*h-g[0]*c,g[3]*c+g[2]*h,g[3]*h-g[2]*c]);return d},quatFromVectors:function(a,b){var c=n.vec3cross(a,b);if(1E-9>n.vec3dot(c,c)){if(0<n.vec3dot(a,b))return[0,0,0,1];c=n.vec3perp(a);c[3]=0}else{var d=n.vec3length(a)*n.vec3length(b);0===d&&(d=1);c[3]=d+n.vec3dot(a,
b)}return n.quatNormalizeInPlace(c)},quatIdentity:function(){return[0,0,0,1]},quatInvert:function(a){var b=1/n.quatDot(a,a);return n.vec4scaleInPlace(n.quatConjugate(a),b)},quatIsIdentity:function(a){return 0===a[0]&&0===a[1]&&0===a[2]&&1===a[3]},quatMultiply:function(a,b){return[a[3]*b[0]+a[0]*b[3]+a[1]*b[2]-a[2]*b[1],a[3]*b[1]+a[1]*b[3]+a[2]*b[0]-a[0]*b[2],a[3]*b[2]+a[2]*b[3]+a[0]*b[1]-a[1]*b[0],a[3]*b[3]-a[0]*b[0]-a[1]*b[1]-a[2]*b[2]]},quatNlerp:function(a,b,c){var d=1-c,e=a[0]*d,f=a[1]*d,h=a[2]*
d;d*=a[3];var g=b[0]*c,k=b[1]*c,m=b[2]*c;c*=b[3];return 0>a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]?n.quatNormalizeInPlace([e-g,f-k,h-m,d-c]):n.quatNormalizeInPlace([e+g,f+k,h+m,d+c])},quatRotate:function(a,b,c,d,e){return n.quatMultiply(a,n.quatFromAxisAngle(b,c,d,e))},quatSlerp:function(a,b,c){var d=n.quatDot(a,b),e=b;0>d&&(e=[-b[0],-b[1],-b[2],-b[3]],d=n.quatDot(a,e));if(-1<d)if(1>d){if(d=Math.acos(d),0===d)return n.quatNlerp(a,b,c)}else return n.quatNlerp(a,b,c);else d=Math.PI;var f=1/Math.sin(d);
b=Math.sin((1-c)*d)*f;c=Math.sin(c*d)*f;return[a[0]*b+e[0]*c,a[1]*b+e[1]*c,a[2]*b+e[2]*c,a[3]*b+e[3]*c]},quatToAxisAngle:function(a){var b=a[3],c=1-b*b;return 0<c?(c=1/Math.sqrt(c),[a[0]*c,a[1]*c,a[2]*c,Math.acos(Math.min(1,Math.max(-1,b)))*n.Num360DividedByPi]):[0,1,0,0]},quatToMat4:function(a){var b=2*a[0],c=2*a[1],d=2*a[2],e=b*a[0],f=b*a[1],h=b*a[2],g=c*a[1],k=d*a[1],m=d*a[2];b*=a[3];c*=a[3];a=d*a[3];return[1-(g+m),f+a,h-c,0,f-a,1-(e+m),k+b,0,h+c,k-b,1-(e+g),0,0,0,0,1]},quatTransform:function(a,
b){var c=a[1]*b[2]-a[2]*b[1]+b[0]*a[3],d=a[2]*b[0]-a[0]*b[2]+b[1]*a[3],e=a[0]*b[1]-a[1]*b[0]+b[2]*a[3],f=a[0]*b[0]+a[1]*b[1]+a[2]*b[2];return 3===b.length?[c*a[3]-(d*a[2]-e*a[1])+a[0]*f,d*a[3]-(e*a[0]-c*a[2])+a[1]*f,e*a[3]-(c*a[1]-d*a[0])+a[2]*f]:[c*a[3]-(d*a[2]-e*a[1])+a[0]*f,d*a[3]-(e*a[0]-c*a[2])+a[1]*f,e*a[3]-(c*a[1]-d*a[0])+a[2]*f,1]},vec2abs:function(a){return[Math.abs(a[0]),Math.abs(a[1])]},vec2absInPlace:function(a){a[0]=Math.abs(a[0]);a[1]=Math.abs(a[1]);return a},vec2add:function(a,b){return[a[0]+
b[0],a[1]+b[1]]},vec2addInPlace:function(a,b){var c=b[1];a[0]+=b[0];a[1]+=c;return a},vec2assign:function(a,b){a[0]=b[0];a[1]=b[1];return a},vec2clamp:function(a,b,c){return n.vec2clampInPlace(n.vec2copy(a),b,c)},vec2clampInPlace:function(a,b,c){var d=Math.min(c,Math.max(b,a[1]));a[0]=Math.min(c,Math.max(b,a[0]));a[1]=d;return a},vec2copy:function(a){return[a[0],a[1]]},vec2dist:function(a,b){return n.vec2length(n.vec2sub(a,b))},vec2dot:function(a,b){return a[0]*b[0]+a[1]*b[1]},vec2length:function(a){var b=
a[0];a=a[1];return Math.sqrt(b*b+a*a)},vec2lerp:function(a,b,c){return[a[0]+(b[0]-a[0])*c,a[1]+(b[1]-a[1])*c]},vec2mul:function(a,b){return[a[0]*b[0],a[1]*b[1]]},vec2mulInPlace:function(a,b){var c=b[1];a[0]*=b[0];a[1]*=c;return a},vec2negate:function(a){return[-a[0],-a[1]]},vec2negateInPlace:function(a){a[0]=-a[0];a[1]=-a[1];return a},vec2normalize:function(a){return n.vec2normalizeInPlace([a[0],a[1]])},vec2normalizeInPlace:function(a){var b=a[0],c=a[1];b=Math.sqrt(b*b+c*c);0!==b&&(b=1/b,a[0]*=b,
a[1]*=b);return a},vec2perp:function(a){return[-a[1],a[0]]},vec2proj:function(a,b){var c=n.vec2dot(b,b);return 0===c?[0,0]:n.vec2scale(b,n.vec2dot(a,b)/c)},vec2reflect:function(a,b){return n.vec2sub(a,n.vec2scale(b,2*n.vec2dot(b,a)))},vec2scale:function(a,b){return n.vec2scaleInPlace([a[0],a[1]],b)},vec2scaleInPlace:function(a,b){a[0]*=b;a[1]*=b;return a},vec2sub:function(a,b){return[a[0]-b[0],a[1]-b[1]]},vec2subInPlace:function(a,b){var c=b[1];a[0]-=b[0];a[1]-=c;return a},vec3abs:function(a){return[Math.abs(a[0]),
Math.abs(a[1]),Math.abs(a[2])]},vec3absInPlace:function(a){a[0]=Math.abs(a[0]);a[1]=Math.abs(a[1]);a[2]=Math.abs(a[2]);return a},vec3add:function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2]]},vec3addInPlace:function(a,b){var c=b[1],d=b[2];a[0]+=b[0];a[1]+=c;a[2]+=d;return a},vec3assign:function(a,b){a[0]=b[0];a[1]=b[1];a[2]=b[2];return a},vec3clamp:function(a,b,c){return n.vec3clampInPlace(n.vec3copy(a),b,c)},vec3clampInPlace:function(a,b,c){var d=Math.min(c,Math.max(b,a[1])),e=Math.min(c,Math.max(b,
a[2]));a[0]=Math.min(c,Math.max(b,a[0]));a[1]=d;a[2]=e;return a},vec3copy:function(a){return[a[0],a[1],a[2]]},vec3cross:function(a,b){return[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]},vec3dist:function(a,b){return n.vec3length(n.vec3sub(a,b))},vec3dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]},vec3fromWindowPoint:function(a,b,c,d){var e=.5*c[2],f=.5*c[3],h=0,g=0,k=2*a[2]-1;0!==e&&0!==f&&(h=(a[0]-c[0]-e)/e,g=(a[1]-c[1]-f)/f);g="undefined"!==typeof d&&null!==d&&!1!==d?g:
-g;a=n.mat4invert(b);return n.mat4projectVec3(a,[h,g,k])},vec3length:function(a){var b=a[0],c=a[1];a=a[2];return Math.sqrt(b*b+c*c+a*a)},vec3lerp:function(a,b,c){return[a[0]+(b[0]-a[0])*c,a[1]+(b[1]-a[1])*c,a[2]+(b[2]-a[2])*c]},vec3mul:function(a,b){return[a[0]*b[0],a[1]*b[1],a[2]*b[2]]},vec3mulInPlace:function(a,b){var c=b[1],d=b[2];a[0]*=b[0];a[1]*=c;a[2]*=d;return a},vec3negate:function(a){return[-a[0],-a[1],-a[2]]},vec3negateInPlace:function(a){a[0]=-a[0];a[1]=-a[1];a[2]=-a[2];return a},vec3normalize:function(a){return n.vec3normalizeInPlace([a[0],
a[1],a[2]])},vec3normalizeInPlace:function(a){var b=a[0],c=a[1],d=a[2];b=Math.sqrt(b*b+c*c+d*d);0!==b&&(b=1/b,a[0]*=b,a[1]*=b,a[2]*=b);return a},vec3perp:function(a){var b=Math.abs(a[0]),c=Math.abs(a[1]),d=Math.max(b,c,Math.abs(a[2])),e=[0,0,0];d===b?(e[0]=a[1],e[1]=-a[0],e[2]=0):d===c?(e[0]=0,e[1]=a[2],e[2]=-a[1]):(e[0]=-a[2],e[1]=0,e[2]=a[0]);return e},vec3proj:function(a,b){var c=n.vec3dot(b,b);return 0===c?[0,0,0]:n.vec3scale(b,n.vec3dot(a,b)/c)},vec3reflect:function(a,b){return n.vec3sub(a,n.vec3scale(b,
2*n.vec3dot(b,a)))},vec3scale:function(a,b){return n.vec3scaleInPlace([a[0],a[1],a[2]],b)},vec3scaleInPlace:function(a,b){a[0]*=b;a[1]*=b;a[2]*=b;return a},vec3sub:function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2]]},vec3subInPlace:function(a,b){var c=b[1],d=b[2];a[0]-=b[0];a[1]-=c;a[2]-=d;return a},vec3toWindowPoint:function(a,b,c,d){if(0>c[2]||0>c[3])throw Error();a=n.mat4projectVec3(b,a);b=.5*c[2];var e=.5*c[3];return[a[0]*b+b+c[0],("undefined"!==typeof d&&null!==d&&!1!==d?a[1]:-a[1])*e+e+c[1],
.5*(a[2]+1)]},vec3triple:function(a,b,c){return n.vec3dot(a,n.vec3cross(b,c))},vec4abs:function(a){return[Math.abs(a[0]),Math.abs(a[1]),Math.abs(a[2]),Math.abs(a[3])]},vec4absInPlace:function(a){a[0]=Math.abs(a[0]);a[1]=Math.abs(a[1]);a[2]=Math.abs(a[2]);a[3]=Math.abs(a[3]);return a},vec4add:function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2],a[3]+b[3]]},vec4addInPlace:function(a,b){var c=b[1],d=b[2],e=b[3];a[0]+=b[0];a[1]+=c;a[2]+=d;a[3]+=e;return a},vec4assign:function(a,b){a[0]=b[0];a[1]=b[1];a[2]=
b[2];a[3]=b[3];return a},vec4clamp:function(a,b,c){return n.vec4clampInPlace(n.vec4copy(a),b,c)},vec4clampInPlace:function(a,b,c){var d=Math.min(c,Math.max(b,a[1])),e=Math.min(c,Math.max(b,a[2])),f=Math.min(c,Math.max(b,a[3]));a[0]=Math.min(c,Math.max(b,a[0]));a[1]=d;a[2]=e;a[3]=f;return a},vec4copy:function(a){return[a[0],a[1],a[2],a[3]]},vec4dot:function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]},vec4length:function(a){var b=a[0],c=a[1],d=a[2];a=a[3];return Math.sqrt(b*b+c*c+d*d+a*a)},
vec4lerp:function(a,b,c){return[a[0]+(b[0]-a[0])*c,a[1]+(b[1]-a[1])*c,a[2]+(b[2]-a[2])*c,a[3]+(b[3]-a[3])*c]},vec4negate:function(a){return[-a[0],-a[1],-a[2],-a[3]]},vec4negateInPlace:function(a){a[0]=-a[0];a[1]=-a[1];a[2]=-a[2];a[3]=-a[3];return a},vec4normalize:function(a){return n.vec4normalizeInPlace([a[0],a[1],a[2],a[3]])},vec4normalizeInPlace:function(a){var b=a[0],c=a[1],d=a[2],e=a[3];b=Math.sqrt(b*b+c*c+d*d+e*e);0!==b&&(b=1/b,a[0]*=b,a[1]*=b,a[2]*=b,a[3]*=b);return a},vec4proj:function(a,
b){var c=n.vec4dot(b,b);return 0===c?[0,0,0]:n.vec4scale(b,n.vec4dot(a,b)/c)},vec4scale:function(a,b){return[a[0]*b,a[1]*b,a[2]*b,a[3]*b]},vec4scaleInPlace:function(a,b){a[0]*=b;a[1]*=b;a[2]*=b;a[3]*=b;return a},vec4sub:function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2],a[3]-b[3]]},vec4subInPlace:function(a,b){var c=b[1],d=b[2],e=b[3];a[0]-=b[0];a[1]-=c;a[2]-=d;a[3]-=e;return a},vecZeros:function(a){var b=[],c;for(c=0;c<a;c++)b[c]=0;return b},vecSub:function(a,b){var c=[],d;for(d=0;d<a.length;d++)c[d]=
a[d]-b[d];return c},vecSubInPlace:function(a,b){var c;for(c=0;c<a.length;c++)a[c]-=b[c];return a},vecScale:function(a,b){var c=[],d;for(d=0;d<a.length;d++)c[d]=a[d]*b;return c},vecSubScaleInPlace:function(a,b,c){var d;for(d=0;d<a.length;d++)a[d]=(a[d]-b[d])*c;return a},vecScaleInPlace:function(a,b){var c;for(c=0;c<a.length;c++)a[c]*=b;return a},vecNormalizeInPlace:function(a){var b=0,c;for(c=0;c<a.length;c++)b+=a[c]*a[c];b=Math.sqrt(b);if(0!==b)for(b=1/b,c=0;c<a.length;c++)a[c]*=b;return a},vecLength:function(a){var b=
0,c;for(c=0;c<a.length;c++)b+=a[c]*a[c];return Math.sqrt(b)},interpCubicBezier:function(a,b,c,d,e){if(0>=e)return 0;if(1<=e)return 1;var f=e,h;for(h=0;10>h;h++){var g=f*(3*a*(f*(f-2)+1)-3*c*f*(f-1)+f*f)-e;if(1E-9>Math.abs(g))break;f-=g/(3*(((3*f-4)*f+1)*a+(-3*f+2)*f*c+f*f))}return f*(3*b*(f*(f-2)+1)-3*d*f*(f-1)+f*f)}};n.quatDot=n.vec4dot;n.quatNormalizeInPlace=n.vec4normalizeInPlace;n.quatNormalize=n.vec4normalize;n.quatLength=n.vec4length;n.quatScaleInPlace=n.vec4scaleInPlace;n.quatScale=n.vec4scale;
n.quatCopy=n.vec4copy;n.PiTimes2=6.283185307179586;n.HalfPi=1.5707963267948966;n.PiDividedBy180=.017453292519943295;n.ToRadians=n.PiDividedBy180;n.PiDividedBy360=.008726646259971648;n.Num360DividedByPi=114.59155902616465;n.Num180DividedByPi=57.29577951308232;n.ToDegrees=n.Num180DividedByPi;n.GlobalPitchYawRoll=0;n.GlobalPitchRollYaw=1;n.GlobalYawPitchRoll=2;n.GlobalYawRollPitch=3;n.GlobalRollPitchYaw=4;n.GlobalRollYawPitch=5;n.LocalPitchYawRoll=n.GlobalRollYawPitch;n.LocalPitchRollYaw=n.GlobalYawRollPitch;
n.LocalYawPitchRoll=n.GlobalRollPitchYaw;n.LocalYawRollPitch=n.GlobalPitchRollYaw;n.LocalRollPitchYaw=n.GlobalYawPitchRoll;n.LocalRollYawPitch=n.GlobalPitchYawRoll;y.prototype.endPoints=function(){return"undefined"!==typeof this.curveParam&&null!==this.curveParam?this.curveParam.endPoints():"undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.endPoints&&null!==this.curve.endPoints?this.curve.endPoints():[0,1]};y.prototype._getCoord=function(a){return"undefined"!==
typeof this.curveParam&&null!==this.curveParam?this.curveParam.getCoordinate(a):a};y._EPSILON=1E-5;y.prototype.evaluate=function(a){return"undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.evaluate&&null!==this.curve.evaluate?this.curve.evaluate(this._getCoord(a)):[0,0,0]};y.prototype.velocity=function(a){if("undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.velocity&&null!==this.curve.velocity)return this.curve.velocity(this._getCoord(a));
var b=y._EPSILON,c=this.evaluate(a+b);0===c[0]&&0===c[1]&&0===c[2]&&(b=-b,c=this.evaluate(a+b));return n.vecSubScaleInPlace(c,this.evaluate(a),1/b)};y.prototype.accel=function(a){if("undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.accel&&null!==this.curve.accel)return this.curve.accel(this._getCoord(a));var b=y._EPSILON,c=this.velocity(a+b);0===c[0]&&0===c[1]&&0===c[2]&&(b=-b,c=this.velocity(a+b));return n.vecSubScaleInPlace(c,this.velocity(a),
1/b)};y.prototype.jerk=function(a){if("undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.jerk&&null!==this.curve.jerk)return this.curve.jerk(this._getCoord(a));var b=y._EPSILON,c=this.accel(a+b);0===c[0]&&0===c[1]&&0===c[2]&&(b=-b,c=this.accel(a+b));return n.vecSubScaleInPlace(c,this.accel(a),1/b)};y.prototype.normal=function(a){if("undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.normal&&null!==
this.curve.normal)return this.curve.normal(this._getCoord(a));var b=y._EPSILON,c=this.tangent(a+b);0===c[0]&&0===c[1]&&0===c[2]&&(c=n.vecScaleInPlace(this.tangent(a+-b),-1));c=n.vecSubInPlace(c,this.tangent(a));return n.vecNormalizeInPlace(c)};y.prototype.tangent=function(a){return n.vecNormalizeInPlace(this.velocity(a))};y.prototype.getLength=function(){var a=this.endPoints();return this.arcLength(a[1])};var ba=[.9969339225295955,.00825771143316837,0,.9815606342467192,.02303608403898155,.04717533638651112,
.9505377959431213,.03891523046929952,0,.9041172563704749,.05369701760775668,.10693932599531891,.8435581241611533,.06725090705083998,0,.7699026741943047,.07992027533360173,.16007832854334625,.6840598954700559,.09154946829504924,0,.5873179542866175,.10164973227906016,.20316742672306579,.4813394504781571,.11002260497764407,0,.3678314989981802,.11671205350175679,.23349253653835478,.24850574832046932,.12162630352394839,0,.1252334085114689,.12458416453615606,.24914704581340283,0,.12555689390547423,0];y.prototype.arcLength=
function(a){if("undefined"!==typeof this.curveParam&&null!==this.curveParam&&this.curveParam instanceof y._ArcLengthParam)return a;if("undefined"!==typeof this.curve&&null!==this.curve&&this.curve!==this&&"undefined"!==typeof this.curve.arcLength&&null!==this.curve.arcLength)return this.curve.arcLength(this._getCoord(a));var b=this.endPoints();if(a===b[0])return 0;var c=this;return da(function(a){return n.vecLength(c.velocity(a))},Math.min(a,b[0]),Math.max(a,b[0]),a>=b[0]?1:-1,0)};y.prototype.getPoints=
function(a){if(0===a)return[];if(0>a)throw Error();var b=this.endPoints(),c=[this.evaluate(b[0])],d;for(d=1;d<a;d++){var e=this.evaluate(b[0]+d/(a-1)*(b[1]-b[0]));c.push(e)}return c};y.prototype.getPointsAsObjects=function(a){if(0===a)return[];if(0>a)throw Error();var b=this.endPoints(),c=[ha(this.evaluate(b[0]))],d;for(d=1;d<a;d++){var e=this.evaluate(b[0]+d/(a-1)*(b[1]-b[0]));c.push(ha(e))}return c};y._ChangeEnds=function(a,b){this.u1=a;this.u2=b;this.getCoordinate=function(a){return a};this.endPoints=
function(){return[this.u1,this.u2]}};y._FitRange=function(a,b,c){this.newEp1=b;this.newEp2=c;this.invNewEpDelta=1/(c-b);a=a.endPoints();this.origEp1=a[0];this.origEp2=a[1];this.getCoordinate=function(a){return this.origEp1+(this.origEp2-this.origEp1)*(a-this.newEp1)*this.invNewEpDelta};this.endPoints=function(){return[b,c]}};y._ArcLengthParam=function(a){this.curve=a;this.ep=this.curve.endPoints();this.segments=[];a=this.ep[0];var b=0,c=this.curve.getLength();c=Math.min(Math.max(10,Math.ceil(18*c)),
50);var d;for(d=1;d<=c;d++){var e=this.ep[0]+d/c*(this.ep[1]-this.ep[0]),f=this.curve.arcLength(e);this.segments.push([b,f,a,e]);a=e;b=f}this.length=0===this.segments.length?0:this.segments[this.segments.length-1][1];this._vecLength=function(a){var b=0,c;for(c=0;c<a.length;c++)b+=a[c]*a[c];return Math.sqrt(b)};this._solveArcLength=function(a,b,c,d){var e;for(e=0;10>e;e++){var f=this.curve.arcLength(b)-a;if(1E-10>Math.abs(f)&&b>=c&&b<d)break;var g=this._vecLength(this.curve.velocity(b));if(0===g)break;
g=f/g;var h=b-g;if(0===g)break;c!==Number.NEGATIVE_INFINITY&&d!==Number.POSITIVE_INFINITY?0>f?(c=Math.max(c,b),b=h,h>=d&&(b=c+.5*(d-c))):0<f&&(d=Math.min(d,b),b=h,h<=c&&(b=c+.5*(d-c))):b=h}return b}};y._ArcLengthParam.prototype.getCoordinate=function(a){if(Number.isNaN(a))throw Error();if(a>this.length){var b=this.curve.endPoints();var c=b[0]+a/this.length*(b[1]-b[0]);return this._solveArcLength(a,c,b[0],Number.POSITIVE_INFINITY)}if(0>a)return b=this.curve.endPoints(),c=b[0]+a/this.length*(b[1]-b[0]),
this._solveArcLength(a,c,Number.NEGATIVE_INFINITY,0);if(a===this.length)return b=this.curve.endPoints(),b[1];if(0===a)return b=this.curve.endPoints(),b[0];c=0;for(var d=this.segments.length,e=0;c<d;){e+=1;if(20<e)throw Error();var f=c+((d-c)/2|0);b=this.segments[f];if(a===b[0])return b[2];if(a===b[1])return b[3];if(a>b[0]&&a<b[1])return c=b[2]+(a-b[0])/(b[1]-b[0])*(b[3]-b[2]),1E-10<=b[1]-b[0]?this._solveArcLength(a,c,b[2],b[3]):c;a<b[0]?d=f:c=f+1}throw Error("Internal error");};y._ArcLengthParam.prototype.endPoints=
function(){return[0,this.length]};y.prototype.changeEnds=function(a,b){return new y(this,new y._ChangeEnds(a,b))};y.prototype.fitRange=function(a,b){return new y(this,new y._FitRange(this,a,b))};y.prototype.toArcLengthParam=function(){return"undefined"!==typeof this.curveParam&&null!==this.curveParam&&this.curveParam instanceof y._ArcLengthParam?this:new y(this,new y._ArcLengthParam(this))};var J=function(a){this.surface="undefined"===typeof a?null:a};J._EPSILON=1E-5;J.prototype.tangent=function(a,
b){if("undefined"!==typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.tangent&&null!==this.surface.tangent)return this.surface.tangent(a,b);var c=J._EPSILON,d=this.evaluate(a+c,b);0===d[0]&&0===d[1]&&0===d[2]&&(c=-c,d=this.evaluate(a+c,b));return n.vecSubScaleInPlace(d,this.evaluate(a,b),1/c)};J.prototype.bitangent=function(a,b){if("undefined"!==typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.bitangent&&null!==this.surface.bitangent)return this.surface.bitangent(a,
b);var c=J._EPSILON,d=this.evaluate(a,b+c);0===d[0]&&0===d[1]&&0===d[2]&&(c=-c,d=this.evaluate(a,b+c));return n.vecSubScaleInPlace(d,this.evaluate(a,b),1/c)};J.prototype.normal=function(a,b){return n.vecNormalizeInPlace(this.gradient(a,b))};J.prototype.gradient=function(a,b){if("undefined"!==typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.gradient&&null!==this.surface.gradient)return this.surface.gradient(a,b);var c=this.tangent(a,b),d=this.bitangent(a,b);if(0===n.vecLength(d))return c;
if(0!==n.vecLength(c)){if(3!==c.length||3!==d.length){var e=c.length,f=n.vecZeros(e);c=[c[0]||0,c[1]||0,c[2]||0];d=[d[0]||0,d[1]||0,d[2]||0];c=n.vec3cross(c,d);f[0]=c[0];f[1]=c[1];f[2]=c[2];return f.slice(0,e)}return n.vec3cross(c,d)}return d};J.prototype.evaluate=function(a,b){return"undefined"!==typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.evaluate&&null!==this.surface.evaluate?this.surface.evaluate(a,b):[0,0,0]};J.prototype.endPoints=function(){return"undefined"!==
typeof this.surface&&null!==this.surface&&"undefined"!==typeof this.surface.endPoints&&null!==this.surface.endPoints?this.surface.endPoints():[0,1,0,1]};var I=function(){};I.LINES=1;I.TRIANGLES=4;I.POINTS=0;var C=function(){this.attributes=[];this.vertexCount=0;this.indices=[];this.mode=I.TRIANGLES},E=function(){this.attributes=[];this.vertexCount=0;this.indices=[];this.mode=I.TRIANGLES};C._toMeshBuffer=function(a,b,c,d){d=a.BufferGeometry();c=new Uint32Array(c);d.index=new a.BufferAttribute(new Uint32Array(c),
1);for(c=0;c<b.length;c++){var e=b[c];if(0!==e[1])throw Error();switch(e[0]){case "POSITION":case "position":e=new a.InterleavedBufferAttribute(new Float32Array(e[3]),e[2],0);d.setAttribute("position",e);break;case "NORMAL":case "normal":e=new a.InterleavedBufferAttribute(new Float32Array(e[3]),e[2],0);d.setAttribute("normal",e);break;case "TEXCOORD":case "uv":e=new a.InterleavedBufferAttribute(new Float32Array(e[3]),e[2],0);d.setAttribute("uv",e);break;case "COLOR":case "color":e=new a.InterleavedBufferAttribute(new Float32Array(e[3]),
e[2],0);d.setAttribute("color",e);break;default:throw Error("unsupported attr:"+e[0]);}}return d};C._blank=function(a){var b=[],c;for(c=0;c<a;c++)b.push(0);return b};C._resize=function(a,b){if(a[2]!==b){var c=a[3].length/a[2],d=Math.min(a[2],b),e=C._blank(c*b),f=0,h=0,g;for(g=0;g<c;g++){var k;for(k=0;k<d;k++)e[h+k]=a[3][f+k];f+=a[2];h+=b}a[2]=b;a[3]=e}};C._addValue=function(a,b){var c=Math.min(b.length,a[2]),d;for(d=0;d<c;d++)a[3].push(b[d]);for(d=c;d<a[2];d++)a[3].push(0)};C._defaultEndPointsCurve=
function(a){var b;for(b=0;b<a.length;b++){var c=a[b];if("position"===c[0]&&0===c[1]){a=c[4];if("undefined"!==typeof a.endPoints&&null!==a.endPoints)return c[4].endPoints();break}}return[0,1]};C._defaultSubdivisionsCurve=function(a){var b;for(b=0;b<a.length;b++){var c=a[b];if("position"===c[0]&&0===c[1])return Math.max(200,Math.ceil((new y(c[4])).getLength()/4))}return 24};C._defaultEndPointsSurface=function(a){var b;for(b=0;b<a.length;b++){var c=a[b];if("position"===c[0]&&0===c[1]){a=c[4];if("undefined"!==
typeof a&&null!==a&&"undefined"!==typeof a.endPoints&&null!==a.endPoints)return c[4].endPoints();break}}return[0,1,0,1]};C._toCurve=function(a){return"undefined"===typeof a||null===a||a instanceof y?a:new y(a)};C._toSurface=function(a){return"undefined"===typeof a||null===a||a instanceof J?a:new J(a)};C._setAttribute=function(a,b,c,d,e,f){var h="undefined"===typeof f||null===f?3:f,g="undefined"!==typeof c&&null!==c;if(0>=f)throw Error("Invalid attribute size");d=[d,("undefined"===typeof e||null===
e?0:e)||0];if("undefined"===typeof d||null===d)throw Error();for(e=0;e<a.length;e++)if(f=a[e],f[0]===d[0]&&f[1]===d[1]){g?(f[4]=c,C._resize(f,h)):a.splice(e,1);return}g&&(b=[d[0],d[1],h,C._blank(h*b),c],a.push(b))};C._NormalSurface=function(a){this.surface=new J(a);this.endPoints=function(){return this.surface.endPoints()};this.evaluate=function(a,c){return this.surface.normal(a,c)}};C.prototype.clearVertices=function(){this.vertexCount=0;this.indices=[];var a;for(a=0;a<this.attributes.length;a++)this.attributes[a][3]=
[];return this};C.prototype.toMeshBuffer=function(a){return C._toMeshBuffer(a,this.attributes,this.indices,this.mode)};C.prototype.position=function(a,b){return this.attribute(a,"position",0,b)};C.prototype.attribute=function(a,b,c,d){C._setAttribute(this.attributes,this.vertexCount,a,b,c,d);return this};C.prototype.constantAttribute=function(a,b,c){return"number"===typeof a?this.attribute({evaluate:function(){return[a]}},b,c,1):this.attribute({evaluate:function(){return a}},b,c,a.length)};C.prototype.constantColor=
function(a,b){var c=Y(a);return this.constantAttribute([c[0],c[1],c[2]],"color",b)};C.curveToBuffer=function(a,b,c,d,e,f){return(new C).position(b,3).evalCurve(c,d,e,f).toMeshBuffer(a)};E.prototype.clearVertices=function(){this.vertexCount=0;this.indices=[];var a;for(a=0;a<this.attributes.length;a++)this.attributes[a][3]=[];return this};E.prototype.toMeshBuffer=function(a){return C._toMeshBuffer(a,this.attributes,this.indices,this.mode)};E.prototype.position=function(a,b){return this.attribute(a,
"position",0,b)};E.prototype.texCoord=function(a,b){return this.attribute(a,"uv",0,"undefined"===typeof b||null===b?2:b)};E.prototype.positionNormal=function(a,b){var c="undefined"!==typeof a&&null!==a?new C._NormalSurface(a):null;return this.attribute(a,"position",0,b).attribute(c,"normal",0,b)};E._TexCoord=function(a){a=(new J(a)).endPoints();this.u1=a[0];this.v1=a[2];this.uinv=a[0]===a[1]?0:1/(a[1]-a[0]);this.vinv=a[2]===a[3]?0:1/(a[3]-a[2]);this.evaluate=function(a,c){return[(a-this.u1)*this.uinv,
(c-this.v1)*this.vinv]}};E.prototype.positionTexCoord=function(a,b){var c="undefined"!==typeof a&&null!==a?new E._TexCoord(a):null;return this.attribute(a,"position",0,b).attribute(c,"uv",0,2)};E.prototype.positionNormalTexCoord=function(a,b){var c="undefined"!==typeof a&&null!==a?new E._TexCoord(a):null;return this.positionNormal(a,b).attribute(c,"uv",0,2)};E.prototype.attribute=function(a,b,c,d){C._setAttribute(this.attributes,this.vertexCount,a,b,c,d);return this};E.prototype.constantAttribute=
function(a,b,c){return"number"===typeof a?this.attribute({evaluate:function(){return[a]}},b,c,1):this.attribute({evaluate:function(){return a}},b,c,a.length)};E.prototype.constantColor=function(a,b){var c=Y(a);return this.constantAttribute([c[0],c[1],c[2]],"color",b)};E.surfaceToBuffer=function(a,b,c,d,e,f,h,g,k){return(new E).positionNormalTexCoord(b,3).evalSurface(c,d,e,f,h,e,k).toMeshBuffer(a)};C.prototype.evalCurve=function(a,b,c,d){b="undefined"===typeof b||null===b?C._defaultSubdivisionsCurve(this.attributes):
Math.ceil(b);if(0===b)return this;if(0>b)throw Error();if("undefined"===typeof a||null===a)a=I.LINES;if("undefined"===typeof c||null===c||"undefined"===typeof d||null===d)d=C._defaultEndPointsCurve(this.attributes),c=d[0],d=d[1];var e=(d-c)/b,f=this.vertexCount;if(a===I.LINES||"undefined"===typeof a||null===a){for(d=0;d<b;d++)this.indices.push(f+d,f+d+1);this.vertexCount+=b+1}else if(a===I.POINTS){for(d=0;d<b;d++)this.indices.push(f+d);this.vertexCount+=b+1}else return this;this.mode=a;for(d=0;d<=
b;d++)for(a=c+d*e,f=0;f<this.attributes.length;f++){var h=this.attributes[f],g="undefined"!==typeof h[4]&&null!==h[4]?h[4].evaluate(a):[];C._addValue(h,g)}return this};E.prototype.evalSurface=function(a,b,c,d,e,f,h){b="undefined"===typeof b||null===b?24:Math.ceil(b);c="undefined"===typeof c||null===c?24:Math.ceil(c);if(0===b||0===c)return this;if(0>=b)throw Error();if(0>=c)throw Error();if("undefined"===typeof a||null===a)a=I.TRIANGLES;if("undefined"===typeof d||null===d||"undefined"===typeof e||
null===e||"undefined"===typeof f||null===f||"undefined"===typeof h||null===h)h=C._defaultEndPointsSurface(this.attributes),d=h[0],e=h[1],f=h[2],h=h[3];if(a!==I.TRIANGLES&&a!==I.LINES&&a!==I.POINTS)return this;var g,k=(e-d)/b,m=(h-f)/c;e=this.vertexCount;this.vertexCount+=(c+1)*(b+1);for(h=0;h<=c;h++)for(g=0;g<=b;g++){var p=g*k+d;var l=h*m+f;var q;for(q=0;q<this.attributes.length;q++){var t=this.attributes[q],n="undefined"!==typeof t[4]&&null!==t[4]?t[4].evaluate(p,l):[];C._addValue(t,n)}}this.mode=
a;if(a===I.TRIANGLES)for(a=b+1,h=0;h<c;h++)for(g=0;g<b;g++)k=h*a+g+e,d=k+a,f=k+1,p=d+1,this.indices.push(k,d,f),this.indices.push(f,d,p);else if(a===I.POINTS)for(b=this.vertexCount,h=e;h<b;h++)this.indices.push(h);else if(a===I.LINES)for(a=b+1,h=0;h<=b;h++)for(g=0;g<=c;g++)d=g*a+h+e,g<c&&(f=d+a,this.indices.push(d,f)),h<b&&(f=d+1,this.indices.push(f,d));return this};w.prototype=Object.create(y.prototype);w.prototype.constructor=w;w.DIVIDE_BIT=2;w._checkKnots=function(a,b){var c;for(c=1;c<a.length;c++)if(a[c]<
a[c-1])throw Error(a+"---/"+[a[c-1],a[c]]);for(c=1;c<a.length-2-b;c++)if(a[c+b]<=a[c])throw Error();if(a[0]===a[a.length-1]||a[0]>=a[b+1])throw Error();if(a[a.length-2-b]>=a[a.length-1])throw Error();if(b+1>=a.length)throw Error();};w._nfunc=function(a,b,c,d){if(0===b)return d[a]<=c&&c<d[a+1]?1:0;if(d[a]>c||d[a]===d[a+b]&&d[a+b+1]===d[a+1]||d[a+b+1]<c)return 0;var e=d[a]===d[a+b]?0:w._nfunc(a,b-1,c,d),f=d[a+b+1]===d[a+1]?0:w._nfunc(a+1,b-1,c,d);if(0===e+f)return 0;var h=0;if(0!==e){var g=d[a+b]-d[a];
h+=(c-d[a])*e*(0===g?1:1/g)}0!==f&&(g=d[a+b+1]-d[a+1],h+=(d[a+b+1]-c)*f*(0===g?1:1/g));return h};w._getFactors=function(a,b,c,d,e){var f=1,h=1,g;for(g=0;g<d;g++)e[g]=0;for(g=1;g<a.length;g++)if(a[g]===a[0])f+=1;else break;for(g=a.length-2;0<=g;g--)if(a[g]===a[a.length-1])h+=1;else break;if(b>=a[a.length-1-c]&&a[a.length-1-c]===a[a.length-1])e[d-1]=1;else if(f!==c+1||h!==c+1)for(f=0;f<d;f++)e[f]=w._nfunc(f,c,b,a);else if(b<=a[c])e[0]=1;else if(b>=a[a.length-1-c])e[d-1]=1;else{d=-1;for(f=0;f<=a.length;f++)if(a[f]<=
b&&b<a[f+1]){d=f;break}if(!(0>d)){h=a[d+1]-b;g=a[d];var k=b-g;e[d]=1;var m;for(m=1;m<=c;m++){e[d-m]=e[d-m+1]*h/(a[d+1]-a[d-m+1]);for(f=d-m+1;f<d;f++){var p=a[f];e[f]*=(b-p)/(a[f+m]-p);e[f]+=e[f+1]*(a[f+m+1]-b)/(a[f+m+1]-a[f+1])}e[d]*=k/(a[d+m]-g)}}}};w.prototype.evaluate=function(a){var b=[];if(this.fastBezier){var c=this.controlPoints;switch(c.length){case 1:b=c[0].slice(0,c[0].length);break;case 2:var d=c[0].length;b=[];var e=c[0];c=c[1];var f;for(f=0;f<d;f++){var h=e[f];b[f]=h+(c[f]-h)*a}break;
case 3:d=c[0].length;b=[];e=c[0];f=c[1];c=c[2];for(h=0;h<d;h++)b[h]=((a-2)*a+1)*e[h]+(-2*a+2)*a*f[h]+a*a*c[h];break;case 4:d=c[0].length;b=[];e=c[0];f=c[1];h=c[2];c=c[3];var g;for(g=0;g<d;g++)b[g]=(((3-a)*a-3)*a+1)*e[g]+((3*a-6)*a+3)*a*f[g]+(-3*a+3)*a*a*h[g]+a*a*a*c[g]}}else if(e=this.controlPoints.length,c=this.knots.length-e-1,d=this.controlPoints[0].length,b=null,a<=this.knots[c]?this.knots[c]===this.knots[0]?b=this.controlPoints[0].slice(0,d):a=this.knots[c]:a>=this.knots[this.knots.length-1-
c]&&(this.knots[this.knots.length-1-c]===this.knots[this.knots.length-1]?b=this.controlPoints[e-1].slice(0,d):a=this.knots[this.knots.length-1-c]),"undefined"===typeof b||null===b){g=0;b=-1;for(e=0;e<this.knots.length;e++)if(f=this.knots[e],(h=a===f)&&g++,f<this.knots[e+1])if(h){b=e;break}else if(f<a&&a<this.knots[e+1]){b=e;break}if(0>b)throw Error();if(g>c)throw Error();if(g===c)b=this.controlPoints[b-c].slice(0,d);else{f=c-g;h=[];for(e=b-c;e<=b-g;e++)h.push(this.controlPoints[e]);for(g=1;g<=f;g++){var k=
h[g-1];for(e=g;e<h.length;e++){var m=b-c+e,p=this.knots[m];m=(a-p)/(this.knots[m+c-g+1]-p);p=h[e];var l=[],q;for(q=0;q<d;q++)l[q]=k[q]*(1-m)+p[q]*m;h[e]=l;k=p}}b=h[h.length-1].slice(0,d)}}0!==(this.bits&w.DIVIDE_BIT)&&(b=w._fromHomogen(b));return b};w._splitKnots=function(a,b,c){var d=-1,e=-1,f=[],h=[],g;for(g=0;g<a.length;g++)if(a[g]>c){e=g;break}else a[g]<c&&(d=g);if(0>d||0>e)throw Error();for(g=0;g<=d;g++)f.push(a[g]);for(g=0;g<b+1;g++)f.push(c),h.push(c);for(g=e;g<a.length;g++)h.push(a[g]);return[f,
h]};w.prototype.split=function(a){var b=this.controlPoints.length,c=this.knots.length-b-1,d=this.controlPoints[0].length,e;if(a<=this.knots[c])return[null,this];if(a>=this.knots[this.knots.length-1-c])return[this,null];var f=0,h=-1;for(e=0;e<this.knots.length;e++){var g=this.knots[e],k=a===g;k&&f++;if(g<this.knots[e+1])if(k){h=e;break}else if(g<a&&a<this.knots[e+1]){h=e;break}}if(0>h)throw Error();if(f>c)throw Error();g=w._splitKnots(this.knots,c,a);k=[];if(f===c){var m=this.controlPoints.slice(0,
h-c+1);k=this.controlPoints.slice(h-c,this.controlPoints.length)}else{var p=c-f,l=[];for(e=h-c;e<=h-f;e++)l.push(this.controlPoints[e]);m=[];for(e=0;e<=h-c;e++)m.push(this.controlPoints[e]);var q=[],n;for(n=1;n<=p;n++){var u=l[n-1];for(e=n;e<l.length;e++){var v=h-c+e,x=this.knots[v];v=(a-x)/(this.knots[v+c-n+1]-x);x=l[e];var P=[],r;for(r=0;r<d;r++)P[r]=u[r]*(1-v)+x[r]*v;l[e]=P;u=x;e===n?m.push(P):e+1===l.length&&q.push(P)}}k.push(m[m.length-1]);for(e=q.length-1;0<=e;e--)k.push(q[e]);for(e=h-f;e<b;e++)k.push(this.controlPoints[e])}a=
new w(m,g[0],this.bits);b=new w(k,g[1],this.bits);return[a,b]};w.prototype.endPoints=function(){var a=this.knots.length-this.controlPoints.length-1;return[this.knots[a],this.knots[this.knots.length-1-a]]};w.prototype.getControlPoints=function(){return this.controlPoints};w.prototype.getKnots=function(){return this.knots};w.prototype.velocity=function(a){var b=[];if(this.fastBezier){var c=this.controlPoints;switch(c.length){case 1:b=n.vecZeros(c[0].length);break;case 2:b=n.vecSub(c[1],c[0]);break;
case 3:b=c[0].length;var d=[],e=c[0],f=c[1];c=c[2];var h;for(h=0;h<b;h++)d[h]=(2*a-2)*e[h]+(-4*a+2)*f[h]+2*a*c[h];b=d;break;case 4:b=c[0].length;d=[];e=c[0];f=c[1];h=c[2];c=c[3];var g;for(g=0;g<b;g++)d[g]=((-3*a+6)*a-3)*e[g]+((9*a-12)*a+3)*f[g]+(-9*a+6)*a*h[g]+3*a*a*c[g];b=d}}else{c=this.controlPoints.length;e=this.knots.length-c-1;d=this.controlPoints[0].length;w._getFactors(this.knots,a,e-1,c,this.buffer);f=[];for(h=0;h<c;h++)f[h]=0;for(a=0;a<c-1;a++)h=e*this.buffer[a+1]/(this.knots[a+e+1]-this.knots[a+
1]),f[a+1]+=h,f[a]-=h;for(h=0;h<d;h++){for(a=e=0;a<c;a++)e+=f[a]*this.controlPoints[a][h];b[h]=e}}0!==(this.bits&w.DIVIDE_BIT)&&(b=w._fromHomogen(b));return b};w._fromHomogen=function(a){var b=a.length,c=1/a[b-1],d;for(d=0;d<b-1;d++)a[d]*=c;return a=a.slice(0,b-1)};L.prototype=Object.create(J.prototype);L.prototype.constructor=L;w.clamped=function(a,b,c){return new w(a,w.clampedKnots(a.length,b),c)};w.fromBezierCurve=function(a,b){return w.clamped(a,a.length-1,b)};w.uniform=function(a,b,c){return new w(a,
w.uniformKnots(a.length,b),c)};L.clamped=function(a,b,c,d){return new L(a,w.clampedKnots(a[0].length,b),w.clampedKnots(a.length,c),d)};L.uniform=function(a,b,c,d){return new L(a,w.uniformKnots(a[0].length,b),w.uniformKnots(a.length,c),d)};w.uniformKnots=function(a,b){"object"===typeof a&&(a=a.length);var c="undefined"===typeof b||null===b?3:b;if(a<c+1)throw Error("too few control points for degree "+c+" curve");c+=1;var d=[],e=1/(a+c-1),f;for(f=0;f<a+c;f++)d.push(f*e);return d};w.clampedKnots=function(a,
b){"object"===typeof a&&(a=a.length);var c="undefined"===typeof b||null===b?3:b;if(a<c+1)throw Error("too few control points for degree "+c+" curve");c+=1;var d=a-c,e=[],f;for(f=0;f<c;f++)e.push(0);for(f=0;f<d;f++)e.push(1*(f+1)/(d+1));for(f=0;f<c;f++)e.push(1);return e};L.prototype.evaluate=function(a,b){var c=this.controlPoints[0][0].length,d=this.bufferU,e=this.bufferV,f,h,g,k;w._getFactors(this.knotsU,a,this.degreeU,this.ucplen,this.bufferU);w._getFactors(this.knotsV,b,this.degreeV,this.vcplen,
this.bufferV);var m=[];for(g=0;g<c;g++){for(f=k=0;f<this.ucplen;f++)for(h=0;h<this.vcplen;h++)k+=this.controlPoints[h][f][g]*d[f]*e[h];m[g]=k}0!==(this.bits&w.DIVIDE_BIT)&&(m=w._fromHomogen(m));return m};L.prototype.getControlPoints=function(){return this.controlPoints};L.prototype.getKnots=function(){return this.knots};L.prototype.tangent=function(a,b){var c=this.controlPoints[0][0].length,d=this.bufferV,e,f,h;w._getFactors(this.knotsU,a,this.degreeU-1,this.ucplen,this.bufferU);w._getFactors(this.knotsV,
b,this.degreeV,this.vcplen,this.bufferV);var g=[],k=[];for(f=0;f<this.ucplen;f++)k[f]=0;for(e=0;e<this.ucplen-1;e++){var m=this.degreeU*this.bufferU[e+1]/(this.knotsU[e+this.degreeU+1]-this.knotsU[e+1]);k[e+1]+=m;k[e]-=m}for(f=0;f<c;f++){for(e=h=0;e<this.ucplen;e++)for(m=0;m<this.vcplen;m++)h+=this.controlPoints[m][e][f]*k[e]*d[m];g[f]=h}0!==(this.bits&w.DIVIDE_BIT)&&(g=w._fromHomogen(g));return g};L.prototype.bitangent=function(a,b){var c=this.controlPoints[0][0].length,d=this.bufferU,e,f,h;w._getFactors(this.knotsU,
a,this.degreeU,this.ucplen,this.bufferU);w._getFactors(this.knotsV,b,this.degreeV-1,this.vcplen,this.bufferV);var g=[],k=[];for(f=0;f<this.vcplen;f++)k[f]=0;for(e=0;e<this.vcplen-1;e++){var m=this.degreeV*this.bufferV[e+1]/(this.knotsV[e+this.degreeV+1]-this.knotsV[e+1]);k[e+1]+=m;k[e]-=m}for(f=0;f<c;f++){for(e=h=0;e<this.ucplen;e++)for(m=0;m<this.vcplen;m++)h+=this.controlPoints[m][e][f]*d[e]*k[m];g[f]=h}0!==(this.bits&w.DIVIDE_BIT)&&(g=w._fromHomogen(g));return g};L.fromBezierSurface=function(a,
b){return L.clamped(a,a[0].length-1,a.length-1,b)};var G=function(a){this.curves=[];this.curvesEp=[];this.runningCurveStart=[];var b;for(b=0;b<a.length;b++)this.curves[b]=a[b]instanceof y?a[b]:new y(a[b]),this.curvesEp[b]=this.curves[b].endPoints(),this.runningCurveStart[b]=0===b?0:Number.NaN};G.prototype=Object.create(y.prototype);G.prototype.constructor=G;G.prototype.endPoints=function(){return[0,this.curves.length]};G.prototype.getCurves=function(){return this.curves};G.prototype._getRunningCurveStart=
function(a){if(0===a)return 0;if(isNaN(this.runningCurveStart[a])){var b;for(b=1;b<=a;b++)isNaN(this.runningCurveStart[b])&&(this.runningCurveStart[b]=this.runningCurveStart[b-1]+this.curves[b-1].arcLength(this.curvesEp[b-1][1]))}return this.runningCurveStart[a]};G.prototype._getCurveAndPoint=function(a){var b;0>a?a=b=0:a>=this.curves.length?(b=this.curves.length-1,a=1):(b=Math.floor(a),a-=b);var c=this.curvesEp[b];return[b,c[0]+(c[1]-c[0])*a]};G.prototype.arcLength=function(a){if(0>=a)return 0;a=
this._getCurveAndPoint(a);return this._getRunningCurveStart(a[0])+this.curves[a[0]].arcLength(a[1])};G.prototype.evaluate=function(a){a=this._getCurveAndPoint(a);return this.curves[a[0]].evaluate(a[1])};G.prototype.velocity=function(a){a=this._getCurveAndPoint(a);return this.curves[a[0]].velocity(a[1])};G.fromTCBSpline=function(a,b,c,d,e,f){var h=a[0].length;if(2>a.length)throw Error();b="undefined"===typeof b||null===b?0:b;c="undefined"===typeof c||null===c?0:c;d="undefined"===typeof d||null===d?
0:d;e="undefined"===typeof e||null===e?!1:e;f="undefined"===typeof f||null===f?!1:f;var g=1/3,k=[],m=a.length-1,p=e?m+1:m,l;for(l=0;l<p;l++){var q=[[],[],[],[]],n=l>m?a[0]:a[l];if(e)if(0===l){var u=a[m];var v=a[l+1];var x=2===a.length?a[0]:a[l+2]}else l===m-1?(u=a[l-1],v=a[l+1],x=a[0]):l===m?(u=a[l-1],v=a[0],x=a[1]):(u=a[l-1],v=a[l+1],x=a[l+2]);else v=a[l+1],u=0===l?null:a[l-1],x=l>=m?null:a[l+2];var P=1-c,r=1+c,y=1-d,A=1+d,C=1-b,B;for(B=0;B<h;B++){var z=n[B],E=v[B],D=v[B]-n[B],F=.5*C*r*A*("undefined"===
typeof u||null===u?0:n[B]-u[B])+.5*C*P*y*D;D=.5*C*P*A*D+.5*C*r*y*("undefined"===typeof x||null===x?0:x[B]-v[B]);if(!f){if("undefined"===typeof u||null===u)F=0;if("undefined"===typeof x||null===x)D=0}F=z+F*g;D=E-D*g;q[0][B]=z;q[1][B]=F;q[2][B]=D;q[3][B]=E}k.push(w.clamped(q,3))}return new G(k)};G.fromHermiteSpline=function(a){var b=a[0].length;if(4>a.length||0!==a.length%2)throw Error();var c=1/3,d=[],e;for(e=0;e<a.length-2;e+=2){var f=[[],[],[],[]],h=a[e],g=a[e+1],k=a[e+2],m=a[e+3],p;for(p=0;p<b;p++){var l=
h[p],q=k[p],n=l+g[p]*c,u=q-m[p]*c;f[0][p]=l;f[1][p]=n;f[2][p]=u;f[3][p]=q}d.push(w.clamped(f,3))}return new G(d)};G.fromCatmullRomSpline=function(a,b,c){var d=a[0].length;if(2>a.length)throw Error();b="undefined"===typeof b||null===b?.5:b;c="undefined"===typeof c||null===c?!1:c;var e=[],f=a.length-1,h=c?f+1:f,g;for(g=0;g<h;g++){var k=[[],[],[],[]],m=0===g?a[0]:a[g-1],p=a[g],l=a[g+1],q=g+2>f?a[f]:a[g+2];if(!c&&g+2>f){var n=[];for(q=0;q<d;q++)n[q]=m[q]+(p[q]-l[q]);q=n}if(!c&&0===g){n=[];for(m=0;m<d;m++)n[m]=
q[m]+(l[m]-p[m]);m=n}c&&(0===g?(m=a[f],q=2===a.length?a[0]:a[g+2]):g===f-1?q=a[0]:g===f&&(l=a[0],q=a[1]));var u=n=0,v=0,x;for(x=0;x<d;x++){var r=m[x]-p[x];n+=r*r;r=p[x]-l[x];u+=r*r;r=l[x]-q[x];v+=r*r}n=Math.sqrt(n);u=Math.sqrt(u);v=Math.sqrt(v);for(x=0;x<d;x++){r=m[x];var y=p[x],A=l[x],C=q[x],z=1,B=1,D=1;0!==b&&(z=Math.pow(n,b),B=Math.pow(u,b),D=Math.pow(v,b));var E=y,F=A;var H=3*z*(z+B);0!==H&&(E=(z*z*A-B*B*r+y*(2*z*z+3*z*B+B*B))/H);H=3*D*(D+B);0!==H&&(F=(D*D*y-B*B*C+A*(2*D*D+3*D*B+B*B))/H);k[0][x]=
y;k[1][x]=E;k[2][x]=F;k[3][x]=A}e.push(w.clamped(k,3))}return new G(e)};G.fromEllipseArc=function(a,b,c,d,e,f){if("undefined"===typeof e||null===e)e=0;if("undefined"===typeof f||null===f)f=0;var h=f=f*Math.PI/180;f=0>f?-1:1;for(var g=h>.5*Math.PI&&h<=2*Math.PI?.25*h:.5*Math.PI,k=[],m,p;0<h;){var l=Math.min(g,h);p=e+l*f;var q=Math.cos(e);m=0<=e&&6.283185307179586>e?3.141592653589793>=e?Math.sqrt(1-q*q):-Math.sqrt(1-q*q):Math.sin(e);var n=Math.cos(p);p=0<=p&&6.283185307179586>p?3.141592653589793>=p?
Math.sqrt(1-n*n):-Math.sqrt(1-n*n):Math.sin(p);h-=l;e+=l*f;m=[q,m,1];n=[n,p,1];l=Math.sin(.5*(Math.PI-l));p=m[0]+.5*(n[0]-m[0]);q=m[1]+.5*(n[1]-m[1]);var u=1/Math.sqrt(p*p+q*q),v=1/l;p=[p*u*v,q*u*v,l];m[0]=a+m[0]*c;m[1]=b+m[1]*d;n[0]=a+n[0]*c;n[1]=b+n[1]*d;p[0]=(a+p[0]*c)*l;p[1]=(b+p[1]*d)*l;k.push(w.fromBezierCurve([m,p,n],w.DIVIDE_BIT))}return new G(k)};var Z=function(a){this.data=a;this.next=this.prev=null},ca=function(){this._last=this.root=null;this.size=function(){for(var a=this.root,b=0;a;)b++,
a=a.next;return b};this.first=function(){return this.root};this.last=function(){return this._last};this.front=function(){return this.root?this.root.data:null};this.back=function(){return this._last?this._last.data:null};this.clear=function(){this.root=this._last=null};this.spliceToBegin=function(a){a.root&&(this.root.prev=a._last,a._last.next=this.root,this.root=a.root,a.clear())};this.spliceToEnd=function(a){a.root&&(this._last.next=a.root,a.root.prev=this._last,this._last=a._last,a.clear())};this.spliceOneToEnd=
function(a,b){a.erase(b);return this.push(b.data)};this.erase=function(a){if(!a)return this;a===this.root&&(this.root=a.next);a===this._last&&(this._last=a.prev);a.prev&&(a.prev.next=a.next);a.next&&(a.next.prev=a.prev);return this};this.insertAfter=function(a,b){var c=new Z(a);b===this._last&&(this._last=c);var d=b.next;b.next=c;c.prev=b;if(c.next=d)d.prev=c;return c};this.push=function(a){this.root?(a=new Z(a),this._last.next=a,a.prev=this._last,this._last=a):this.root=this._last=new Z(a);return this};
this.reverse=function(){var a=this.root,b=this._last;if(a){for(var c=a;a;){var d=a.next,e=a.prev;a.prev=d;a.next=e;a=d}this.root=b;this._last=c;return this}};this.unshift=function(a){this.root?(a=new Z(a),this.root.prev=a,a.next=this.root,this.root=a):this.root=this._last=new Z(a);return this};this.pop=function(){this._last&&(this._last.prev&&(this._last.prev.next=null),this._last=this._last.prev);return this};this.shift=function(){this.root&&(this.root.next&&(this.root.next.prev=null),this.root=
this.root.next);return this}};R.prototype=Object.create(y.prototype);R.prototype.constructor=R;R.prototype.evaluate=function(a){return[this.x1+(this.x2-this.x1)*a,this.y1+(this.y2-this.y1)*a,0]};R.prototype.velocity=function(){return[this.x2-this.x1,this.y2-this.y1,0]};R.prototype.arcLength=function(a){var b=this.x1+(this.x2-this.x1)*a-this.x1,c=this.y1+(this.y2-this.y1)*a-this.y1;b=Math.sqrt(b*b+c*c);0>a&&(b=-b);return b};W.prototype=Object.create(y.prototype);W.prototype.constructor=W;W.prototype.evaluate=
function(a){if(0===a)return[this.x1,this.y1,0];if(1===a)return[this.x2,this.y2,0];var b=this.theta+this.delta*a;a=Math.cos(b);b=0<=b&&6.283185307179586>b?3.141592653589793>=b?Math.sqrt(1-a*a):-Math.sqrt(1-a*a):Math.sin(b);return[this.cr*a*this.rx-this.sr*b*this.rx+this.cx,this.sr*a*this.rx+this.cr*b*this.ry+this.cy,0]};W.prototype.velocity=function(a){var b=this.theta+this.delta*a;a=Math.cos(b);b=-(0<=b&&6.283185307179586>b?3.141592653589793>=b?Math.sqrt(1-a*a):-Math.sqrt(1-a*a):Math.sin(b))*this.delta;
a*=this.delta;return[this.cr*b*this.rx-this.sr*a*this.rx,this.sr*b*this.rx+this.cr*a*this.ry,0]};var l=function(){this.segments=[];this.incomplete=!1;this.startPos=[0,0];this.endPos=[0,0]},N={};l.CLOSE=0;l.LINE=1;l.QUAD=2;l.CUBIC=3;l.ARC=4;l.prototype.isIncomplete=function(){return this.incomplete};l._startPoint=function(a){return a[0]===l.CLOSE?[0,0]:[a[1],a[2]]};l._endPoint=function(a){return a[0]===l.CLOSE?[0,0]:a[0]===l.ARC?[a[8],a[9]]:[a[a.length-2],a[a.length-1]]};l._point=function(a,b){if(a[0]===
l.CLOSE)return[0,0];if(a[0]===l.LINE)return[a[1]+(a[3]-a[1])*b,a[2]+(a[4]-a[2])*b];if(a[0]===l.QUAD){var c=1-b;var d=c*c,e=c+c;var f=a[1]*d;var h=a[3]*e;c=f+b*(h+b*a[5]);f=a[2]*d;h=a[4]*e;f+=b*(h+b*a[6]);return[c,f]}if(a[0]===l.CUBIC)return f=3*(a[3]-a[1]),h=3*(a[5]-a[3])-f,d=a[7]-f-h-a[1],c=a[1]+b*(f+b*(h+b*d)),f=3*(a[4]-a[2]),h=3*(a[6]-a[4])-f,d=a[8]-f-h-a[2],f=a[2]+b*(f+b*(h+b*d)),[c,f];if(a[0]===l.ARC){if(0===b)return[a[1],a[2]];if(1===b)return[a[8],a[9]];c=a[3];f=a[4];e=a[5];d=a[12]+(a[13]-a[12])*
b;h=Math.cos(e);e=0<=e&&6.283185307179586>e?3.141592653589793>=e?Math.sqrt(1-h*h):-Math.sqrt(1-h*h):Math.sin(e);var g=Math.cos(d);d=0<=d&&6.283185307179586>d?3.141592653589793>=d?Math.sqrt(1-g*g):-Math.sqrt(1-g*g):Math.sin(d);return[h*g*c-e*d*f+a[10],e*g*c+h*d*f+a[11]]}return[0,0]};l._segToCurve=function(a){if(a[0]===l.LINE)return new R(a[1],a[2],a[3],a[4]);if(a[0]===l.QUAD)return w.fromBezierCurve([[a[1],a[2],0],[a[3],a[4],0],[a[5],a[6],0]]);if(a[0]===l.CUBIC)return w.fromBezierCurve([[a[1],a[2],
0],[a[3],a[4],0],[a[5],a[6],0],[a[7],a[8],0]]);if(a[0]===l.ARC)return new W(a[1],a[2],a[8],a[9],a[3],a[4],a[5],a[10],a[11],a[12],a[13]-a[12]);throw Error();};l._subdivide2=function(a,b,c,d,e,f,h,g,k,m,p,n,q,t,u){var O=a+(c-a)*p,x=c+(e-c)*p;c=O+(x-O)*p;e+=(h-e)*p;x+=(e-x)*p;var r=c+(x-c)*p,w=b+(d-b)*p,y=d+(f-d)*p;d=w+(y-w)*p;f+=(g-f)*p;y+=(f-y)*p;var A=d+(y-d)*p;p=k+(m-k)*p;l._flattenCubic(a,b,O,w,c,d,r,A,k,p,n,q,t,u+1);l._flattenCubic(r,A,x,y,e,f,h,g,p,m,n,q,t,u+1)};l._subdivide3=function(a,b,c,d,
e,f,h,g,k,m,p,n,q,t,u,v){var O=a+(c-a)*p,r=c+(e-c)*p;c=O+(r-O)*p;e+=(h-e)*p;r+=(e-r)*p;var w=c+(r-c)*p,y=b+(d-b)*p,A=d+(f-d)*p;d=y+(A-y)*p;f+=(g-f)*p;A+=(f-A)*p;var z=d+(A-d)*p;p=k+(m-k)*p;n=(n-p)/(m-p);l._flattenCubic(a,b,O,y,c,d,w,z,k,p,q,t,u,v+1);l._subdivide2(w,z,r,A,e,f,h,g,p,m,n,q,t,u,v+1)};l._flattenCubic=function(a,b,c,d,e,f,h,g,k,m,p,n,q,t){if("undefined"===typeof t||null===t)t=0;20<=t||Math.abs(a-c-c+e)+Math.abs(c-e-e+h)+Math.abs(b-d-d+f)+Math.abs(d-f-f+g)<=n?0===q?p.push([a,b,h,g]):(a=
h-a,b=g-b,p.push(k,m,Math.sqrt(a*a+b*b))):l._subdivide2(a,b,c,d,e,f,h,g,k,m,.5,p,n,q,t)};l._flattenQuad=function(a,b,c,d,e,f,h,g,k,m,p,n){if("undefined"===typeof n||null===n)n=0;if(20<=n||Math.abs(a-c-c+e)+Math.abs(b-d-d+f)<=m)0===p?k.push([a,b,e,f]):(a=e-a,b=f-b,k.push(h,g,Math.sqrt(a*a+b*b)));else{var q=.5*(a+c);c=.5*(c+e);var O=.5*(q+c),u=.5*(b+d);d=.5*(d+f);var v=.5*(u+d),x=.5*(h+g);l._flattenQuad(a,b,q,u,O,v,h,x,k,m,p,n+1);l._flattenQuad(O,v,c,d,e,f,x,g,k,m,p,n+1)}};l._flattenArc=function(a,
b,c,d,e,f,h){var g=a[5],k=Math.cos(g);l._flattenArcInternal([a[3],a[4],a[10],a[11],k,0<=g&&6.283185307179586>g?3.141592653589793>=g?Math.sqrt(1-k*k):-Math.sqrt(1-k*k):Math.sin(g)],a[1],a[2],a[8],a[9],a[12],a[13],b,c,d,e,f,h)};l._flattenArcInternal=function(a,b,c,d,e,f,h,g,k,m,p,n,q){if("undefined"===typeof q||null===q)q=0;var O=.5*(f+h),u=.5*(g+k),v=Math.cos(O),x=0<=O&&6.283185307179586>O?3.141592653589793>=O?Math.sqrt(1-v*v):-Math.sqrt(1-v*v):Math.sin(O),r=a[4]*v*a[0]-a[5]*x*a[1]+a[2];v=a[5]*v*a[0]+
a[4]*x*a[1]+a[3];20<=q||Math.abs(b-r-r+d)+Math.abs(c-v-v+e)<=p?0===n?(m.push([b,c,r,v]),m.push([r,v,d,e])):(a=r-b,c=v-c,c=Math.sqrt(a*a+c*c),m.push(g,u,c),a=d-r,c=e-v,c=Math.sqrt(a*a+c*c),m.push(u,k,c)):(l._flattenArcInternal(a,b,c,r,v,f,O,g,u,m,p,n,q+1),l._flattenArcInternal(a,r,v,d,e,O,h,u,k,m,p,n,q+1))};l.prototype._start=function(){var a;for(a=0;a<this.segments.length;a++){var b=this.segments[a];if(b[0]!==l.CLOSE)return l._startPoint(b)}return[0,0]};l.prototype._end=function(){var a;for(a=this.segments.length-
1;0<=a;a--){var b=this.segments[a];if(b[0]!==l.CLOSE)return l._endPoint(b)}return[0,0]};l.prototype.merge=function(a){var b=null;if(!a)return this;var c=a.segments.length,d;for(d=0;d<c;d++){var e=a.segments[d];if(e[0]===l.CLOSE)this.closePath();else{var f=l._startPoint(e);b&&b[0]===f[0]&&b[1]===f[1]||this.moveTo(f[0],f[1]);b=l._endPoint(e);e[0]===l.LINE&&this.lineTo(e[3],e[4]);e[0]===l.QUAD&&this.quadraticCurveTo(e[3],e[4],e[5],e[6]);e[0]===l.CUBIC&&this.bezierCurveTo(e[3],e[4],e[5],e[6],e[7],e[8]);
e[0]===l.ARC&&(f=e[13]-e[12],this.arcSvgTo(e[3],e[4],e[5]*l._toDegrees,Math.abs(f)>Math.PI,0<f,e[8],e[9]))}}return this};l.prototype.toString=function(){var a=null,b="",c;for(c=0;c<this.segments.length;c++){var d=this.segments[c];if(d[0]===l.CLOSE)b+="Z";else{var e=l._startPoint(d);a&&a[0]===e[0]&&a[1]===e[1]||(b+="M"+e[0]+","+e[1]);a=l._endPoint(d);d[0]===l.LINE&&(b+="L"+d[3]+","+d[4]);d[0]===l.QUAD&&(b+="Q"+d[3]+","+d[4]+","+d[5]+","+d[6]);d[0]===l.CUBIC&&(b+="C"+d[3]+","+d[4]+","+d[5]+","+d[6]+
","+d[7]+","+d[8]);d[0]===l.ARC&&(e=d[13]-d[12],b+="A"+d[3]+","+d[4]+","+180*d[5]/Math.PI+","+(Math.abs(e)>Math.PI?"1":"0")+(0<e?"1":"0")+d[8]+","+d[9])}}return b};l.prototype.pathLength=function(a){if(0===this.segments.length)return 0;"undefined"!==typeof a&&null!==a&&console.warn("Unused parameter flatness is defined");return this.getCurves().getLength()};l.prototype.getLines=function(a){var b=[];if("undefined"===typeof a||null===a)a=1;var c;for(c=0;c<this.segments.length;c++){var d=this.segments[c];
d[0]===l.QUAD?l._flattenQuad(d[1],d[2],d[3],d[4],d[5],d[6],0,1,b,2*a,0,0):d[0]===l.CUBIC?l._flattenCubic(d[1],d[2],d[3],d[4],d[5],d[6],d[7],d[8],0,1,b,2*a,0,0):d[0]===l.ARC?l._flattenArc(d,0,1,b,2*a,0,0):d[0]!==l.CLOSE&&b.push([d[1],d[2],d[3],d[4]])}return b};l.prototype.toLinePath=function(a){var b=[],c=new l,d=null;if("undefined"===typeof a||null===a)a=1;var e;for(e=0;e<this.segments.length;e++){var f=this.segments[e];if(f[0]===l.CLOSE)c.closePath();else{var h=l._endPoint(f),g=l._startPoint(f);
d&&d[0]===g[0]&&d[1]===g[1]||c.moveTo(g[0],g[1]);d=h;b.splice(0,b.length);if(f[0]===l.QUAD)for(l._flattenQuad(f[1],f[2],f[3],f[4],f[5],f[6],0,1,b,2*a,0,0),f=0;f<b.length;f++)c.lineTo(b[f][2],b[f][3]);else if(f[0]===l.CUBIC)for(l._flattenCubic(f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],0,1,b,2*a,0,0),f=0;f<b.length;f++)c.lineTo(b[f][2],b[f][3]);else if(f[0]===l.ARC)for(l._flattenArc(f,0,1,b,2*a,0,0),f=0;f<b.length;f++)c.lineTo(b[f][2],b[f][3]);else f[0]!==l.CLOSE?c.lineTo(f[3],f[4]):c.closePath()}}return c};
l.prototype.toCurvePath=function(){var a=new l,b=null,c;for(c=0;c<this.segments.length;c++){var d=this.segments[c];if(d[0]===l.CLOSE)a.closePath();else{var e=l._endPoint(d),f=l._startPoint(d);b&&b[0]===f[0]&&b[1]===f[1]||a.moveTo(f[0],f[1]);b=e;if(d[0]===l.QUAD)a.quadraticCurveTo(d[3],d[4],d[5],d[6]);else if(d[0]===l.CUBIC)a.bezierCurveTo(d[3],d[4],d[5],d[6],d[7],d[8]);else if(d[0]===l.ARC)for(e=l._arcToBezierCurves(d[10],d[11],d[3],d[4],d[5],d[12],d[13]),d=0;d<e.length;d++)a.bezierCurveTo(e[d][2],
e[d][3],e[d][4],e[d][5],e[d][6],e[d][7]);else d[0]===l.LINE&&a.lineTo(d[3],d[4])}}return a};l._accBounds=function(a,b,c){0<=c&&1>=c&&(b=l._point(b,c),a[0]=Math.min(b[0],a[0]),a[1]=Math.min(b[1],a[1]),a[2]=Math.max(b[0],a[2]),a[3]=Math.max(b[1],a[3]))};l._accBoundsPoint=function(a,b,c){a[0]=Math.min(b,a[0]);a[1]=Math.min(c,a[1]);a[2]=Math.max(b,a[2]);a[3]=Math.max(c,a[3])};l._accBoundsArc=function(a,b,c,d,e,f,h,g){var k=Math.cos(g);g=0<=g&&6.283185307179586>g?3.141592653589793>=g?Math.sqrt(1-k*k):
-Math.sqrt(1-k*k):Math.sin(g);f=d*k*b-e*g*c+f;b=e*k*b+d*g*c+h;a[0]=Math.min(f,a[0]);a[1]=Math.min(b,a[1]);a[2]=Math.max(f,a[2]);a[3]=Math.max(b,a[3])};l._normAngleRadians=function(a){var b=2*Math.PI;return 0<=a?a<b?a:a%b:a%b+b};l._angleInRange=function(a,b,c){if(Math.abs(c-b)>=2*Math.PI)return!0;a=l._normAngleRadians(a);var d=l._normAngleRadians(b),e=l._normAngleRadians(c);return b===c?a===d:b<c?d<e?a>=d&&a<=e:a>=d||a<=e:e<d?a>=e&&a<=d:a>=e||a<=d};l.prototype.getBounds=function(){var a=Number.POSITIVE_INFINITY;
a=[a,a,-a,a];var b=!0,c;for(c=0;c<this.segments.length;c++){var d=this.segments[c];if(d[0]!==l.CLOSE){var e=l._endPoint(d),f=d[1],h=d[2],g=e[0],k=e[1];b?(a[0]=Math.min(f,g),a[1]=Math.min(h,k),a[2]=Math.max(f,g),a[3]=Math.max(h,k)):(a[0]=Math.min(f,g,a[0]),a[1]=Math.min(h,k,a[1]),a[2]=Math.max(f,g,a[2]),a[3]=Math.max(h,k,a[3]));b=!1;if(d[0]===l.QUAD){g=d[5];k=d[6];var m=f-2*d[3]+g;var p=h-2*d[4]+k;0!==m&&l._accBounds(a,d,(f-d[3])/m);0!==p&&l._accBounds(a,d,(h-d[4])/p)}else if(d[0]===l.CUBIC){g=d[7];
k=d[8];e=f-3*d[3]+3*d[5]-g;var n=h-3*d[4]+3*d[6]-k;if(0!==e||0!==n)m=f-2*d[3]+d[5],p=h-2*d[4]+d[6],f=d[3]*d[3]+d[5]*d[5]-d[5]*(f+d[3])+g*(f-d[3]),g=d[4]*d[4]+d[6]*d[6]-d[6]*(h+d[4])+k*(h-d[4]),0<=f&&0!==e&&(f=Math.sqrt(f),l._accBounds(a,d,(m-f)/e),l._accBounds(a,d,(m+f)/e)),0<=g&&0!==n&&(g=Math.sqrt(g),l._accBounds(a,d,(p-g)/n),l._accBounds(a,d,(p+g)/n))}else if(d[0]===l.ARC)if(p=d[3],n=d[4],h=d[10],e=d[11],m=d[12],f=d[13],g=d[5],Math.abs(f-m)>=2*Math.PI)p===n?(d=p,m=n):(d=Math.cos(g),g=0<=g&&6.283185307179586>
g?3.141592653589793>=g?Math.sqrt(1-d*d):-Math.sqrt(1-d*d):Math.sin(g),m=d*p,p*=g,f=-g*n,g=d*n,d=Math.sqrt(m*m+f*f),m=Math.sqrt(p*p+g*g)),l._accBoundsPoint(a,h+d,e+m),l._accBoundsPoint(a,h+d,e-m),l._accBoundsPoint(a,h-d,e+m),l._accBoundsPoint(a,h-d,e-m);else if(f!==m){d=Math.cos(g);g=0<=g&&6.283185307179586>g?3.141592653589793>=g?Math.sqrt(1-d*d):-Math.sqrt(1-d*d):Math.sin(g);k=[];if(0!==d&&0!==g){var q=Math.atan2(-n*g/d,p);k.push(q,q+Math.PI);q=Math.atan2(n*d/g,p);k.push(q,q+Math.PI)}else k.push(0,
Math.PI,.5*Math.PI,1.5*Math.PI);for(q=0;q<k.length;q++)l._angleInRange(k[q],m,f)&&l._accBoundsArc(a,p,n,d,g,h,e,k[q])}}}return a};l.prototype.reverse=function(){var a=0,b=0,c=!1,d=0,e=0,f=new l,h;for(h=this.segments.length-1;0<=h;h--){var g=this.segments[h],k=l._startPoint(g),m=l._endPoint(g);if(g[0]!==l.CLOSE){if(h===this.segments.length-1)f.moveTo(m[0],m[1]);else if(a!==m[0]||b!==m[1])c&&f.closePath(),c=!1,f.moveTo(m[0],m[1]);a=k[0];b=k[1]}if(g[0]===l.CLOSE){c&&f.closePath();c=!0;g=!1;var p;for(p=
h-1;0<=p&&this.segments[p][0]!==l.CLOSE;p--){k=l._startPoint(this.segments[p]);m=l._endPoint(this.segments[p]);if(g&&(d!==m[0]||e!==m[1]))break;d=k[0];e=k[1];g=!0}g&&(f.moveTo(d,e),m=l._endPoint(this.segments[h-1]),d===m[0]&&e===m[1]||f.lineTo(m[0],m[1]),a=m[0],b=m[1])}else g[0]===l.QUAD?f.quadraticCurveTo(g[3],g[4],g[1],g[2]):g[0]===l.CUBIC?f.bezierCurveTo(g[5],g[6],g[3],g[4],g[1],g[2]):g[0]===l.ARC?(k=g[13]-g[12],f.arcSvgTo(g[3],g[4],g[5]*l._toDegrees,Math.abs(k)>Math.PI,0>k,g[1],g[2])):g[0]===
l.LINE&&f.lineTo(g[1],g[2])}c&&f.closePath();return f};l._pushXY=function(a,b,c,d){d?0===a.length?a.push(b,c):(a[a.length-1]!==c||a[a.length-2]!==b)&&a.push(b,c):a.push(b,c)};l.prototype._getSubpaths=function(a,b){var c=[],d=[];if("undefined"===typeof a||null===a)a=1;var e=0,f=0,h=!0,g=null,k;for(k=0;k<this.segments.length;k++){var m=this.segments[k];var p=l._startPoint(m),n=l._endPoint(m);c.splice(0,c.length);if(m[0]!==l.CLOSE){if(h||e!==p[0]||f!==p[1])g=p,d.push(g),h=!1;e=n[0];f=n[1]}if(m[0]===
l.QUAD)for(l._flattenQuad(m[1],m[2],m[3],m[4],m[5],m[6],0,1,c,2*a,0,0),m=0;m<c.length;m++)l._pushXY(g,c[m][2],c[m][3],b);else if(m[0]===l.CUBIC)for(l._flattenCubic(m[1],m[2],m[3],m[4],m[5],m[6],m[7],m[8],0,1,c,2*a,0,0),m=0;m<c.length;m++)l._pushXY(g,c[m][2],c[m][3],b);else if(m[0]===l.ARC)for(l._flattenArc(m,0,1,c,2*a,0,0),m=0;m<c.length;m++)l._pushXY(g,c[m][2],c[m][3],b);else m[0]!==l.CLOSE&&l._pushXY(g,m[3],m[4],b)}return d};l._CurveList=function(a){y.prototype.constructor.apply(this,[(new G(a)).toArcLengthParam().fitRange(0,
1)]);this.curves=a};l._CurveList.prototype=Object.create(y.prototype);l._CurveList.prototype.constructor=l._CurveList;l._CurveList.prototype.getCurves=function(){return this.curves};l.prototype.interpolate=function(a,b){if(!a||a.segments.length!==this.segments.length)return null;var c=[],d=[],e=[],f=new l,h;for(h=0;h<this.segments.length;h++){var g=this.segments[h],k=a.segments[h],m=!1;if(g[0]!==l.CLOSE){var p=l._startPoint(g);n&&n[0]===p[0]&&n[1]===p[1]||(m=!0);var n=l._endPoint(g)}if(g[0]===l.QUAD){c[0]=
l.CUBIC;c[1]=g[1];c[2]=g[2];p=2*g[3];var q=2*g[4];c[3]=(g[1]+p)/3;c[4]=(g[2]+q)/3;c[5]=(g[5]+p)/3;c[6]=(g[6]+q)/3;c[7]=g[5];c[8]=g[6];g=c}k[0]===l.QUAD&&(d[0]=l.CUBIC,d[1]=k[1],d[2]=k[2],p=2*k[3],q=2*k[4],d[3]=(k[1]+p)/3,d[4]=(k[2]+q)/3,d[5]=(k[5]+p)/3,d[6]=(k[6]+q)/3,d[7]=k[5],d[8]=k[6],k=d);if(g[0]!==k[0])return null;switch(g[0]){case l.CLOSE:f.closePath();n=null;break;case l.LINE:case l.QUAD:case l.CUBIC:for(p=1;p<g.length;p++)e[p]=g[p]+(k[p]-g[p])*b;m&&f.moveTo(e[1],e[2]);g[0]===l.LINE?f.lineTo(e[3],
e[4]):g[0]===l.QUAD?f.quadraticCurveTo(e[3],e[4],e[5],e[6]):g[0]===l.CUBIC&&f.bezierCurveTo(e[3],e[4],e[5],e[6],e[7],e[8]);break;case l.ARC:q=g[13]-g[12];p=Math.abs(q)>Math.PI;var t=k[13]-k[12],u=Math.abs(t)>Math.PI;p=.5>b?p:u;q=.5>b?0<q:0<t;t=g[1]+(k[1]-g[1])*b;u=g[2]+(k[2]-g[2])*b;var v=g[3]+(k[3]-g[3])*b,x=g[4]+(k[4]-g[4])*b,r=g[5]+(k[5]-g[5])*b,w=g[8]+(k[8]-g[8])*b;g=g[9]+(k[9]-g[9])*b;m&&f.moveTo(t,u);f.arcSvgTo(v,x,r*l._toDegrees,p,q,w,g);break;default:return console.log("unknown kind"),null}}return f};
l._addSegment=function(a,b){0<a.length&&b instanceof R&&b.x1===b.x2&&b.y1===b.y2||a.push(b)};l.prototype.getCurves=function(){var a=[],b=[],c=0,d=0,e=0,f=0,h=!0,g=null,k;for(k=0;k<this.segments.length;k++){var m=this.segments[k],p=l._startPoint(m),n=l._endPoint(m);if(m[0]!==l.CLOSE){if(h||c!==p[0]||d!==p[1])g=[],a.push(g),e=p[0],f=p[1],h=!1;c=n[0];d=n[1];l._addSegment(g,l._segToCurve(m))}else l._addSegment(g,new R(c,d,e,f)),c=e,d=f}for(k=0;k<a.length;k++)b.push((new G(a[k])).toArcLengthParam().fitRange(0,
1));return new l._CurveList(b)};l.prototype.getSubpaths=function(){var a=[],b=0,c=0,d=!0,e=null,f;for(f=0;f<this.segments.length;f++){var h=this.segments[f],g=l._startPoint(h),k=l._endPoint(h);if(h[0]!==l.CLOSE){if(d||b!==g[0]||c!==g[1])e=(new l).moveTo(g[0],g[1]),a.push(e),d=!1;e.segments.push(h.slice(0,h.length));b=k[0];c=k[1];e.setEndPos(k[0],k[1])}else e.closePath()}return a};l.prototype.getLinePoints=function(a){a=this.getLines(a);var b=[],c=0,d=0,e;for(e=0;e<a.length;e++){var f=a[e];0!==e&&
c===f[0]&&d===f[1]||b.push([f[0],f[1]]);b.push([f[2],f[3]]);c=f[2];d=f[3]}return b};l.prototype.getLinePointsAsObjects=function(a){a=this.getLines(a);var b=[],c=0,d=0,e;for(e=0;e<a.length;e++){var f=a[e];0!==e&&c===f[0]&&d===f[1]||b.push({x:f[0],y:f[1]});b.push({x:f[2],y:f[3]});c=f[2];d=f[3]}return b};l.prototype.getPoints=function(a){if(1>a||0===this.segments.length)return[];if(1===a)return[this._start()];if(2===a)return[this._start(),this._end()];var b=this.getCurves(),c=[],d;for(d=0;d<a;d++){var e=
b.evaluate(d/(a-1));c.push([e[0],e[1]])}return c};l.prototype.getPointsAsObjects=function(a){if(1>a||0===this.segments.length)return[];if(1===a)return a=this._start(),[{x:a[0],y:a[1]}];if(2===a){a=this._start();var b=this._end();return[{x:a[0],y:a[1]},{x:b[0],y:b[1]}]}b=this.getCurves();var c=[],d;for(d=0;d<a;d++){var e=b.evaluate(d/(a-1));c.push({x:e[0],y:e[1]})}return c};l.prototype.closePath=function(){this.startPos[0]===this.endPos[0]&&this.startPos[1]===this.endPos[1]||this.lineTo(this.startPos[0],
this.startPos[1]);0<this.segments.length&&this.segments.push([l.CLOSE]);this.incomplete=!1;return this};l.prototype.moveTo=function(a,b){this.startPos[0]=a;this.startPos[1]=b;this.endPos[0]=a;this.endPos[1]=b;this.incomplete=!1;return this};l.prototype.lineTo=function(a,b){this.segments.push([l.LINE,this.endPos[0],this.endPos[1],a,b]);this.endPos[0]=a;this.endPos[1]=b;this.incomplete=!1;return this};l.prototype.setEndPos=function(a,b){this.endPos[0]=a;this.endPos[1]=b;return this};l.prototype.getCurrentPoint=
function(){return[this.endPos[0],this.endPos[1]]};l._areCollinear=function(a,b,c,d,e,f){c-=a;d-=b;var h=[e-a,f-b],g=c*c+d*d;if(0===g)return!0;h=(c*h[0]+d*h[1])/g;a=[a+h*c,b+h*d];e=[e-a[0],f-a[1]];return 0===e[0]*e[0]+e[1]*e[1]};l.prototype.arcTo=function(a,b,c,d,e){if(0>e)throw Error("IndexSizeError");var f=this.endPos[0],h=this.endPos[1];if(0===e||f===a&&h===b||a===c&&b===d||l._areCollinear(f,h,a,b,c,d))return this.lineTo(a,b);f=[f-a,h-b];h=1/Math.sqrt(f[0]*f[0]+f[1]*f[1]);f=[f[0]*h,f[1]*h];c=[c-
a,d-b];d=1/Math.sqrt(c[0]*c[0]+c[1]*c[1]);d=[c[0]*d,c[1]*d];c=f[0]*d[1]-f[1]*d[0];h=(1+(f[0]*d[0]+f[1]*d[1]))*e/Math.abs(c);f=[f[0]*h,f[1]*h];d=[d[0]*h,d[1]*h];f=[a+f[0],b+f[1]];a=[a+d[0],b+d[1]];this.lineTo(f[0],f[1]);return this.arcSvgTo(e,e,0,!1,0>c,a[0],a[1])};l.prototype.arc=function(a,b,c,d,e,f){return this._arcInternal(a,b,c,d,e,f,!0)};l.prototype._arcInternal=function(a,b,c,d,e,f,h){if(0>c)throw Error("IndexSizeError");var g=l._normAngleRadians(d),k=l._normAngleRadians(e),m=2*Math.PI,p=Math.cos(g),
n=Math.cos(k),q=a+c*p;p=b+c*(3.141592653589793>=g?Math.sqrt(1-p*p):-Math.sqrt(1-p*p));var t=a+c*n;n=b+c*(3.141592653589793>=k?Math.sqrt(1-n*n):-Math.sqrt(1-n*n));h&&this.lineTo(q,p);if(q===t&&p===n&&d===e||0===c)return this.lineTo(t,n);if(!f&&e-d>=m||f&&d-e>=m)return this._arcInternal(a,b,c,d,d+Math.PI,f,!1)._arcInternal(a,b,c,d+Math.PI,d+2*Math.PI,f,!1)._arcInternal(a,b,c,g,k,f,!1);h=e-d;if(h>=m||0>h){m=h%m;if(0===m&&0!==h)return this._arcInternal(a,b,c,d,d+Math.PI,f,!1)._arcInternal(a,b,c,d+Math.PI,
d+2*Math.PI,f,!1)._arcInternal(a,b,c,g,k,f,!1);h=m}a=!!(Math.abs(h)>Math.PI^!!f^d>e);d=!!(0<h^!!f^d>e);return this.lineTo(q,p).arcSvgTo(c,c,0,a,d,t,n)};l.prototype.quadraticCurveTo=function(a,b,c,d){this.segments.push([l.QUAD,this.endPos[0],this.endPos[1],a,b,c,d]);this.endPos[0]=c;this.endPos[1]=d;this.incomplete=!1;return this};l.prototype.bezierCurveTo=function(a,b,c,d,e,f){this.segments.push([l.CUBIC,this.endPos[0],this.endPos[1],a,b,c,d,e,f]);this.endPos[0]=e;this.endPos[1]=f;this.incomplete=
!1;return this};l._vecangle=function(a,b,c,d){var e=(a*c+b*d)/(Math.sqrt(a*a+b*b)*Math.sqrt(c*c+d*d));-1>e?e=-1:1<e&&(e=1);e=Math.acos(e);0>a*d-b*c&&(e=-e);return e};l._arcSvgToCenterParam=function(a){var b=a[1],c=a[2],d=a[8],e=a[9],f=a[3],h=a[4],g=a[5],k=.5*(b-d),m=.5*(c-e),p=Math.cos(g),n=0<=g&&6.283185307179586>g?3.141592653589793>=g?Math.sqrt(1-p*p):-Math.sqrt(1-p*p):Math.sin(g);g=p*k+n*m;k=p*m-n*k;m=f*f;var q=h*h,t=m*k*k+q*g*g;q=Math.sqrt(Math.max(0,(m*q-t)/t));m=f*k*q/h;q=h*g*q/f;a[6]===a[7]?
m=-m:q=-q;b=p*m-n*q+.5*(b+d);c=n*m+p*q+.5*(c+e);e=(g-m)/f;p=(k-q)/h;d=e/Math.sqrt(e*e+p*p);-1>d?d=-1:1<d&&(d=1);d=Math.acos(d);0>p&&(d=-d);f=l._vecangle(e,p,(-g-m)/f,(-k-q)/h);f=0>f?2*Math.PI+f:f;!a[7]&&0<f?f-=2*Math.PI:a[7]&&0>f&&(f+=2*Math.PI);return[b,c,d,f+d]};l._toRadians=Math.PI/180;l._toDegrees=180/Math.PI;l._arcToBezierCurves=function(a,b,c,d,e,f,h){var g=Math.cos(e);e=0<=e&&6.283185307179586>e?3.141592653589793>=e?Math.sqrt(1-g*g):-Math.sqrt(1-g*g):Math.sin(e);var k=Math.abs(h-f),m=16;k<
Math.PI/8?m=2:k<Math.PI/4?m=4:k<Math.PI/2?m=6:k<Math.PI&&(m=10);var p=(h-f)/m;h=[];k=Math.tan(.5*p);k=1/3*Math.sin(p)*(Math.sqrt(3*k*k+4)-1);p=2*Math.PI/m;var l=Math.cos(p);p=0<=p&&6.283185307179586>p?3.141592653589793>=p?Math.sqrt(1-l*l):-Math.sqrt(1-l*l):Math.sin(p);var n=Math.cos(f),t=0<=f&&6.283185307179586>f?3.141592653589793>=f?Math.sqrt(1-n*n):-Math.sqrt(1-n*n):Math.sin(f);for(f=0;f<m;f++){var u=l*t+p*n,v=l*n-p*t,x=u,r=v,w=[a+c*g*n-d*e*t,b+c*e*n+d*g*t],y=[a+c*g*r-d*e*x,b+c*e*r+d*g*x];n=[-c*
g*t-d*e*n,-c*e*t+d*g*n];x=[-c*g*x-d*e*r,-c*e*x+d*g*r];n=[w[0]+n[0]*k,w[1]+n[1]*k];x=[y[0]-x[0]*k,y[1]-x[1]*k];h.push([w[0],w[1],n[0],n[1],x[0],x[1],y[0],y[1]]);n=v;t=u}return h};l.prototype.arcSvgTo=function(a,b,c,d,e,f,h){if(0===a||0===b)return this.lineTo(f,h);var g=this.endPos[0],k=this.endPos[1];if(g===f&&k===h)return this;c=(0<=c&&360>c?c:c%360+(0>c?360:0))*l._toRadians;a=Math.abs(a);b=Math.abs(b);var m=.5*(g-f),p=.5*(k-h),n=Math.cos(c),q=0<=c&&6.283185307179586>c?3.141592653589793>=c?Math.sqrt(1-
n*n):-Math.sqrt(1-n*n):Math.sin(c),t=n*m+q*p;m=n*p-q*m;t=t*t/(a*a)+m*m/(b*b);1<t&&(t=Math.sqrt(t),a*=t,b*=t);a=[l.ARC,g,k,a,b,c,!!d,!!e,f,h];b=l._arcSvgToCenterParam(a);a[6]=null;a[7]=null;a[10]=b[0];a[11]=b[1];a[12]=b[2];a[13]=b[3];this.segments.push(a);this.endPos[0]=f;this.endPos[1]=h;this.incomplete=!1;return this};l._nextAfterWs=function(a,b){for(;b[0]<a.length;){var c=a.charCodeAt(b[0]);b[0]++;if(32!==c&&13!==c&&9!==c&&10!==c)return c}return-1};l._nextAfterSepReq=function(a,b){for(var c=!1,
d=!1;b[0]<a.length;){var e=a.charCodeAt(b[0]);b[0]++;if(32===e||13===e||9===e||10===e)d=!0;else{if(c||44!==e)return d?e:-1;c=d=!0}}return-1};l._nextAfterSep=function(a,b){for(var c=!1;b[0]<a.length;){var d=a.charCodeAt(b[0]);b[0]++;if(32!==d&&13!==d&&9!==d&&10!==d){if(c||44!==d)return d;c=!0}}return-1};l._peekNextNumber=function(a,b){var c=b[0],d=null!==l._nextNumber(a,b,!0);b[0]=c;return d};l._nextNumber=function(a,b,c){var d=b[0];c=c?l._nextAfterSep(a,b):l._nextAfterWs(a,b);var e=b[0]-1,f=!1,h=
!1,g=!1;if(46===c)f=!0;else if(48<=c&&57>=c)h=!0;else if(45!==c&&43!==c)return b[0]=d,null;for(;b[0]<a.length;)if(c=a.charCodeAt(b[0]),b[0]++,46===c){if(f)return b[0]=d,null;f=!0}else if(48<=c&&57>=c)h=!0;else if(69===c||101===c){if(!h)return b[0]=d,null;g=!0;break}else{if(!h)return b[0]=d,null;b[0]--;a=parseFloat(a.substr(e,b[0]-e));return Number.isNaN(a)?(b[0]=a,null):a===Number.POSITIVE_INFINITY||a===Number.NEGATIVE_INFINITY?0:a}if(g){c=a.charCodeAt(b[0]);if(0>c)return b[0]=d,null;b[0]++;h=!1;
if(48<=c&&57>=c)h=!0;else if(45!==c&&43!==c)return b[0]=d,null;for(;b[0]<a.length;)if(c=a.charCodeAt(b[0]),b[0]++,48<=c&&57>=c)h=!0;else{if(!h)return b[0]=d,null;b[0]--;a=parseFloat(a.substr(e,b[0]-e));return Number.isNaN(a)?(b[0]=d,null):a===Number.POSITIVE_INFINITY||a===Number.NEGATIVE_INFINITY?0:a}}if(!h)return b[0]=d,null;a=parseFloat(a.substr(e,a.length-e));return Number.isNaN(a)?(b[0]=d,null):a===Number.POSITIVE_INFINITY||a===Number.NEGATIVE_INFINITY?0:a};l.prototype.transform=function(a){var b=
new l,c=a[0],d=a[1],e=a[2],f=a[3],h=a[4];a=a[5];var g,k=[0],m=null;for(g=0;g<this.segments.length;g++){var p=this.segments[g];var n=!1;if(p[0]!==l.CLOSE){var q=l._startPoint(p);m&&m[0]===q[0]&&m[1]===q[1]||(n=!0);m=l._endPoint(p)}switch(p[0]){case l.CLOSE:b.closePath();m=null;break;case l.LINE:case l.QUAD:case l.CUBIC:for(q=1;q<p.length;q+=2)k[q]=c*p[q]+e*p[q+1]+h,k[q+1]=d*p[q]+f*p[q+1]+a;n&&b.moveTo(k[1],k[2]);p[0]===l.LINE?b.lineTo(k[3],k[4]):p[0]===l.QUAD?b.quadraticCurveTo(k[3],k[4],k[5],k[6]):
p[0]===l.CUBIC&&b.bezierCurveTo(k[3],k[4],k[5],k[6],k[7],k[8]);break;case l.ARC:if(1===c&&0===d&&0===e&&1===f){var t=p[13]-p[12];q=Math.abs(t)>Math.PI;n&&b.moveTo(p[1]+h,p[2]+a);b.arcSvgTo(p[3],p[4],p[5]*l._toDegrees,q,0<t,p[8]+h,p[9]+a)}else if(0===d&&0===e&&0===p[5])t=p[13]-p[12],q=Math.abs(t)>Math.PI,n&&b.moveTo(c*p[1]+h,f*p[2]+a),b.arcSvgTo(c*p[3],f*p[4],0,q,0<t,c*p[8]+h,f*p[9]+a);else for(t=l._arcToBezierCurves(p[10],p[11],p[3],p[4],p[5],p[12],p[13]),t[0][0]=p[1],t[0][1]=p[2],t[t.length-1][6]=
p[8],t[t.length-1][7]=p[9],q=0;q<t.length;q++){var u=t[q],v;for(v=0;8>v;v+=2){p=c*u[v]+e*u[v+1]+h;var r=d*u[v]+f*u[v+1]+a;u[v]=p;u[v+1]=r}n&&0===q&&b.moveTo(u[0],u[1]);b.bezierCurveTo(u[2],u[3],u[4],u[5],u[6],u[7])}}}return b};l.prototype.rect=function(a,b,c,d){return 0>c||0>d?this:this.moveTo(a,b).lineTo(a+c,b).lineTo(a+c,b+d).lineTo(a,b+d).closePath()};l.prototype.line=function(a,b,c,d){return this.moveTo(a,b).lineTo(c,d)};l.prototype.polyline=function(a,b){var c="undefined"!==typeof b&&null!==
b?b:!1;if(0===a.length)return this;if(0!==a.length%2)throw Error();this.moveTo(a[0],a[1]);var d;for(d=2;d<a.length;d+=2)this.lineTo(a[d],a[d+1]);c&&this.closePath();return this};l.prototype.roundRect=function(a,b,c,d,e,f){if(0>c||0>d)return this;e=Math.min(c,Math.max(0,e));f=Math.min(d,Math.max(0,f));var h=.5*e,g=.5*f;a+=h;this.moveTo(a,b);a+=c-e;this.lineTo(a,b);a+=h;b+=g;this.arcSvgTo(h,g,0,!1,!0,a,b);b+=d-f;this.lineTo(a,b);a-=h;b+=g;this.arcSvgTo(h,g,0,!1,!0,a,b);a-=c-e;this.lineTo(a,b);a-=h;
b-=g;this.arcSvgTo(h,g,0,!1,!0,a,b);b-=d-f;this.lineTo(a,b);this.arcSvgTo(h,g,0,!1,!0,a+h,b-g);this.closePath();return this};l.prototype.bevelRect=function(a,b,c,d,e,f){if(0>c||0>d)return this;e=Math.min(c,Math.max(0,e));f=Math.min(d,Math.max(0,f));var h=.5*e,g=.5*f;a+=h;this.moveTo(a,b);a+=c-e;this.lineTo(a,b);a+=h;b+=g;this.lineTo(a,b);b+=d-f;this.lineTo(a,b);a-=h;b+=g;this.lineTo(a,b);a-=c-e;this.lineTo(a,b);a-=h;b-=g;this.lineTo(a,b);b-=d-f;this.lineTo(a,b);this.lineTo(a+h,b-g);this.closePath();
return this};l.prototype.ellipse=function(a,b,c,d){if(0>c||0>d)return this;var e=.5*c;d*=.5;a+=e;return this.moveTo(a,b).arcSvgTo(e,d,0,!1,!0,a-c,b).arcSvgTo(e,d,0,!1,!0,a,b).closePath()};l.prototype.ellipseForBox=function(a,b,c,d){return this.ellipse(a+.5*c,b+.5*d,c,d)};l.prototype.arcShape=function(a,b,c,d,e,f,h){if(0>c||0>d)return this;var g=Math.PI/180,k=e+f;c*=.5;d*=.5;var m=(0<=k&&360>k?k:k%360+(0>k?360:0))*g,p=(0<=e&&360>e?e:e%360+(0>e?360:0))*g,l=Math.cos(m);m=3.141592653589793>=m?Math.sqrt(1-
l*l):-Math.sqrt(1-l*l);var n=Math.cos(p);this.moveTo(a+n*c,b+(3.141592653589793>=p?Math.sqrt(1-n*n):-Math.sqrt(1-n*n))*d);0<f?(p=e+180,e=180,f=!0):(p=e-180,e=-180,f=!1);for(;f?p<k:p>k;p+=e){n=(0<=p&&360>p?p:p%360+(0>p?360:0))*g;var t=Math.cos(n);this.arcSvgTo(c,d,0,!1,f,a+t*c,b+(3.141592653589793>=n?Math.sqrt(1-t*t):-Math.sqrt(1-t*t))*d)}this.arcSvgTo(c,d,0,!1,f,a+l*c,b+m*d);2===h?this.lineTo(a,b).closePath():1===h&&this.closePath();return this};l.prototype.arcShapeForBox=function(a,b,c,d,e,f,h){return this.arcShape(a+
.5*c,b+.5*d,c,d,e,f,h)};l.prototype.arrow=function(a,b,c,d,e,f,h){var g=c-a,k=d-b,m=Math.sqrt(g*g+k*k);if(0===m)return this;h*=.5;e*=.5;var p=1/m;g*=p;k*=p;f=Math.min(f,m);f=m-f;this.moveTo(a,b);this.lineTo(h*k+a,-h*g+b);this.lineTo(f*g+h*k+a,f*k-h*g+b);this.lineTo(f*g+e*k+a,f*k-e*g+b).lineTo(c,d);this.lineTo(f*g-e*k+a,f*k+e*g+b);this.lineTo(f*g-h*k+a,f*k+h*g+b);this.lineTo(-h*k+a,h*g+b);this.closePath();return this};l.prototype.regularPolygon=function(a,b,c,d,e){if(2>=c)return this;var f="undefined"===
typeof e||null===e?e:0;f=(0<=f&&360>f?f:f%360+(0>f?360:0))*n.ToRadians;var h=n.PiTimes2/c;e=Math.cos(h);h=3.141592653589793>=h?Math.sqrt(1-e*e):-Math.sqrt(1-e*e);var g=Math.cos(f);f=3.141592653589793>=f?Math.sqrt(1-g*g):-Math.sqrt(1-g*g);var k;for(k=0;k<c;k++){var m=a+g*d,p=b+f*d;0===k?this.moveTo(m,p):this.lineTo(m,p);m=e*g-h*f;f=e*f+h*g;g=m}return this.closePath()};l.prototype.regularStar=function(a,b,c,d,e,f){if(0>=c)return this;var h=f||0;h=(0<=h&&360>h?h:h%360+(0>h?360:0))*n.ToRadians;c*=2;var g=
n.PiTimes2/c;f=Math.cos(g);g=3.141592653589793>=g?Math.sqrt(1-f*f):-Math.sqrt(1-f*f);var k=Math.cos(h);h=3.141592653589793>=h?Math.sqrt(1-k*k):-Math.sqrt(1-k*k);var m;for(m=0;m<c;m++){var p=0===(m&1)?d:e,l=a+k*p;p=b+h*p;0===m?this.moveTo(l,p):this.lineTo(l,p);l=f*k-g*h;h=f*h+g*k;k=l}return this.closePath()};l.fromString=function(a){for(var b=[0],c=!1,d=new l,e=!1,f,h,g,k,m,p,n,q,t,u;!e&&b[0]<a.length;){var v=l._nextAfterWs(a,b);if(!c&&77!==v&&109!==v){e=!0;break}switch(v){case 90:case 122:d.closePath();
break;case 77:case 109:for(g=!1;;){k=109===v?d.endPos[0]:0;m=109===v?d.endPos[1]:0;p=l._nextNumber(a,b,g);if("undefined"===typeof p||null===p){g||(e=!0);break}n=l._nextNumber(a,b,!0);if("undefined"===typeof n||null===n){e=!0;break}g?d.lineTo(k+p,m+n):d.moveTo(k+p,m+n);g=!0}c=!0;break;case 76:case 108:for(g=!1;;){k=108===v?d.endPos[0]:0;m=108===v?d.endPos[1]:0;p=l._nextNumber(a,b,g);if("undefined"===typeof p||null===p){g||(e=!0);break}n=l._nextNumber(a,b,!0);if("undefined"===typeof n||null===n){e=
!0;break}d.lineTo(k+p,m+n);g=!0}break;case 72:case 104:for(g=!1;;){k=104===v?d.endPos[0]:0;p=l._nextNumber(a,b,g);if("undefined"===typeof p||null===p){g||(e=!0);break}d.lineTo(k+p,d.endPos[1]);g=!0}break;case 86:case 118:for(g=!1;;){k=118===v?d.endPos[1]:0;p=l._nextNumber(a,b,g);if("undefined"===typeof p||null===p){g||(e=!0);break}d.lineTo(d.endPos[0],k+p);g=!0}break;case 67:case 99:for(g=!1;;){k=99===v?d.endPos[0]:0;m=99===v?d.endPos[1]:0;p=l._nextNumber(a,b,g);if("undefined"===typeof p||null===
p){g||(e=!0);break}f=[];for(n=0;5>n;n++)if(f[n]=l._nextNumber(a,b,!0),"undefined"===typeof f[n]||null===f[n]){e=!0;break}if(e)break;n=f[0];g=f[1];q=f[2];d.bezierCurveTo(k+p,m+n,k+g,m+q,k+f[3],m+f[4]);g=!0}break;case 81:case 113:for(g=!1;;){k=113===v?d.endPos[0]:0;m=113===v?d.endPos[1]:0;p=l._nextNumber(a,b,g);if("undefined"===typeof p||null===p){g||(e=!0);break}n=l._nextNumber(a,b,!0);if("undefined"===typeof n||null===n){e=!0;break}g=l._nextNumber(a,b,!0);if("undefined"===typeof g||null===g){e=!0;
break}q=l._nextNumber(a,b,!0);if("undefined"===typeof q||null===q){e=!0;break}d.quadraticCurveTo(k+p,m+n,k+g,m+q);g=!0}break;case 65:case 97:for(g=!1;;){k=97===v?d.endPos[0]:0;m=97===v?d.endPos[1]:0;p=l._nextNumber(a,b,g);if("undefined"===typeof p||null===p){g||(e=!0);break}n=l._nextNumber(a,b,!0);if("undefined"===typeof n||null===n){e=!0;break}f=l._nextNumber(a,b,!0);if("undefined"===typeof f||null===f){e=!0;break}h=l._nextAfterSepReq(a,b);t=l._nextAfterSep(a,b);if(-1===h||-1===t){e=!0;break}g=l._nextNumber(a,
b,!0);if("undefined"===typeof g||null===g){e=!0;break}q=l._nextNumber(a,b,!0);if("undefined"===typeof q||null===q){e=!0;break}d.arcSvgTo(p+k,n+m,f,48!==h,48!==t,g+k,q+m);g=!0}break;case 83:case 115:for(g=!1;;){k=115===v?d.endPos[0]:0;m=115===v?d.endPos[1]:0;p=l._nextNumber(a,b,g);if("undefined"===typeof p||null===p){g||(e=!0);break}n=l._nextNumber(a,b,!0);if("undefined"===typeof n||null===n){e=!0;break}g=l._nextNumber(a,b,!0);if("undefined"===typeof g||null===g){e=!0;break}q=l._nextNumber(a,b,!0);
if("undefined"===typeof q||null===q){e=!0;break}t=d.endPos[0];u=d.endPos[1];f=d.endPos[0];h=d.endPos[1];0<d.segments.length&&d.segments[d.segments.length-1][0]===l.CUBIC&&(t=d.segments[d.segments.length-1][5],u=d.segments[d.segments.length-1][6]);d.bezierCurveTo(2*f-t,2*h-u,p+k,n+m,g+k,q+m);g=!0}break;case 84:case 116:for(g=!1;;){k=116===v?d.endPos[0]:0;m=116===v?d.endPos[1]:0;p=l._nextNumber(a,b,g);if("undefined"===typeof p||null===p){g||(e=!0);break}n=l._nextNumber(a,b,!0);if("undefined"===typeof n||
null===n){e=!0;break}t=d.endPos[0];u=d.endPos[1];f=d.endPos[0];h=d.endPos[1];0<d.segments.length&&d.segments[d.segments.length-1][0]===l.QUAD&&(t=d.segments[d.segments.length-1][3],u=d.segments[d.segments.length-1][4]);d.quadraticCurveTo(2*f-t,2*h-u,p+k,n+m);g=!0}break;default:return d.incomplete=!0,d}}e&&(d.incomplete=!0);return d};N._CONVEX=1;N._EAR=2;N._REFLEX=3;N._pointInTri=function(a,b,c,d){if(d[0]===a[0]&&d[1]===a[1]||d[0]===b[0]&&d[1]===b[1]||d[0]===c[0]&&d[1]===c[1])return!1;var e=b[0]-c[0],
f=b[1]-c[1],h=b[0]-a[0],g=b[1]-a[1],k=h*e+g*f;return 1E-9<Math.sqrt(Math.abs(h*h+g*g-k*k/(e*e+f*f)))?(e=V(b,c,d),f=V(b,c,a),h=0===e||0===f||e===f,e=V(a,c,d),f=V(a,c,b),h=h&&(0===e||0===f||e===f),e=V(a,b,d),f=V(a,b,c),h&&(0===e||0===f||e===f)):!1};N._Contour=function(a){this.vertexList=new ca;var b=a.length;4<=b&&a[0]===a[b-2]&&a[1]===a[b-1]&&(b-=2);var c=-1,d=-1,e=null,f=-1,h=Number.POSITIVE_INFINITY;h=[h,h,-h,-h];var g=!0;this.vertexCount=0;var k;for(k=0;k<b;k+=2){var m=a[k],p=a[k+1];if(!(0<k&&m===
c&&p===d)){c=m;d=p;this.vertexList.push([m,p]);if(!e||m>f)f=m,e=this.vertexList.last();g?(h[0]=h[2]=m,h[1]=h[3]=p,g=!1):(h[0]=Math.min(h[0],m),h[1]=Math.min(h[1],p),h[2]=Math.max(h[2],m),h[3]=Math.max(h[3],p));this.vertexCount++}}this.maxXNode=e;this.bounds=h;a=0;b=!0;c=-2;d=this.vertexList.first();e=this.vertexList.last().data;for(f=d.data;d;)h=d.next?d.next.data:f,g=d.prev?d.prev.data:e,b&&(g=V(g,d.data,h),-2!==c&&g!==c&&(b=!1),c=g),a+=d.data[0]*h[1]-d.data[1]*h[0],d=d.next;this.convex=b;this.winding=
0===a?0:0>a?-1:1};N._Contour.prototype.findVisiblePoint=function(a,b){var c=this.vertexList.first();if("undefined"===typeof c||null===c)return null;var d=this.bounds;if(a<d[0]||b<d[1]||a>d[2]||b>d[2])return null;d=this.vertexList.last();for(var e=c,f=[];c;){var h=c.next?c.next:e,g=c.data[0],k=h.data[0],m=c.data[1],p=h.data[1],n=Math.min(g,k),l=Math.min(m,p),t=Math.max(m,p);if(g===a&&m===b)return c;if(k===a&&p===b)return h;a<=Math.max(g,k)&&b>=l&&b<=t&&(m===p?f.push([n,n===c.data[0]?c:h,!0]):(m=a+
(b-m)/(p-m)*(k-g),m>=a&&(m===g?f.push([m,c,!0]):m===k?f.push([m,h,!0]):f.push([m,c,!1]))));c=c.next}if(0===f.length)return null;1<f.length&&(f=f.sort(function(a,b){return a[0]===b[0]?0:a[0]<b[0]?-1:1}));if(f[0][2])return f[0][1];c=f[0][1];c=c.next?c.next:e;h=[a,b];f=[f[0][0],b];g=e;for(k=[];g;)g!==c&&(m=V((g.prev?g.prev:d).data,g.data,(g.next?g.next:e).data),0!==m&&m!==this.winding&&N._pointInTri(h,f,c.data,g.data)&&(m=g.data[0]-h[0],p=g.data[1]-h[1],p=Math.sqrt(m*m+p*p),m/=p,-1>m&&(m=-1),1<m&&(m=
1),k.push([Math.acos(m),p,g]))),g=g.next;if(0===k.length)return c;1<k.length&&(k=k.sort(function(a,b){return a[0]===b[0]?a[1]===b[1]?0:a[1]<b[1]?-1:1:a[0]<b[0]?-1:1}));return k[0][2]};l.prototype.getTriangles=function(a){if("undefined"===typeof a||null===a)a=1;var b=this._getSubpaths(a,!0),c=[],d=[],e=0;a=[];var f;for(f=0;f<b.length;f++){var h=new N._Contour(b[f]);0<h.winding?(0===e&&(e=1),c.push(h)):0>h.winding&&(0===e&&(e=-1),d.push(h))}if(0===d.length||0===c.length)for(b=0===d.length?c:d,f=0;f<
b.length;f++)N._triangulate(b[f],a);else{b=0<e?c:d;d=0<e?d:c;for(f=0;f<d.length;f++)if(d[f])for(c=0;c<b.length;c++)if(b[c]&&(e=d[f].maxXNode,h=b[c].findVisiblePoint(e.data[0],e.data[1]))){b[c].vertexCount+=N._connectContours(d[f].vertexList,b[c].vertexList,e,h);d[f]=null;break}for(f=0;f<b.length;f++)N._triangulate(b[f],a);for(f=0;f<d.length;f++)N._triangulate(d[f],a)}return a};N._connectContours=function(a,b,c,d){for(var e=d,f=c,h=0;f;)e=b.insertAfter(f.data,e),f=f.next,h++;for(f=a.first();f!==c&&
"undefined"!==typeof f&&null!==f;)e=b.insertAfter(f.data,e),f=f.next,h++;e=b.insertAfter(c.data,e);b.insertAfter(d.data,e);b.convex=!1;return h+2};N._triangulate=function(a,b){var c;if(a&&!(3>a.vertexCount)&&0!==a.winding)if(3===a.vertexCount){var d=a.vertexList.first();for(c=[];d;)c.push(d.data[0],d.data[1]),d=d.next;b.push(c)}else{c=[];for(d=a.vertexList.first();d;)c.push([d.data[0],d.data[1]]),d=d.next;d=[];a.convex?d.push(c):3>c.length||(console.warn("not implemented"),d.push(c));if(0<c.length&&
0===d.length)throw Error();for(c=0;c<d.length;c++){var e=d[c],f;for(f=0;f<e.length-2;f++)b.push([e[0][0],e[0][1],e[f+1][0],e[f+1][1],e[f+2][0],e[f+2][1]])}}};var vb=function(a){this.comparer=a;this.nodes=[];this._size=0;this.size=function(){return this._size};this._compare=function(a,c){return this.comparer?this.comparer(a,c):a===c?0:a<c?-1:1};this.push=function(a){for(var b=this._size;0<b;){var d=(b-1)/2|0;if(0<this.comparer(a,this.nodes[d]))this.nodes[b]=this.nodes[d],b=d;else break}this.nodes[b]=
a;this._size+=1;return this};this.pop=function(){var a=null;if(0<this._size){var c=0;a=this.nodes[c];this._size--;for(var d=this.nodes[this._size];;){var e=1+2*c,f=2*(c+1);if(e<this._size)if(e=f>=this._size||0<this.comparer(this.nodes[e],this.nodes[f])?e:f,0>this.comparer(d,this.nodes[e]))this.nodes[c]=this.nodes[e],c=e;else break;else break}this.nodes[c]=d}return a}},aa=function(a){this.right=this.left=null;this.red=!0;this.p=null;this.data=a;this.link=function(a){return a?this.right:this.left};
this.copy=function(){var a=new aa(this.data);a.left=this.left;a.right=this.right;a.red=this.red;a.p=this.p;a.data=this.data;return a};this.setLink=function(a,c){a?this.right=c:this.left=c;"undefined"!==typeof c&&null!==c&&(c.p=this)};this.prev=function(){if("undefined"!==typeof this.left&&null!==this.left){for(var a=this.left;"undefined"!==typeof a.right&&null!==a.right;)a=a.right;return a}a=this.p;for(var c=this;"undefined"!==typeof a&&null!==a&&c===a.left;)c=a,a=a.p;return a};this.next=function(){if("undefined"!==
typeof this.right&&null!==this.right){for(var a=this.right;"undefined"!==typeof a.left&&null!==a.left;)a=a.left;return a}a=this.p;for(var c=this;"undefined"!==typeof a&&null!==a&&c===a.right;)c=a,a=a.p;return a}},z=function(a){this.comparer=a?a:z._defaultCompare;this.root=null;this._size=0;this.size=function(){return this._size}};z._defaultCompare=function(a,b){return a===b?0:a<b?-1:1};z.prototype.first=function(){var a=this.root;if("undefined"===typeof a||null===a)return null;for(;"undefined"!==
typeof a.left&&null!==a.left;)a=a.left;return a};z.prototype.last=function(){var a=this.root;if("undefined"===typeof a||null===a)return null;for(;"undefined"!==typeof a.right&&null!==a.right;)a=a.right;return a};z.prototype.find=function(a){for(var b=this.root;"undefined"!==typeof b&&null!==b;){var c=this.comparer(b.data,a);if(0===c)break;b=0>c?b.right:b.left}return"undefined"===typeof b||null===b?null:b.data};z._red=function(a){return"undefined"!==typeof a&&null!==a&&1===a.red};z._single=function(a,
b){var c=a.link(!b);a.setLink(!b,c.link(b));c.setLink(b,a);a.red=!0;c.red=!1;return c};z._double=function(a,b){a.setLink(!b,z._single(a.link(!b),!b));return z._single(a,b)};z.prototype.erase=function(a){if("undefined"!==typeof this.root&&null!==this.root){var b=new aa(null),c=null,d=!0;var e=b;var f=null;for(e.setLink(!0,this.root);null!==e.link(d);){var h=d;var g=f;f=e;e=e.link(d);var k=this.comparer(e.data,a);d=0>k;0===k&&(c=e);if(!z._red(e)&&!z._red(e.link(d)))if(z._red(e.link(!d)))f.setLink(h,
f=z._single(e,d));else if(!z._red(e.link(!d))&&(k=f.link(!h),"undefined"!==typeof k&&null!==k))if(z._red(k.link(!h))||z._red(k.link(h))){var m=g.right===f;z._red(k.link(h))?g.setLink(m,z._double(f,h)):z._red(k.link(!h))&&g.setLink(m,z._single(f,h));e.red=g.link(m).red=!1;g.link(m).left.red=!0;g.link(m).right.red=!0}else f.red=!1,k.red=!0,e.red=!0}"undefined"!==typeof c&&null!==c&&(c.data=e.data,f.setLink(f.right===e,e.link("undefined"===typeof e.left||null===e.left)));this.root=b.right;"undefined"!==
typeof this.root&&null!==this.root&&(this.root.p=null,this.root.red=!1);--this._size}};z.prototype.insert=function(a){if(!a)throw Error();if("undefined"===typeof this.root||null===this.root)a=this.root=new aa(a);else{var b=new aa(null),c,d=!1,e=!1;var f=b;var h=c=null;var g=this.root;for(f.setLink(!0,g);;){"undefined"===typeof g||null===g?c.setLink(d,g=new aa(a)):z._red(g.left)&&z._red(g.right)&&(g.red=!0,g.left.red=!1,g.right.red=!1);if(z._red(g)&&z._red(c)){var k=f.right===h;g===c.link(e)?f.setLink(k,
z._single(h,!e)):f.setLink(k,z._double(h,!e))}k=this.comparer(g.data,a);if(0===k){a=g;break}e=d;d=0>k;"undefined"!==typeof h&&null!==h&&(f=h);h=c;c=g;g=g.link(d)}this.root=b.right;"undefined"!==typeof this.root&&null!==this.root&&(this.root.p=null)}this.root.red=!1;++this._size;return a};var K=function(a,b){this.subpaths=[];this.contours=[];if("undefined"!==typeof a&&null!==a){this.subpaths=a._getSubpaths(b,!0);var c;for(c=0;c<this.subpaths.length;c++)this.contours[c]=new K._Contour(this.subpaths[c])}this.path=
a;this.getBounds=function(){return this.path.getBounds()};this.ncontours=function(){return this.subpaths.length};this.contour=function(a){return this.contours[a]};this.push=function(a){this.contours.push(a)};this.toPath=function(){var a=new l,b;for(b=0;b<this.contours.length;b++){var c=this.contours[b].vertices,h;for(h=0;h<c.length;h+=2)0===h?a.moveTo(c[h],c[h+1]):a.lineTo(c[h],c[h+1]);a.closePath()}return a}};K._Contour=function(a){this.vertices=a;this.nvertices=function(){return this.vertices.length/
2};this.segment=function(a){return a===this.nvertices()-1?[[this.vertices[2*a],this.vertices[2*a+1]],[this.vertices[0],this.vertices[1]]]:[[this.vertices[2*a],this.vertices[2*a+1]],[this.vertices[2*a+2],this.vertices[2*a+3]]]}};var r=function(a,b){this.eq=new vb(r.sweepEventCompNum);this.eventHolder=[];this.subject=a;this.clipping=b;this.nint=0};K.PointChain=function(){this.l=new ca;this._closed=!1;this.closed=function(){return this._closed};this.clear=function(){this.l.clear()};this.first=function(){return this.l.first()};
this.size=function(){return this.l.size()};this.init=function(a){this.l.push(a[0]).push(a[1])};this.linkSegment=function(a){return r._ptEq(a[0],this.l.front())?(r._ptEq(a[1],this.l.back())?this._closed=!0:this.l.unshift(a[1]),!0):r._ptEq(a[1],this.l.back())?(r._ptEq(a[0],this.l.front())?this._closed=!0:this.l.push(a[0]),!0):r._ptEq(a[1],this.l.front())?(r._ptEq(a[0],this.l.back())?this._closed=!0:this.l.unshift(a[0]),!0):r._ptEq(a[0],this.l.back())?(r._ptEq(a[1],this.l.front())?this._closed=!0:this.l.push(a[1]),
!0):!1}};K.PointChain.prototype.linkPointChain=function(a){return r._ptEq(a.l.front(),this.l.back())?(a.l.shift(),this.l.spliceToEnd(a.l),!0):r._ptEq(a.l.back(),this.l.front())?(this.l.shift(),this.l.spliceToBegin(a.l),!0):r._ptEq(a.l.front(),this.l.front())?(this.l.shift(),a.l.reverse(),this.l.spliceToBegin(a.l),!0):r._ptEq(a.l.back(),this.l.back())?(this.l.pop(),a.l.reverse(),this.l.spliceToEnd(a.l),!0):!1};ea.prototype.add=function(a){for(var b=this.openPolygons.first();b;){if(b.data.linkSegment(a)){if(b.data.closed())this.closedPolygons.spliceOneToEnd(this.openPolygons,
b);else for(a=b.next;a;){if(b.data.linkPointChain(a.data)){this.openPolygons.erase(a);break}a=a.next}return}b=b.next}b=new K.PointChain;b.init(a);this.openPolygons.push(b)};ea.prototype.toPolygon=function(){for(var a=new K(null,null),b=this.closedPolygons.first();b;){for(var c=new K._Contour([]),d=b.data.first();d;)c.vertices.push(d.data[0],d.data[1]),d=d.next;a.contours.push(c);b=b.next}return a};r.SweepEvent=function(a,b,c,d,e){this.p=a;this.id=-1;this.left=b;this.pl=c;this.other=d;this.type="undefined"===
typeof e||null===e?0:e;this.poss=null;this.inside=this.inOut=!1;this.segment=function(){return[this.p,this.other.p]};this.below=function(a){return this.left?0<r.signedArea(this.p,this.other.p,a):0<r.signedArea(this.other.p,this.p,a)};this.above=function(a){return!this.below(a)}};r.signedArea=function(a,b,c){return.5*((a[0]-c[0])*(b[1]-c[1])-(b[0]-c[0])*(a[1]-c[1]))};r._ptEq=function(a,b){return a[0]===b[0]&&a[1]===b[1]};r.sweepEventComp=function(a,b){return a.p[0]>b.p[0]?!0:b.p[0]>a.p[0]?!1:r._ptEq(a.p,
b.p)?a.left!==b.left?a.left:a.above(b.other.p):a.p[1]>b.p[1]};r.sweepEventCompNum=function(a,b){return a===b?0:r.sweepEventComp(a,b)?-1:1};r.segmentComp=function(a,b){return a===b?!1:0!==r.signedArea(a.p,a.other.p,b.p)||0!==r.signedArea(a.p,a.other.p,b.other.p)?r._ptEq(a.p,b.p)?a.below(b.other.p):r.sweepEventComp(a,b)?b.above(a.p):a.below(b.p):r._ptEq(a.p,b.p)?a.id<b.id:r.sweepEventComp(a,b)};r.segmentCompNum=function(a,b){return a===b?0:r.segmentComp(a,b)?-1:1};r.prototype.storeSweepEvent=function(a){a.id=
this.eventHolder.length;this.eventHolder.push(a);return a};r.prototype.compute=function(a){if(0===this.subject.ncontours()*this.clipping.ncontours())return 2===a?this.subject:1===a?0===this.subject.ncontours()?this.clipping:this.subject:new K(null,null);var b=new K(null,null);var c=this.subject.getBounds(),d=this.clipping.getBounds();var e=[c[0],c[1]];c=[c[2],c[3]];var f=[d[0],d[1]];d=[d[2],d[3]];if(e[0]>d[0]||f[0]>c[0]||e[1]>d[1]||f[1]>c[1]){if(2===a)return this.subject;if(1===a)for(b=this.subject,
e=0;e<this.clipping.ncontours();e++)b.push(this.clipping.contour(e));return b}for(e=0;e<this.subject.ncontours();e++)for(b=0;b<this.subject.contour(e).nvertices();b++)this.processSegment(this.subject.contour(e).segment(b),0);for(e=0;e<this.clipping.ncontours();e++)for(b=0;b<this.clipping.contour(e).nvertices();b++)this.processSegment(this.clipping.contour(e).segment(b),1);b=new z(r.segmentCompNum);var h,g;e=new ea;for(f=Math.min(c[0],d[0]);0<this.eq.size();){d=this.eq.pop();if(0===a&&d.p[0]>f||2===
a&&d.p[0]>c[0])break;if(1===a&&d.p[0]>f){for(d.left||e.add(d.segment());0<this.eq.size();)d=this.eq.pop(),d.left||e.add(d.segment());break}if(d.left){var k=b.insert(d);d.poss=k;if(!k)throw Error();if((g=h=k)&&!g.data)throw Error();h=h!==b.first()?h.prev():null;"undefined"===typeof h||null===h?d.inside=d.inOut=!1:0!==h.data.type?h===b.first()?(d.inside=!0,d.inOut=!1):(k=h,k=k.prev(),h.data.pl===d.pl?(d.inOut=!h.data.inOut,d.inside=!k.data.inOut):(d.inOut=!k.data.inOut,d.inside=!h.data.inOut)):d.pl===
h.data.pl?(d.inside=h.data.inside,d.inOut=!h.data.inOut):(d.inside=!h.data.inOut,d.inOut=h.data.inside);g=g.next();"undefined"!==typeof g&&null!==g&&this.possibleIntersection(d,g.data);"undefined"!==typeof h&&null!==h&&this.possibleIntersection(h.data,d)}else{g=h=k=d.other.poss;g=g.next();h=h!==b.first()?h.prev():null;switch(d.type){default:throw Error();case 0:switch(a){default:throw Error();case 0:d.other.inside&&e.add(d.segment());break;case 1:d.other.inside||e.add(d.segment());break;case 2:(0===
d.pl&&!d.other.inside||1===d.pl&&d.other.inside)&&e.add(d.segment());break;case 3:e.add(d.segment())}break;case 2:0!==a&&1!==a||e.add(d.segment());break;case 3:2===a&&e.add(d.segment())}b.erase(k.data);"undefined"!==typeof g&&null!==g&&"undefined"!==typeof h&&null!==h&&this.possibleIntersection(h.data,g.data)}}return e.toPolygon()};r.prototype.processSegment=function(a,b){if(!r._ptEq(a[0],a[1])){var c=this.storeSweepEvent(new r.SweepEvent(a[0],!0,b,null,0)),d=this.storeSweepEvent(new r.SweepEvent(a[1],
!0,b,c,0));c.other=d;c.p[0]<d.p[0]?d.left=!1:c.p[0]>d.p[0]?c.left=!1:c.p[1]<d.p[1]?d.left=!1:c.left=!1;this.eq.push(c);this.eq.push(d)}};r.findIntersection=function(a,b,c,d){a=r._findIntersectionInternal(a[0][0],a[0][1],a[1][0],a[1][1],b[0][0],b[0][1],b[1][0],b[1][1]);0<a.length&&(c[0]=a[0][0],c[1]=a[0][1]);1<a.length&&(d[0]=a[1][0],d[1]=a[1][1]);return a.length};r._findIntersectionInternal=function(a,b,c,d,e,f,h,g){var k=c-a,m=d-b,p=h-e,n=g-f,l=k*k+m*m,t=p*p+n*n,u=[];if(0===l)return 0===t?a===e&&
b===f&&u.push([a,b]):(k=((a-e)*p+(b-f)*n)/t,0<=k&&1>=k&&(m=[e+p*k,f+n*k],k=a-m[0],m=b-m[1],1E-9>=Math.sqrt(k*k+m*m)&&u.push([a,b]))),u;if(0===t)return c=((e-a)*k+(f-b)*m)/l,0<=c&&1>=c&&(b=[a+k*c,b+m*c],a=e-b[0],b=f-b[1],1E-9>=Math.sqrt(a*a+b*b)&&u.push([e,f])),u;l=k*n-p*m;t=e-a;var v=f-b;p=t*n-p*v;n=t*m-k*v;if(0===l){if(0===p&&0===n){u=(k*(e-a)+m*(f-b))/(k*k+m*m);f=(k*(h-a)+m*(g-b))/(k*k+m*m);if(0>=u&&1<=f||1<=u&&0>=f)return[[a,b],[c,d]];if(0>u&&0>f||1<u&&1<f)return[];if(0>=u&&0>=f)return[[a,b]];
if(1<=u&&1<=f)return[[c,d]];if(0>u||0>f)return u=Math.max(u,f),[[a,b],[a+k*u,b+m*u]];if(1<u||1<f)return e=Math.min(u,f),[[a+k*e,b+m*e],[c,d]];e=Math.min(u,f);u=Math.max(u,f);return[[a+k*e,b+m*e],[a+k*u,b+m*u]]}}else e=p/l,f=n/l,0<=e&&1>=e&&0<=f&&1>=f&&u.push([a+k*e,b+m*e]);return u};r.prototype.possibleIntersection=function(a,b){var c=[],d;if(d=r.findIntersection(a.segment(),b.segment(),c,[]))if(1!==d||!r._ptEq(a.p,b.p)&&!r._ptEq(a.other.p,b.other.p))if(2!==d||a.pl!==b.pl)1===d?(r._ptEq(a.p,c)||r._ptEq(a.other.p,
c)||this._divideSegment(a,c),r._ptEq(b.p,c)||r._ptEq(b.other.p,c)||this._divideSegment(b,c)):(c=[],r._ptEq(a.p,b.p)?c.push(null):r.sweepEventComp(a,b)?(c.push(b),c.push(a)):(c.push(a),c.push(b)),r._ptEq(a.other.p,b.other.p)?c.push(null):r.sweepEventComp(a.other,b.other)?(c.push(b.other),c.push(a.other)):(c.push(a.other),c.push(b.other)),2===c.length?(a.type=a.other.type=1,b.type=b.other.type=a.inOut===b.inOut?2:3):3===c.length?(c[1].type=c[1].other.type=1,c[0]?c[0].other.type=a.inOut===b.inOut?2:
3:c[2].other.type=a.inOut===b.inOut?2:3,this._divideSegment(c[0]?c[0]:c[2].other,c[1].p)):c[0]!==c[3].other?(c[1].type=1,c[2].type=a.inOut===b.inOut?2:3,this._divideSegment(c[0],c[1].p),this._divideSegment(c[1],c[2].p)):(c[1].type=c[1].other.type=1,this._divideSegment(c[0],c[1].p),c[3].other.type=a.inOut===b.inOut?2:3,this._divideSegment(c[3].other,c[2].p)))};r.prototype._divideSegment=function(a,b){var c=this.storeSweepEvent(new r.SweepEvent(b,!1,a.pl,a,a.type)),d=this.storeSweepEvent(new r.SweepEvent(b,
!0,a.pl,a.other,a.other.type));r.sweepEventComp(d,a.other)&&(a.other.left=!0,d.left=!1);r.sweepEventComp(a,c);a.other.other=d;a.other=c;this.eq.push(d);this.eq.push(c)};l.prototype.union=function(a,b){if("undefined"===typeof a||null===a)return this;var c=new K(this,b),d=new K(a,b);return(new r(c,d)).compute(1).toPath()};l.prototype.difference=function(a,b){if("undefined"===typeof a||null===a)return this;var c=new K(this,b),d=new K(a,b);return(new r(c,d)).compute(2).toPath()};l.prototype.intersection=
function(a,b){if("undefined"===typeof a||null===a)return this;var c=new K(this,b),d=new K(a,b);return(new r(c,d)).compute(0).toPath()};l.prototype.xor=function(a,b){if("undefined"===typeof a||null===a)return this;var c=new K(this,b),d=new K(a,b);return(new r(c,d)).compute(3).toPath()};var H=function(){this.scale=[1,1,1];this.position=[0,0,0];this.rotation=n.quatIdentity();this._matrixDirty=this.complexMatrix=!1;this._isIdentity=!0;this.matrix=n.mat4identity()};H.prototype.getScale=function(){return this.complexMatrix?
[this.matrix[0],this.matrix[5],this.matrix[10]]:this.scale.slice(0,3)};H.prototype.getPosition=function(){return this.complexMatrix?[this.matrix[12],this.matrix[13],this.matrix[14]]:this.position.slice(0,3)};H.prototype.getQuaternion=function(){return this.complexMatrix?n.quatNormalizeInPlace(n.quatFromMat4(this.matrix)):this.rotation.slice(0,4)};H.prototype.reset=function(){this.matrix=n.mat4identity();this.position=[0,0,0];this.scale=[1,1,1];this.rotation=n.quatIdentity();this._matrixDirty=this.complexMatrix=
!1;this._isIdentity=!0;return this};H.prototype.setMatrix=function(a){this._matrixDirty=!1;this.complexMatrix=!0;this.matrix=a.slice(0,16);this.position=[this.matrix[12],this.matrix[13],this.matrix[14]];this.rotation=n.quatFromMat4(this.matrix);this.rotation=n.quatNormalizeInPlace(this.rotation);this.scale=[this.matrix[0],this.matrix[5],this.matrix[10]];this._isIdentity=1===a[0]&&0===a[1]&&0===a[2]&&0===a[3]&&0===a[4]&&1===a[5]&&0===a[6]&&0===a[7]&&0===a[8]&&0===a[9]&&1===a[10]&&0===a[11]&&0===a[12]&&
0===a[13]&&0===a[14]&&1===a[15];return this};H.prototype.isIdentity=function(){if(this._matrixDirty)if(this.complexMatrix)this.getMatrix();else return 0===this.position[0]&&0===this.position[1]&&0===this.position[2]&&1===this.scale[0]&&1===this.scale[1]&&1===this.scale[2]&&n.quatIsIdentity(this.rotation);return this._isIdentity};H.prototype.setScale=function(a,b,c){if(this.complexMatrix)return this;this.scale="undefined"===typeof a||null===a||"undefined"!==typeof b&&null!==b||"undefined"!==typeof c&&
null!==c?[a,b,c]:"number"!==typeof a?[a[0],a[1],a[2]]:[a,a,a];this._isIdentity=this._isIdentity&&1===this.scale[0]&&1===this.scale[1]&&1===this.scale[2];this._matrixDirty=!0;return this};H.prototype.setPosition=function(a,b,c){if(this.complexMatrix)return this;this.position="undefined"===typeof a||null===a||"undefined"!==typeof b&&null!==b||"undefined"!==typeof c&&null!==c?[a,b,c]:"number"!==typeof a?[a[0],a[1],a[2]]:[a,a,a];this._isIdentity=this._isIdentity&&0===this.position[0]&&0===this.position[1]&&
0===this.position[2];this._matrixDirty=!0;return this};H.prototype.movePosition=function(a,b,c){if(this.complexMatrix)return this;"undefined"===typeof a||null===a||"undefined"!==typeof b&&null!==b||"undefined"!==typeof c&&null!==c?(this.position[0]+=a,this.position[1]+=b,this.position[2]+=c):"number"!==typeof a?(this.position[0]+=a[0],this.position[1]+=a[1],this.position[2]+=a[2]):(this.position[0]+=a,this.position[1]+=a,this.position[2]+=a);this._isIdentity=this._isIdentity&&0===this.position[0]&&
0===this.position[1]&&0===this.position[2];this._matrixDirty=!0;return this};H.prototype.setQuaternion=function(a){if(this.complexMatrix)return this;this.rotation=a.slice(0,4);n.quatNormalizeInPlace(this.rotation);this._matrixDirty=!0;return this};H.prototype.setRotation=function(a,b,c,d){return this.setQuaternion(n.quatFromAxisAngle(a,b,c,d))};H.prototype.multQuaternion=function(a){if(this.complexMatrix)return this;this.rotation=n.quatNormalizeInPlace(n.quatMultiply(this.rotation,a));this._matrixDirty=
!0;return this};H.prototype.multRotation=function(a,b,c,d){return this.multQuaternion(n.quatFromAxisAngle(a,b,c,d))};H.prototype.getMatrix=function(){if(this._matrixDirty)if(this._matrixDirty=!1,n.quatIsIdentity(this.rotation))this.matrix=[this.scale[0],0,0,0,0,this.scale[1],0,0,0,0,this.scale[2],0,this.position[0],this.position[1],this.position[2],1],this._isIdentity=0===this.position[0]&&0===this.position[1]&&0===this.position[2]&&1===this.scale[0]&&1===this.scale[1]&&1===this.scale[2];else{this.matrix=
[1,0,0,0,0,1,0,0,0,0,1,0,this.position[0],this.position[1],this.position[2],1];this.matrix=n.mat4multiply(this.matrix,n.quatToMat4(this.rotation));n.mat4scaleInPlace(this.matrix,this.scale);var a=this.matrix;this._isIdentity=1===a[0]&&0===a[1]&&0===a[2]&&0===a[3]&&0===a[4]&&1===a[5]&&0===a[6]&&0===a[7]&&0===a[8]&&0===a[9]&&1===a[10]&&0===a[11]&&0===a[12]&&0===a[13]&&0===a[14]&&1===a[15]}else if(this._isIdentity)return n.mat4identity();return this.matrix.slice(0,16)};H.prototype.copy=function(){var a=
new H;a.scale=this.scale.slice(0,this.scale.length);a.position=this.position.slice(0,this.scale.length);a.complexMatrix=this.complexMatrix;a._matrixDirty=this._matrixDirty;a.matrix=this.matrix.slice(0,this.matrix.length);return a};var F=function(){this._init()};F.prototype._init=function(){this.shapes=[];this.parent=null;this.visible=!0;this.transform=new H};F.prototype.shapeCount=function(){return this.shapes.length};F.prototype.getShape=function(a){return"undefined"===typeof this.shapes[a]?null:
this.shapes[a]};F.prototype.setShape=function(a,b){this.shapes[a]=b;return this};F.prototype.copy=function(){var a=new F;a.visible=this.visible;a.transform=this.transform.copy();var b;for(b=0;b<this.shapes.length;b++)a.addShape(this.shapes[b].copy());return a};F.prototype.addShape=function(a){if(!a)throw Error();a.parent=this;this.shapes.push(a);return this};F.prototype.setVisible=function(a){this.visible=!!a;return this};F.prototype.getVisible=function(){return this.visible};F.prototype.getTransform=
function(){return this.transform};F.prototype.getMatrix=function(){var a=this.getTransform(),b=a.isIdentity();if("undefined"!==typeof this.parent&&null!==this.parent){var c=this.parent.getMatrix();a=b?n.mat4multiply(c,a.getMatrix()):n.mat4isIdentity(c)?a.getMatrix():c}else a=a.getMatrix();return a};F.prototype.setTransform=function(a){this.transform=a.copy();return this};F.prototype.removeShape=function(a){var b;for(b=0;b<this.shapes.length;b++)this.shapes[b]===a&&(this.shapes.splice(b,1),b--);return this};
F.prototype.getBounds=function(){var a=Number.POSITIVE_INFINITY;a=[a,a,a,-a,-a,-a];var b=!0,c;for(c=0;c<this.shapes.length;c++){var d=this.shapes[c].getBounds();n.boxIsEmpty(d)||(b?(a[0]=d[0],a[1]=d[1],a[2]=d[2],a[3]=d[3],a[4]=d[4],a[5]=d[5],b=!1):(a[0]=Math.min(d[0],a[0]),a[1]=Math.min(d[1],a[1]),a[2]=Math.min(d[2],a[2]),a[3]=Math.max(d[3],a[3]),a[4]=Math.max(d[4],a[4]),a[5]=Math.max(d[5],a[5])))}return a};F.prototype.vertexCount=function(){var a=0,b;for(b=0;b<this.shapes.length;b++)a+=this.shapes[b].vertexCount();
return a};F.prototype.primitiveCount=function(){var a=0,b;for(b=0;b<this.shapes.length;b++)a+=this.shapes[b].primitiveCount();return a};F.prototype.setPosition=function(a,b,c){this.transform.setPosition(a,b,c);return this};F.prototype.setQuaternion=function(a){this.transform.setQuaternion(a);return this};F.prototype.setScale=function(a,b,c){this.transform.setScale(a,b,c);return this};var A={lineStripIndices:function(a){var b=[];if(2<=a){var c;for(c=1;c<a;c++)b.push(c-1,c)}return b},lineLoopIndices:function(a){var b=
[];if(2<=a){var c;for(c=1;c<a;c++)b.push(c-1,c);b.push(a-1,0)}return b},triangleFanIndices:function(a){var b=[];if(3<=a){var c;for(c=2;c<a;c++)b.push(0,c-1,c)}return b},triangleStripIndices:function(a){var b=[];if(3<=a){var c;for(c=2;c<a;c++)b.push(c-1,c-2,c)}return b},quadsIndices:function(a){var b=[];if(4<=a){var c;for(c=3;c<a;c+=4)b.push(c-3,c-2,c,c,c-2,c-1)}return b},quadStripIndices:function(a){var b=[];if(4<=a){var c;for(c=3;c<a;c+=2)b.push(c-3,c-2,c-1,c-1,c-2,c)}return b}},la=function(a){this.indices=
a;this.last=this.start=-1;this.addIndex=function(a){0>this.start?this.start=a:(0>this.last||(this.indices.push(this.start),this.indices.push(this.last),this.indices.push(a)),this.last=a)}};A.setColor=function(a,b,c,d,e){c=Y(c,d,e);d=[];for(var f=e=0;f<b.index.count;f++,e+=3)d[e]=c[0],d[e+1]=c[1],d[e+2]=c[2];b.setAttribute("color",new a.BufferAttribute(new Float32Array(d),3));return b};A.reverseWinding=function(a){var b=a.index.array;if(0!=b.length%3)throw Error();for(var c=0;c<b.length;c+=3){var d=
b[c+1];b[c+1]=b[c+2];b[c+2]=d}return a};A.recalcNormals=function(a,b){a.computeVectorNormals();if(b){var c=a.getAttribute("normal");if(c)for(var d=0;d<c.count;d++)c.setX(d,-c.getX(d)),c.setY(d,-c.getY(d)),c.setZ(d,-c.getZ(d))}return a};A.fromPositions=function(a,b,c){if(!a.BufferGeometry)return null;if(!c){c=[];for(var d=0;d<b.length/3|0;d++)c[d]=d}d=new a.BufferGeometry;b=new a.InterleavedBuffer(new Float32Array(b),3);b=new a.InterleavedBufferAttribute(b,3,0);d.setAttribute("position",b);d.index=
new a.BufferAttribute(new Uint32Array(c),1);return d};A.fromPositionsAutoNormals=function(a,b,c){return A.recalcNormals(A.fromPositions(a,b,c),!1)};A.fromPositionsNormals=function(a,b,c){return ia(a,b,c,"position","normal")};A.fromPositionsColors=function(a,b,c){return ia(a,b,c,"position","color")};A.fromPositionsNormalsUV=function(a,b,c){if(!a.BufferGeometry)return null;var d=new a.BufferGeometry,e=new a.InterleavedBuffer(new Float32Array(b),8);b=new a.InterleavedBufferAttribute(e,3,0);d.setAttribute("position",
b);b=new a.InterleavedBufferAttribute(e,3,3);d.setAttribute("normal",b);b=new a.InterleavedBufferAttribute(e,2,6);d.setAttribute("uv",b);d.index=new a.BufferAttribute(new Uint32Array(c),1);return d};A.createBox=function(a,b,c,d,e){b*=.5;c*=.5;d*=.5;return A.createBoxEx(a,[-b,-c,-d,b,c,d],e)};A.createBoxEx=function(a,b,c){if(!b)throw Error();var d=n.boxDimensions(b);if(0>d[0]||0>d[1]||0>d[2])throw Error();d=c?-1:1;c=c?1:-1;return A.fromPositionsNormalsUV(a,[b[0],b[1],b[5],c,0,0,1,0,b[0],b[4],b[5],
c,0,0,1,1,b[0],b[4],b[2],c,0,0,0,1,b[0],b[1],b[2],c,0,0,0,0,b[3],b[1],b[2],d,0,0,1,0,b[3],b[4],b[2],d,0,0,1,1,b[3],b[4],b[5],d,0,0,0,1,b[3],b[1],b[5],d,0,0,0,0,b[3],b[1],b[2],0,c,0,1,0,b[3],b[1],b[5],0,c,0,1,1,b[0],b[1],b[5],0,c,0,0,1,b[0],b[1],b[2],0,c,0,0,0,b[3],b[4],b[5],0,d,0,1,0,b[3],b[4],b[2],0,d,0,1,1,b[0],b[4],b[2],0,d,0,0,1,b[0],b[4],b[5],0,d,0,0,0,b[0],b[1],b[2],0,0,c,1,0,b[0],b[4],b[2],0,0,c,1,1,b[3],b[4],b[2],0,0,c,0,1,b[3],b[1],b[2],0,0,c,0,0,b[3],b[1],b[5],0,0,d,1,0,b[3],b[4],b[5],0,
0,d,1,1,b[0],b[4],b[5],0,0,d,0,1,b[0],b[1],b[5],0,0,d,0,0],[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23])};A.createCylinder=function(a,b,c,d,e,f,h,g){if("undefined"===typeof e||null===e)e=32;if("undefined"===typeof f||null===f)f=1;if(2>=e)throw Error("too few slices");if(1>f)throw Error("too few stacks");if(0>d)throw Error("negative height");if(0>=b&&0>=c||0===d)return new a.BufferGeometry;var k=g?-1:1,m=[],p=[],l=n.PiTimes2/e,q=Math.cos(l);l=3.141592653589793>=
l?Math.sqrt(1-q*q):-Math.sqrt(1-q*q);var t=1,u=0,v;for(v=0;v<e;v++){var r=1*v/e;m.push(t,u);p.push(r);r=q*t+l*u;u=q*u-l*t;t=r}m.push(m[0],m[1]);p.push(1);if(0<d){b===c?(l=0,q=k):(l=b-c,q=d,t=Math.sqrt(q*q+l*l),0!==t&&(t=1/t,l*=t,q*=t),q*=k,l*=k);k=1/f;t=[];for(u=0;u<=f;u++){v=u===f?1:u*k;r=d*v;var w=b+(c-b)*v,y;for(y=0;y<=e;y++){var z=m[2*y],C=m[2*y+1];t.push(z*w,C*w,r,z*q,C*q,l,1-p[y],v)}}a=X(a,t,e+1,f+1);return h?A.recalcNormals(a.toNonIndexed(),g):a}return A.fromPositionsNormalsUV(a,[],[])};A.createLathe=
function(a,b,c,d,e){if(4>b.length)throw Error("too few points");if("undefined"===typeof c||null===c)c=32;if(2>=c)throw Error("too few slices");if(0!==b.length%1)throw Error("points array length is not an even number");var f;for(f=0;f<b.length;f+=2)if(0>b[f<<1])throw Error("point's x is less than 0");var h=[],g=[];f=n.PiTimes2/c;var k=Math.cos(f),m=3.141592653589793>=f?Math.sqrt(1-k*k):-Math.sqrt(1-k*k),p=1,l=0;for(f=0;f<c;f++){var q=1*f/c;h.push(p,l);g.push(q);q=k*p+m*l;l=k*l-m*p;p=q}h.push(h[0],
h[1]);g.push(1);k=b.length/2-1;m=1/k;p=[];for(f=0;f<=k;f++){l=f===k?1:f*m;var t=f<<1;q=b[t+1];t=b[t];var u;for(u=0;u<=c;u++)p.push(h[2*u]*t,h[2*u+1]*t,q,0,0,0,1-g[u],l)}a=X(a,p,c+1,k+1);return A.recalcNormals(d?a.toNonIndexed():a,e)};A.createClosedCylinder=function(a,b,c,d,e,f,h,g){f=A.createCylinder(a.THREE,b,c,d,e,f,h,g);b=A.reverseWinding(A.createDisk(a.THREE,0,b,e,2,!g));c=A.createDisk(a.THREE,0,c,e,2,g);c.applyMatrix4(ub(a.THREE,n.mat4translated(0,0,d)));return a.BufferGeometryUtils.mergeGeometries([f,
b,c],!1)};A.createDisk=function(a,b,c,d,e,f){return A.createPartialDisk(a,b,c,d,e,0,360,f)};A.createPartialDisk=function(a,b,c,d,e,f,h,g){if("undefined"===typeof d||null===d)d=32;if("undefined"===typeof e||null===e)e=1;if("undefined"===typeof f||null===f)f=0;if("undefined"===typeof h||null===h)h=360;if(2>=d)throw Error("too few slices");if(1>e)throw Error("too few loops");if(b>c)throw Error("inner greater than outer");0>b&&(b=0);0>c&&(c=0);if(0===c||0===h)return new a.BufferGeometry;var k=360===h&&
0===f,m=0>h?-1:1;0>h&&(h=-h);h%=360;0===h&&(h=360);var l=[],r=[],q=n.PiTimes2,t=360===h?q:h*n.PiDividedBy180;f*=n.PiDividedBy180;0>m&&(t=-t);var u=t/d;m=Math.cos(u);u=0<=u&&6.283185307179586>u?3.141592653589793>=u?Math.sqrt(1-m*m):-Math.sqrt(1-m*m):Math.sin(u);var v=Math.cos(f),x=0<=f&&6.283185307179586>f?3.141592653589793>=f?Math.sqrt(1-v*v):-Math.sqrt(1-v*v):Math.sin(f),w=v,y=x;for(f=0;f<=d;f++){f===d&&t===q?l.push(y,w):l.push(x,v);r.push(1*f/d);var z=m*x+u*v;v=m*v-u*x;x=z}k&&(l[0]=0,l[1]=1,l[l.length-
1]=1,l[l.length-2]=0,r[0]=0,r[r.length-1]=1);r=g?-1:1;g=360===h?d:d+1;if(0===b&&1===e&&360===h){k=[];e=[];b=new la(e);h=c;m=h/c;for(t=0;t<d;t++)c=l[2*t],q=l[2*t+1],k.push(c*h,q*h,0,0,0,r,.5*(1+c*m),.5*(1+q*m)),b.addIndex(t);k.push(0,0,0,0,0,r,.5,.5);b.addIndex(0);console.log("cc=["+k+"]");console.log("cv=["+e+"]");return A.fromPositionsNormalsUV(a,k,e)}d=c-b;v=1/c;k=[];for(f=0;f<=e;f++)for(u=b+f/e*d,m=u*v,t=0;t<g;t++)c=l[2*t],q=l[2*t+1],k.push(c*u,q*u,0,0,0,r,.5*(1+c*m),.5*(1+q*m));if(360===h){l=
k;e+=1;b=[];for(d=0;d<e-1;d++)for(h=0;h<g;h++)c=d*g+h,f=c+g,k=h===g-1?d*g:c+1,r=h===g-1?(d+1)*g:f+1,b.push(c,f,k),b.push(k,f,r);a=A.fromPositionsNormalsUV(a,l,b)}else a=X(a,k,g,e+1);return a};A.createTorus=function(a,b,c,d,e,f,h){if("undefined"===typeof e||null===e)e=16;if("undefined"===typeof d||null===d)d=16;if(3>e)throw Error("crosswise is less than 3");if(3>d)throw Error("lengthwise is less than 3");if(0>b||0>c)throw Error("inner or outer is less than 0");if(0===c||0===b)return new a.BufferGeometry;
var g=[],k=[],m=n.PiTimes2/e;var l=Math.cos(m);m=0<=m&&6.283185307179586>m?3.141592653589793>=m?Math.sqrt(1-l*l):-Math.sqrt(1-l*l):Math.sin(m);var r=0;var q=1;var t;for(t=0;t<e;t++){g.push(r,q);var u=l*r+m*q;q=l*q-m*r;r=u}g.push(g[0]);g.push(g[1]);m=n.PiTimes2/d;l=Math.cos(m);m=0<=m&&6.283185307179586>m?3.141592653589793>=m?Math.sqrt(1-l*l):-Math.sqrt(1-l*l):Math.sin(m);r=0;q=1;for(t=0;t<d;t++)k.push(r,q),u=l*r+m*q,q=l*q-m*r,r=u;k.push(k[0]);k.push(k[1]);m=[];for(t=0;t<=d;t++){q=t/d;r=k[2*t];u=k[2*
t+1];var v;for(v=0;v<=e;v++){l=v/e;var x=g[2*v],w=g[2*v+1];m.push(w*(c+u*b),x*(c+u*b),r*b,u*w,u*x,r,l,q)}}a=X(a,m,e+1,d+1);return f?A.recalcNormals(a.toNonIndexed(),h):a};A.createPlane=function(a,b,c,d,e,f){if("undefined"===typeof b||null===b)b=1;if("undefined"===typeof c||null===c)c=1;if("undefined"===typeof d||null===d)d=1;if("undefined"===typeof e||null===e)e=1;if(0>b||0>c)throw Error("width or height is less than 0");if(0>=e||0>=d)throw Error("widthDiv or heightDiv is 0 or less");if(0===b||0===
c)return new a.BufferGeometry;var h=.5*-b,g=.5*-c;f=f?-1:1;var k=[],l;for(l=0;l<=e;l++){var n=l/e,r=g+c*n,q;for(q=0;q<=d;q++){var t=q/d;k.push(h+b*t,r,0,0,0,f,t,n)}}return X(a,k,d+1,e+1)};A.createSphere=function(a,b,c,d,e,f){return A._createCapsule(a,b,0,c,d,1,e,f)};A.createCapsule=function(a,b,c,d,e,f,h,g){if("undefined"===typeof e||null===e)e=8;if(1>e)throw Error("too few stacks");return A._createCapsule(a,b,c,d,2*e,f,h,g)};A._createCapsule=function(a,b,c,d,e,f,h,g){if("undefined"===typeof d||null===
d)d=16;if("undefined"===typeof e||null===e)e=16;if("undefined"===typeof f||null===f)f=1;if("undefined"===typeof b||null===b)b=1;if("undefined"===typeof c||null===c)c=1;if(2>e)throw Error("too few stacks");if(2>=d)throw Error("too few slices");if(1>f&&0<c)throw Error("too few middle stacks");if(0>c)throw Error("negative length");if(0>b)throw Error("negative radius");if(0===b)return new a.BufferGeometry;var k,l=.5*c,p=e/2,r=g?-1:1,q=[],t=[],u=[],v=[],x=n.PiTimes2/d,w=Math.cos(x),y=0<=x&&6.283185307179586>
x?3.141592653589793>=x?Math.sqrt(1-w*w):-Math.sqrt(1-w*w):Math.sin(x);var z=1;for(x=k=0;x<d;x++){var C=1*x/d;q.push(z,k);v.push(C);C=w*k-y*z;z=w*z+y*k;k=C}q.push(q[0],q[1]);v.push(1);C=2*b;C/=C+c;var D=[];D.push(-1);t.push(0);u.push(0);x=Math.PI/e;w=Math.cos(x);z=y=0<=x&&6.283185307179586>x?3.141592653589793>=x?Math.sqrt(1-w*w):-Math.sqrt(1-w*w):Math.sin(x);k=w;for(x=0;x<e;x++){var B=1*(x+1)/e;t.push(z);D.push(-k);u.push(B);B=w*z+y*k;k=w*k-y*z;z=B}w=[];for(x=B=0;x<=e;x++){var E=u[x],F=b*D[x];var H=
x<p?-l:l;var G=b*t[x];B++;var I;for(I=0;I<=d;I++)z=v[I],y=q[2*I],k=q[2*I+1],w.push(y*G,k*G,F+H,y*G*r,k*G*r,F*r,1-z,E);if(x+1===p&&0<c){I=.5*C;var K=2*l,L=1-C,M;for(M=0;M<=f;M++){H=-l+(0===M?0:K*M/f);E=I+(0===M?0:L*M/f);B++;var J;for(J=0;J<=d;J++)z=v[J],y=q[2*J],k=q[2*J+1],w.push(y*G,k*G,F+H,y*G*r,k*G*r,F*r,1-z,E)}}}a=X(a,w,d+1,B);if(!a)throw Error();h?h=A.recalcNormals(a.toNonIndexed(),g):(a.normalizeNormals(),h=a);return h};A.createPointedStar=function(a,b,c,d,e){if(2>b||0>c||0>d||0>=c&&0>=d)return new a.BufferGeometry;
if(c===d)return A.createDisk(a,c,c,b,1,e);var f=[],h=[],g=new la(h),k=0,l=1/Math.max(c,d);e=e?-1:1;f.push(0,0,0,0,0,e,.5,.5);g.addIndex(k++);var p=n.PiTimes2/(2*b),r=Math.cos(p);p=3.141592653589793>=p?Math.sqrt(1-r*r):-Math.sqrt(1-r*r);var q=0,t=1,u;for(u=0;u<2*b;u++){var v=0===(u&1)?c:d,w=-q*v;v*=t;f.push(w,v,0,0,0,e,.5*(1+w*l),.5*(1+v*l));g.addIndex(k);w=r*t-p*q;q=r*q+p*t;t=w}g.addIndex(1);return A.fromPositionsNormalsUV(a,f,h)};D.BSplineCurve=w;D.BSplineSurface=L;D.Curve=y;D.CurveBuilder=C;D.GraphicsPath=
l;D.MathUtil=n;D.MeshBuffer=I;D.Meshes=A;D.PiecewiseCurve=G;D.ShapeGroup=F;D.Surface=J;D.SurfaceBuilder=E;D.Transform=H;D.getPromiseResults=ja;D.getPromiseResultsAll=function(a,b,c){return ja(a,b,c).then(function(a){return 0<a.failures.length?Promise.reject(a):Promise.resolve(a.successes)})};D.getTimePosition=function(a,b,c){if("undefined"===typeof a.time||null===a.time)return a.time=b,a.lastTime=b,0;if("undefined"===typeof a.lastTime||null===a.lastTime)a.lastTime=b;return(b-a.time)%c/c};D.newFrames=
function(a,b){if("undefined"===typeof a.time||null===a.time)return a.time=b,a.lastTime=b,0;if("undefined"===typeof a.lastTime||null===a.lastTime)return a.lastTime=b,0;var c=b-a.lastTime;a.lastTime=b;return 60*c/1E3};D.toGLColor=Y});