three-text 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * three-text v0.2.3
2
+ * three-text v0.2.4
3
3
  * Copyright (C) 2025 Countertype LLC
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
@@ -1993,2066 +1993,102 @@
1993
1993
  }
1994
1994
  }
1995
1995
 
1996
- var WINDING;
1997
- (function (WINDING) {
1998
- WINDING[WINDING["ODD"] = 0] = "ODD";
1999
- WINDING[WINDING["NONZERO"] = 1] = "NONZERO";
2000
- WINDING[WINDING["POSITIVE"] = 2] = "POSITIVE";
2001
- WINDING[WINDING["NEGATIVE"] = 3] = "NEGATIVE";
2002
- WINDING[WINDING["ABS_GEQ_TWO"] = 4] = "ABS_GEQ_TWO";
2003
- })(WINDING || (WINDING = {}));
2004
- var ELEMENT;
2005
- (function (ELEMENT) {
2006
- ELEMENT[ELEMENT["POLYGONS"] = 0] = "POLYGONS";
2007
- ELEMENT[ELEMENT["CONNECTED_POLYGONS"] = 1] = "CONNECTED_POLYGONS";
2008
- ELEMENT[ELEMENT["BOUNDARY_CONTOURS"] = 2] = "BOUNDARY_CONTOURS";
2009
- })(ELEMENT || (ELEMENT = {}));
1996
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2010
1997
 
2011
- function assert(cond, message) {
2012
- if (!cond) {
2013
- throw message || "Assertion Failed!";
2014
- }
1998
+ function getDefaultExportFromCjs (x) {
1999
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
2015
2000
  }
2016
2001
 
2017
- var Geom = (function () {
2018
- function Geom() {
2019
- }
2020
- Geom.vertEq = function (u, v) {
2021
- return u.s === v.s && u.t === v.t;
2022
- };
2023
- Geom.vertLeq = function (u, v) {
2024
- return u.s < v.s || (u.s === v.s && u.t <= v.t);
2025
- };
2026
- Geom.transLeq = function (u, v) {
2027
- return u.t < v.t || (u.t === v.t && u.s <= v.s);
2028
- };
2029
- Geom.edgeGoesLeft = function (e) {
2030
- return Geom.vertLeq(e.Dst, e.Org);
2031
- };
2032
- Geom.edgeGoesRight = function (e) {
2033
- return Geom.vertLeq(e.Org, e.Dst);
2034
- };
2035
- Geom.vertL1dist = function (u, v) {
2036
- return Math.abs(u.s - v.s) + Math.abs(u.t - v.t);
2037
- };
2038
- Geom.edgeEval = function (u, v, w) {
2039
- assert(Geom.vertLeq(u, v) && Geom.vertLeq(v, w));
2040
- var gapL = v.s - u.s;
2041
- var gapR = w.s - v.s;
2042
- if (gapL + gapR > 0.0) {
2043
- if (gapL < gapR) {
2044
- return v.t - u.t + (u.t - w.t) * (gapL / (gapL + gapR));
2045
- }
2046
- else {
2047
- return v.t - w.t + (w.t - u.t) * (gapR / (gapL + gapR));
2048
- }
2049
- }
2050
- return 0.0;
2051
- };
2052
- Geom.edgeSign = function (u, v, w) {
2053
- assert(Geom.vertLeq(u, v) && Geom.vertLeq(v, w));
2054
- var gapL = v.s - u.s;
2055
- var gapR = w.s - v.s;
2056
- if (gapL + gapR > 0.0) {
2057
- return (v.t - w.t) * gapL + (v.t - u.t) * gapR;
2058
- }
2059
- return 0.0;
2060
- };
2061
- Geom.transEval = function (u, v, w) {
2062
- assert(Geom.transLeq(u, v) && Geom.transLeq(v, w));
2063
- var gapL = v.t - u.t;
2064
- var gapR = w.t - v.t;
2065
- if (gapL + gapR > 0.0) {
2066
- if (gapL < gapR) {
2067
- return v.s - u.s + (u.s - w.s) * (gapL / (gapL + gapR));
2068
- }
2069
- else {
2070
- return v.s - w.s + (w.s - u.s) * (gapR / (gapL + gapR));
2071
- }
2072
- }
2073
- return 0.0;
2074
- };
2075
- Geom.transSign = function (u, v, w) {
2076
- assert(Geom.transLeq(u, v) && Geom.transLeq(v, w));
2077
- var gapL = v.t - u.t;
2078
- var gapR = w.t - v.t;
2079
- if (gapL + gapR > 0.0) {
2080
- return (v.s - w.s) * gapL + (v.s - u.s) * gapR;
2081
- }
2082
- return 0.0;
2083
- };
2084
- Geom.vertCCW = function (u, v, w) {
2085
- return u.s * (v.t - w.t) + v.s * (w.t - u.t) + w.s * (u.t - v.t) >= 0.0;
2086
- };
2087
- Geom.interpolate = function (a, x, b, y) {
2088
- return ((a = a < 0 ? 0 : a),
2089
- (b = b < 0 ? 0 : b),
2090
- a <= b
2091
- ? b === 0
2092
- ? (x + y) / 2
2093
- : x + (y - x) * (a / (a + b))
2094
- : y + (x - y) * (b / (a + b)));
2095
- };
2096
- Geom.intersect = function (o1, d1, o2, d2, v) {
2097
- var z1, z2;
2098
- var t;
2099
- if (!Geom.vertLeq(o1, d1)) {
2100
- t = o1;
2101
- o1 = d1;
2102
- d1 = t;
2103
- }
2104
- if (!Geom.vertLeq(o2, d2)) {
2105
- t = o2;
2106
- o2 = d2;
2107
- d2 = t;
2108
- }
2109
- if (!Geom.vertLeq(o1, o2)) {
2110
- t = o1;
2111
- o1 = o2;
2112
- o2 = t;
2113
- t = d1;
2114
- d1 = d2;
2115
- d2 = t;
2116
- }
2117
- if (!Geom.vertLeq(o2, d1)) {
2118
- v.s = (o2.s + d1.s) / 2;
2119
- }
2120
- else if (Geom.vertLeq(d1, d2)) {
2121
- z1 = Geom.edgeEval(o1, o2, d1);
2122
- z2 = Geom.edgeEval(o2, d1, d2);
2123
- if (z1 + z2 < 0) {
2124
- z1 = -z1;
2125
- z2 = -z2;
2126
- }
2127
- v.s = Geom.interpolate(z1, o2.s, z2, d1.s);
2128
- }
2129
- else {
2130
- z1 = Geom.edgeSign(o1, o2, d1);
2131
- z2 = -Geom.edgeSign(o1, d2, d1);
2132
- if (z1 + z2 < 0) {
2133
- z1 = -z1;
2134
- z2 = -z2;
2135
- }
2136
- v.s = Geom.interpolate(z1, o2.s, z2, d2.s);
2137
- }
2138
- if (!Geom.transLeq(o1, d1)) {
2139
- t = o1;
2140
- o1 = d1;
2141
- d1 = t;
2142
- }
2143
- if (!Geom.transLeq(o2, d2)) {
2144
- t = o2;
2145
- o2 = d2;
2146
- d2 = t;
2147
- }
2148
- if (!Geom.transLeq(o1, o2)) {
2149
- t = o1;
2150
- o1 = o2;
2151
- o2 = t;
2152
- t = d1;
2153
- d1 = d2;
2154
- d2 = t;
2155
- }
2156
- if (!Geom.transLeq(o2, d1)) {
2157
- v.t = (o2.t + d1.t) / 2;
2158
- }
2159
- else if (Geom.transLeq(d1, d2)) {
2160
- z1 = Geom.transEval(o1, o2, d1);
2161
- z2 = Geom.transEval(o2, d1, d2);
2162
- if (z1 + z2 < 0) {
2163
- z1 = -z1;
2164
- z2 = -z2;
2165
- }
2166
- v.t = Geom.interpolate(z1, o2.t, z2, d1.t);
2167
- }
2168
- else {
2169
- z1 = Geom.transSign(o1, o2, d1);
2170
- z2 = -Geom.transSign(o1, d2, d1);
2171
- if (z1 + z2 < 0) {
2172
- z1 = -z1;
2173
- z2 = -z2;
2174
- }
2175
- v.t = Geom.interpolate(z1, o2.t, z2, d2.t);
2176
- }
2177
- };
2178
- return Geom;
2179
- }());
2180
-
2181
- var TESSface = (function () {
2182
- function TESSface() {
2183
- this.next = null;
2184
- this.prev = null;
2185
- this.anEdge = null;
2186
- this.trail = null;
2187
- this.n = 0;
2188
- this.marked = false;
2189
- this.inside = false;
2190
- }
2191
- return TESSface;
2192
- }());
2002
+ function getAugmentedNamespace(n) {
2003
+ if (n.__esModule) return n;
2004
+ var f = n.default;
2005
+ if (typeof f == "function") {
2006
+ var a = function a () {
2007
+ if (this instanceof a) {
2008
+ return Reflect.construct(f, arguments, this.constructor);
2009
+ }
2010
+ return f.apply(this, arguments);
2011
+ };
2012
+ a.prototype = f.prototype;
2013
+ } else a = {};
2014
+ Object.defineProperty(a, '__esModule', {value: true});
2015
+ Object.keys(n).forEach(function (k) {
2016
+ var d = Object.getOwnPropertyDescriptor(n, k);
2017
+ Object.defineProperty(a, k, d.get ? d : {
2018
+ enumerable: true,
2019
+ get: function () {
2020
+ return n[k];
2021
+ }
2022
+ });
2023
+ });
2024
+ return a;
2025
+ }
2193
2026
 
2194
- var TESShalfEdge = (function () {
2195
- function TESShalfEdge(side) {
2196
- this.side = side;
2197
- this.next = null;
2198
- this.Org = null;
2199
- this.Sym = null;
2200
- this.Onext = null;
2201
- this.Lnext = null;
2202
- this.Lface = null;
2203
- this.activeRegion = null;
2204
- this.winding = 0;
2205
- }
2206
- Object.defineProperty(TESShalfEdge.prototype, "Rface", {
2207
- get: function () {
2208
- return this.Sym.Lface;
2209
- },
2210
- set: function (v) {
2211
- this.Sym.Lface = v;
2212
- },
2213
- enumerable: true,
2214
- configurable: true
2215
- });
2216
- Object.defineProperty(TESShalfEdge.prototype, "Dst", {
2217
- get: function () {
2218
- return this.Sym.Org;
2219
- },
2220
- set: function (v) {
2221
- this.Sym.Org = v;
2222
- },
2223
- enumerable: true,
2224
- configurable: true
2225
- });
2226
- Object.defineProperty(TESShalfEdge.prototype, "Oprev", {
2227
- get: function () {
2228
- return this.Sym.Lnext;
2229
- },
2230
- set: function (v) {
2231
- this.Sym.Lnext = v;
2232
- },
2233
- enumerable: true,
2234
- configurable: true
2235
- });
2236
- Object.defineProperty(TESShalfEdge.prototype, "Lprev", {
2237
- get: function () {
2238
- return this.Onext.Sym;
2239
- },
2240
- set: function (v) {
2241
- this.Onext.Sym = v;
2242
- },
2243
- enumerable: true,
2244
- configurable: true
2245
- });
2246
- Object.defineProperty(TESShalfEdge.prototype, "Dprev", {
2247
- get: function () {
2248
- return this.Lnext.Sym;
2249
- },
2250
- set: function (v) {
2251
- this.Lnext.Sym = v;
2252
- },
2253
- enumerable: true,
2254
- configurable: true
2255
- });
2256
- Object.defineProperty(TESShalfEdge.prototype, "Rprev", {
2257
- get: function () {
2258
- return this.Sym.Onext;
2259
- },
2260
- set: function (v) {
2261
- this.Sym.Onext = v;
2262
- },
2263
- enumerable: true,
2264
- configurable: true
2265
- });
2266
- Object.defineProperty(TESShalfEdge.prototype, "Dnext", {
2267
- get: function () {
2268
- return this.Sym.Onext.Sym;
2269
- },
2270
- set: function (v) {
2271
- this.Sym.Onext.Sym = v;
2272
- },
2273
- enumerable: true,
2274
- configurable: true
2275
- });
2276
- Object.defineProperty(TESShalfEdge.prototype, "Rnext", {
2277
- get: function () {
2278
- return this.Sym.Lnext.Sym;
2279
- },
2280
- set: function (v) {
2281
- this.Sym.Lnext.Sym = v;
2282
- },
2283
- enumerable: true,
2284
- configurable: true
2285
- });
2286
- return TESShalfEdge;
2287
- }());
2027
+ var libtess_min = {exports: {}};
2288
2028
 
2289
- var TESSvertex = (function () {
2290
- function TESSvertex() {
2291
- this.next = null;
2292
- this.prev = null;
2293
- this.anEdge = null;
2294
- this.coords = [0, 0, 0];
2295
- this.s = 0.0;
2296
- this.t = 0.0;
2297
- this.pqHandle = 0;
2298
- this.n = 0;
2299
- this.idx = 0;
2300
- }
2301
- return TESSvertex;
2302
- }());
2029
+ /*
2303
2030
 
2304
- var TESSmesh = (function () {
2305
- function TESSmesh() {
2306
- var v = new TESSvertex();
2307
- var f = new TESSface();
2308
- var e = new TESShalfEdge(0);
2309
- var eSym = new TESShalfEdge(1);
2310
- v.next = v.prev = v;
2311
- v.anEdge = null;
2312
- f.next = f.prev = f;
2313
- e.next = e;
2314
- e.Sym = eSym;
2315
- eSym.next = eSym;
2316
- eSym.Sym = e;
2317
- this.vHead = v;
2318
- this.fHead = f;
2319
- this.eHead = e;
2320
- this.eHeadSym = eSym;
2321
- }
2322
- TESSmesh.prototype.makeEdge_ = function (eNext) {
2323
- var e = new TESShalfEdge(0);
2324
- var eSym = new TESShalfEdge(1);
2325
- if (eNext.Sym.side < eNext.side) {
2326
- eNext = eNext.Sym;
2327
- }
2328
- var ePrev = eNext.Sym.next;
2329
- eSym.next = ePrev;
2330
- ePrev.Sym.next = e;
2331
- e.next = eNext;
2332
- eNext.Sym.next = eSym;
2333
- e.Sym = eSym;
2334
- e.Onext = e;
2335
- e.Lnext = eSym;
2336
- e.Org = null;
2337
- e.Lface = null;
2338
- e.winding = 0;
2339
- e.activeRegion = null;
2340
- eSym.Sym = e;
2341
- eSym.Onext = eSym;
2342
- eSym.Lnext = e;
2343
- eSym.Org = null;
2344
- eSym.Lface = null;
2345
- eSym.winding = 0;
2346
- eSym.activeRegion = null;
2347
- return e;
2348
- };
2349
- TESSmesh.prototype.splice_ = function (a, b) {
2350
- var aOnext = a.Onext;
2351
- var bOnext = b.Onext;
2352
- aOnext.Sym.Lnext = b;
2353
- bOnext.Sym.Lnext = a;
2354
- a.Onext = bOnext;
2355
- b.Onext = aOnext;
2356
- };
2357
- TESSmesh.prototype.makeVertex_ = function (newVertex, eOrig, vNext) {
2358
- var vNew = newVertex;
2359
- assert(vNew, "Vertex can't be null!");
2360
- var vPrev = vNext.prev;
2361
- vNew.prev = vPrev;
2362
- vPrev.next = vNew;
2363
- vNew.next = vNext;
2364
- vNext.prev = vNew;
2365
- vNew.anEdge = eOrig;
2366
- var e = eOrig;
2367
- do {
2368
- e.Org = vNew;
2369
- e = e.Onext;
2370
- } while (e !== eOrig);
2371
- };
2372
- TESSmesh.prototype.makeFace_ = function (newFace, eOrig, fNext) {
2373
- var fNew = newFace;
2374
- assert(fNew, "Face can't be null");
2375
- var fPrev = fNext.prev;
2376
- fNew.prev = fPrev;
2377
- fPrev.next = fNew;
2378
- fNew.next = fNext;
2379
- fNext.prev = fNew;
2380
- fNew.anEdge = eOrig;
2381
- fNew.trail = null;
2382
- fNew.marked = false;
2383
- fNew.inside = fNext.inside;
2384
- var e = eOrig;
2385
- do {
2386
- e.Lface = fNew;
2387
- e = e.Lnext;
2388
- } while (e !== eOrig);
2389
- };
2390
- TESSmesh.prototype.killEdge_ = function (eDel) {
2391
- if (eDel.Sym.side < eDel.side) {
2392
- eDel = eDel.Sym;
2393
- }
2394
- var eNext = eDel.next;
2395
- var ePrev = eDel.Sym.next;
2396
- eNext.Sym.next = ePrev;
2397
- ePrev.Sym.next = eNext;
2398
- };
2399
- TESSmesh.prototype.killVertex_ = function (vDel, newOrg) {
2400
- var eStart = vDel.anEdge;
2401
- var e = eStart;
2402
- do {
2403
- e.Org = newOrg;
2404
- e = e.Onext;
2405
- } while (e !== eStart);
2406
- var vPrev = vDel.prev;
2407
- var vNext = vDel.next;
2408
- vNext.prev = vPrev;
2409
- vPrev.next = vNext;
2410
- };
2411
- TESSmesh.prototype.killFace_ = function (fDel, newLface) {
2412
- var eStart = fDel.anEdge;
2413
- var e = eStart;
2414
- do {
2415
- e.Lface = newLface;
2416
- e = e.Lnext;
2417
- } while (e !== eStart);
2418
- var fPrev = fDel.prev;
2419
- var fNext = fDel.next;
2420
- fNext.prev = fPrev;
2421
- fPrev.next = fNext;
2422
- };
2423
- TESSmesh.prototype.makeEdge = function () {
2424
- var newVertex1 = new TESSvertex();
2425
- var newVertex2 = new TESSvertex();
2426
- var newFace = new TESSface();
2427
- var e = this.makeEdge_(this.eHead);
2428
- this.makeVertex_(newVertex1, e, this.vHead);
2429
- this.makeVertex_(newVertex2, e.Sym, this.vHead);
2430
- this.makeFace_(newFace, e, this.fHead);
2431
- return e;
2432
- };
2433
- TESSmesh.prototype.splice = function (eOrg, eDst) {
2434
- var joiningLoops = false;
2435
- var joiningVertices = false;
2436
- if (eOrg === eDst)
2437
- return;
2438
- if (eDst.Org !== eOrg.Org) {
2439
- joiningVertices = true;
2440
- this.killVertex_(eDst.Org, eOrg.Org);
2441
- }
2442
- if (eDst.Lface !== eOrg.Lface) {
2443
- joiningLoops = true;
2444
- this.killFace_(eDst.Lface, eOrg.Lface);
2445
- }
2446
- this.splice_(eDst, eOrg);
2447
- if (!joiningVertices) {
2448
- var newVertex = new TESSvertex();
2449
- this.makeVertex_(newVertex, eDst, eOrg.Org);
2450
- eOrg.Org.anEdge = eOrg;
2451
- }
2452
- if (!joiningLoops) {
2453
- var newFace = new TESSface();
2454
- this.makeFace_(newFace, eDst, eOrg.Lface);
2455
- eOrg.Lface.anEdge = eOrg;
2456
- }
2457
- };
2458
- TESSmesh.prototype.delete = function (eDel) {
2459
- var eDelSym = eDel.Sym;
2460
- var joiningLoops = false;
2461
- if (eDel.Lface !== eDel.Rface) {
2462
- joiningLoops = true;
2463
- this.killFace_(eDel.Lface, eDel.Rface);
2464
- }
2465
- if (eDel.Onext === eDel) {
2466
- this.killVertex_(eDel.Org, null);
2467
- }
2468
- else {
2469
- eDel.Rface.anEdge = eDel.Oprev;
2470
- eDel.Org.anEdge = eDel.Onext;
2471
- this.splice_(eDel, eDel.Oprev);
2472
- if (!joiningLoops) {
2473
- var newFace = new TESSface();
2474
- this.makeFace_(newFace, eDel, eDel.Lface);
2475
- }
2476
- }
2477
- if (eDelSym.Onext === eDelSym) {
2478
- this.killVertex_(eDelSym.Org, null);
2479
- this.killFace_(eDelSym.Lface, null);
2480
- }
2481
- else {
2482
- eDel.Lface.anEdge = eDelSym.Oprev;
2483
- eDelSym.Org.anEdge = eDelSym.Onext;
2484
- this.splice_(eDelSym, eDelSym.Oprev);
2485
- }
2486
- this.killEdge_(eDel);
2487
- };
2488
- TESSmesh.prototype.addEdgeVertex = function (eOrg) {
2489
- var eNew = this.makeEdge_(eOrg);
2490
- var eNewSym = eNew.Sym;
2491
- this.splice_(eNew, eOrg.Lnext);
2492
- eNew.Org = eOrg.Dst;
2493
- var newVertex = new TESSvertex();
2494
- this.makeVertex_(newVertex, eNewSym, eNew.Org);
2495
- eNew.Lface = eNewSym.Lface = eOrg.Lface;
2496
- return eNew;
2497
- };
2498
- TESSmesh.prototype.splitEdge = function (eOrg) {
2499
- var tempHalfEdge = this.addEdgeVertex(eOrg);
2500
- var eNew = tempHalfEdge.Sym;
2501
- this.splice_(eOrg.Sym, eOrg.Sym.Oprev);
2502
- this.splice_(eOrg.Sym, eNew);
2503
- eOrg.Dst = eNew.Org;
2504
- eNew.Dst.anEdge = eNew.Sym;
2505
- eNew.Rface = eOrg.Rface;
2506
- eNew.winding = eOrg.winding;
2507
- eNew.Sym.winding = eOrg.Sym.winding;
2508
- return eNew;
2509
- };
2510
- TESSmesh.prototype.connect = function (eOrg, eDst) {
2511
- var joiningLoops = false;
2512
- var eNew = this.makeEdge_(eOrg);
2513
- var eNewSym = eNew.Sym;
2514
- if (eDst.Lface !== eOrg.Lface) {
2515
- joiningLoops = true;
2516
- this.killFace_(eDst.Lface, eOrg.Lface);
2517
- }
2518
- this.splice_(eNew, eOrg.Lnext);
2519
- this.splice_(eNewSym, eDst);
2520
- eNew.Org = eOrg.Dst;
2521
- eNewSym.Org = eDst.Org;
2522
- eNew.Lface = eNewSym.Lface = eOrg.Lface;
2523
- eOrg.Lface.anEdge = eNewSym;
2524
- if (!joiningLoops) {
2525
- var newFace = new TESSface();
2526
- this.makeFace_(newFace, eNew, eOrg.Lface);
2527
- }
2528
- return eNew;
2529
- };
2530
- TESSmesh.prototype.zapFace = function (fZap) {
2531
- var eStart = fZap.anEdge;
2532
- var e, eNext, eSym;
2533
- var fPrev, fNext;
2534
- eNext = eStart.Lnext;
2535
- do {
2536
- e = eNext;
2537
- eNext = e.Lnext;
2538
- e.Lface = null;
2539
- if (e.Rface === null) {
2540
- if (e.Onext === e) {
2541
- this.killVertex_(e.Org, null);
2542
- }
2543
- else {
2544
- e.Org.anEdge = e.Onext;
2545
- this.splice_(e, e.Oprev);
2546
- }
2547
- eSym = e.Sym;
2548
- if (eSym.Onext === eSym) {
2549
- this.killVertex_(eSym.Org, null);
2550
- }
2551
- else {
2552
- eSym.Org.anEdge = eSym.Onext;
2553
- this.splice_(eSym, eSym.Oprev);
2554
- }
2555
- this.killEdge_(e);
2556
- }
2557
- } while (e != eStart);
2558
- fPrev = fZap.prev;
2559
- fNext = fZap.next;
2560
- fNext.prev = fPrev;
2561
- fPrev.next = fNext;
2562
- };
2563
- TESSmesh.prototype.countFaceVerts_ = function (f) {
2564
- var eCur = f.anEdge;
2565
- var n = 0;
2566
- do {
2567
- n++;
2568
- eCur = eCur.Lnext;
2569
- } while (eCur !== f.anEdge);
2570
- return n;
2571
- };
2572
- TESSmesh.prototype.mergeConvexFaces = function (maxVertsPerFace) {
2573
- var f;
2574
- var eCur, eNext, eSym;
2575
- var vStart;
2576
- var curNv, symNv;
2577
- for (f = this.fHead.next; f !== this.fHead; f = f.next) {
2578
- if (!f.inside)
2579
- continue;
2580
- eCur = f.anEdge;
2581
- vStart = eCur.Org;
2582
- while (true) {
2583
- eNext = eCur.Lnext;
2584
- eSym = eCur.Sym;
2585
- if (eSym && eSym.Lface && eSym.Lface.inside) {
2586
- curNv = this.countFaceVerts_(f);
2587
- symNv = this.countFaceVerts_(eSym.Lface);
2588
- if (curNv + symNv - 2 <= maxVertsPerFace) {
2589
- if (Geom.vertCCW(eCur.Lprev.Org, eCur.Org, eSym.Lnext.Lnext.Org) &&
2590
- Geom.vertCCW(eSym.Lprev.Org, eSym.Org, eCur.Lnext.Lnext.Org)) {
2591
- eNext = eSym.Lnext;
2592
- this.delete(eSym);
2593
- eCur = null;
2594
- eSym = null;
2595
- }
2596
- }
2597
- }
2598
- if (eCur && eCur.Lnext.Org === vStart)
2599
- break;
2600
- eCur = eNext;
2601
- }
2602
- }
2603
- return true;
2604
- };
2605
- TESSmesh.prototype.check = function () {
2606
- var fHead = this.fHead;
2607
- var vHead = this.vHead;
2608
- var eHead = this.eHead;
2609
- var f, fPrev, v, vPrev, e, ePrev;
2610
- fPrev = fHead;
2611
- for (fPrev = fHead; (f = fPrev.next) !== fHead; fPrev = f) {
2612
- assert(f.prev === fPrev);
2613
- e = f.anEdge;
2614
- do {
2615
- assert(e.Sym !== e);
2616
- assert(e.Sym.Sym === e);
2617
- assert(e.Lnext.Onext.Sym === e);
2618
- assert(e.Onext.Sym.Lnext === e);
2619
- assert(e.Lface === f);
2620
- e = e.Lnext;
2621
- } while (e !== f.anEdge);
2622
- }
2623
- assert(f.prev === fPrev && f.anEdge === null);
2624
- vPrev = vHead;
2625
- for (vPrev = vHead; (v = vPrev.next) !== vHead; vPrev = v) {
2626
- assert(v.prev === vPrev);
2627
- e = v.anEdge;
2628
- do {
2629
- assert(e.Sym !== e);
2630
- assert(e.Sym.Sym === e);
2631
- assert(e.Lnext.Onext.Sym === e);
2632
- assert(e.Onext.Sym.Lnext === e);
2633
- assert(e.Org === v);
2634
- e = e.Onext;
2635
- } while (e !== v.anEdge);
2636
- }
2637
- assert(v.prev === vPrev && v.anEdge === null);
2638
- ePrev = eHead;
2639
- for (ePrev = eHead; (e = ePrev.next) !== eHead; ePrev = e) {
2640
- assert(e.Sym.next === ePrev.Sym);
2641
- assert(e.Sym !== e);
2642
- assert(e.Sym.Sym === e);
2643
- assert(e.Org !== null);
2644
- assert(e.Dst !== null);
2645
- assert(e.Lnext.Onext.Sym === e);
2646
- assert(e.Onext.Sym.Lnext === e);
2647
- }
2648
- assert(e.Sym.next === ePrev.Sym &&
2649
- e.Sym === this.eHeadSym &&
2650
- e.Sym.Sym === e &&
2651
- e.Org === null &&
2652
- e.Dst === null &&
2653
- e.Lface === null &&
2654
- e.Rface === null);
2655
- };
2656
- return TESSmesh;
2657
- }());
2031
+ Copyright 2000, Silicon Graphics, Inc. All Rights Reserved.
2032
+ Copyright 2015, Google Inc. All Rights Reserved.
2658
2033
 
2659
- var PQnode = (function () {
2660
- function PQnode() {
2661
- this.handle = null;
2662
- }
2663
- return PQnode;
2664
- }());
2665
- var PQhandleElem = (function () {
2666
- function PQhandleElem() {
2667
- this.key = null;
2668
- this.node = 0;
2669
- }
2670
- return PQhandleElem;
2671
- }());
2672
- var PriorityQ = (function () {
2673
- function PriorityQ(size, leq) {
2674
- this.leq = leq;
2675
- this.max = 0;
2676
- this.nodes = [];
2677
- this.handles = [];
2678
- this.initialized = false;
2679
- this.freeList = 0;
2680
- this.size = 0;
2681
- this.max = size;
2682
- this.nodes = [];
2683
- this.handles = [];
2684
- for (var i = 0; i < size + 1; i++) {
2685
- this.nodes[i] = new PQnode();
2686
- this.handles[i] = new PQhandleElem();
2687
- }
2688
- this.initialized = false;
2689
- this.nodes[1].handle = 1;
2690
- this.handles[1].key = null;
2691
- }
2692
- PriorityQ.prototype.floatDown_ = function (curr) {
2693
- var n = this.nodes;
2694
- var h = this.handles;
2695
- var hCurr, hChild;
2696
- var child;
2697
- hCurr = n[curr].handle;
2698
- for (;;) {
2699
- child = curr << 1;
2700
- if (child < this.size &&
2701
- this.leq(h[n[child + 1].handle].key, h[n[child].handle].key)) {
2702
- ++child;
2703
- }
2704
- assert(child <= this.max);
2705
- hChild = n[child].handle;
2706
- if (child > this.size || this.leq(h[hCurr].key, h[hChild].key)) {
2707
- n[curr].handle = hCurr;
2708
- h[hCurr].node = curr;
2709
- break;
2710
- }
2711
- n[curr].handle = hChild;
2712
- h[hChild].node = curr;
2713
- curr = child;
2714
- }
2715
- };
2716
- PriorityQ.prototype.floatUp_ = function (curr) {
2717
- var n = this.nodes;
2718
- var h = this.handles;
2719
- var hCurr, hParent;
2720
- var parent;
2721
- hCurr = n[curr].handle;
2722
- for (;;) {
2723
- parent = curr >> 1;
2724
- hParent = n[parent].handle;
2725
- if (parent === 0 || this.leq(h[hParent].key, h[hCurr].key)) {
2726
- n[curr].handle = hCurr;
2727
- h[hCurr].node = curr;
2728
- break;
2729
- }
2730
- n[curr].handle = hParent;
2731
- h[hParent].node = curr;
2732
- curr = parent;
2733
- }
2734
- };
2735
- PriorityQ.prototype.init = function () {
2736
- for (var i = this.size; i >= 1; --i) {
2737
- this.floatDown_(i);
2738
- }
2739
- this.initialized = true;
2740
- };
2741
- PriorityQ.prototype.min = function () {
2742
- return this.handles[this.nodes[1].handle].key;
2743
- };
2744
- PriorityQ.prototype.insert = function (keyNew) {
2745
- var curr;
2746
- var free;
2747
- curr = ++this.size;
2748
- if (curr * 2 > this.max) {
2749
- this.max *= 2;
2750
- var i;
2751
- var s;
2752
- s = this.nodes.length;
2753
- this.nodes.length = this.max + 1;
2754
- for (i = s; i < this.nodes.length; i++)
2755
- this.nodes[i] = new PQnode();
2756
- s = this.handles.length;
2757
- this.handles.length = this.max + 1;
2758
- for (i = s; i < this.handles.length; i++)
2759
- this.handles[i] = new PQhandleElem();
2760
- }
2761
- if (this.freeList === 0) {
2762
- free = curr;
2763
- }
2764
- else {
2765
- free = this.freeList;
2766
- this.freeList = this.handles[free].node;
2767
- }
2768
- this.nodes[curr].handle = free;
2769
- this.handles[free].node = curr;
2770
- this.handles[free].key = keyNew;
2771
- if (this.initialized) {
2772
- this.floatUp_(curr);
2773
- }
2774
- return free;
2775
- };
2776
- PriorityQ.prototype.extractMin = function () {
2777
- var n = this.nodes;
2778
- var h = this.handles;
2779
- var hMin = n[1].handle;
2780
- var min = h[hMin].key;
2781
- if (this.size > 0) {
2782
- n[1].handle = n[this.size].handle;
2783
- h[n[1].handle].node = 1;
2784
- h[hMin].key = null;
2785
- h[hMin].node = this.freeList;
2786
- this.freeList = hMin;
2787
- --this.size;
2788
- if (this.size > 0) {
2789
- this.floatDown_(1);
2790
- }
2791
- }
2792
- return min;
2793
- };
2794
- PriorityQ.prototype.delete = function (hCurr) {
2795
- var n = this.nodes;
2796
- var h = this.handles;
2797
- var curr;
2798
- assert(hCurr >= 1 && hCurr <= this.max && h[hCurr].key !== null);
2799
- curr = h[hCurr].node;
2800
- n[curr].handle = n[this.size].handle;
2801
- h[n[curr].handle].node = curr;
2802
- --this.size;
2803
- if (curr <= this.size) {
2804
- if (curr <= 1 ||
2805
- this.leq(h[n[curr >> 1].handle].key, h[n[curr].handle].key)) {
2806
- this.floatDown_(curr);
2807
- }
2808
- else {
2809
- this.floatUp_(curr);
2810
- }
2811
- }
2812
- h[hCurr].key = null;
2813
- h[hCurr].node = this.freeList;
2814
- this.freeList = hCurr;
2815
- };
2816
- return PriorityQ;
2817
- }());
2034
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2035
+ of this software and associated documentation files (the "Software"), to
2036
+ deal in the Software without restriction, including without limitation the
2037
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2038
+ sell copies of the Software, and to permit persons to whom the Software is
2039
+ furnished to do so, subject to the following conditions:
2818
2040
 
2819
- var ActiveRegion = (function () {
2820
- function ActiveRegion() {
2821
- this.eUp = null;
2822
- this.nodeUp = null;
2823
- this.windingNumber = 0;
2824
- this.inside = false;
2825
- this.sentinel = false;
2826
- this.dirty = false;
2827
- this.fixUpperEdge = false;
2828
- }
2829
- return ActiveRegion;
2830
- }());
2041
+ The above copyright notice including the dates of first publication and
2042
+ either this permission notice or a reference to http://oss.sgi.com/projects/FreeB/
2043
+ shall be included in all copies or substantial portions of the Software.
2831
2044
 
2832
- var DictNode = (function () {
2833
- function DictNode() {
2834
- this.key = null;
2835
- this.next = null;
2836
- this.prev = null;
2837
- }
2838
- return DictNode;
2839
- }());
2840
- var Dict = (function () {
2841
- function Dict(frame, leq) {
2842
- this.frame = frame;
2843
- this.leq = leq;
2844
- this.head = new DictNode();
2845
- this.head.next = this.head;
2846
- this.head.prev = this.head;
2847
- }
2848
- Dict.prototype.min = function () {
2849
- return this.head.next;
2850
- };
2851
- Dict.prototype.max = function () {
2852
- return this.head.prev;
2853
- };
2854
- Dict.prototype.insert = function (k) {
2855
- return this.insertBefore(this.head, k);
2856
- };
2857
- Dict.prototype.search = function (key) {
2858
- var node = this.head;
2859
- do {
2860
- node = node.next;
2861
- } while (node.key !== null && !this.leq(this.frame, key, node.key));
2862
- return node;
2863
- };
2864
- Dict.prototype.insertBefore = function (node, key) {
2865
- do {
2866
- node = node.prev;
2867
- } while (node.key !== null && !this.leq(this.frame, node.key, key));
2868
- var newNode = new DictNode();
2869
- newNode.key = key;
2870
- newNode.next = node.next;
2871
- node.next.prev = newNode;
2872
- newNode.prev = node;
2873
- node.next = newNode;
2874
- return newNode;
2875
- };
2876
- Dict.prototype.delete = function (node) {
2877
- node.next.prev = node.prev;
2878
- node.prev.next = node.next;
2879
- };
2880
- return Dict;
2881
- }());
2045
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2046
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2047
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2048
+ SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
2049
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
2050
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2882
2051
 
2883
- var Sweep = (function () {
2884
- function Sweep() {
2885
- }
2886
- Sweep.regionBelow = function (r) {
2887
- return r.nodeUp.prev.key;
2888
- };
2889
- Sweep.regionAbove = function (r) {
2890
- return r.nodeUp.next.key;
2891
- };
2892
- Sweep.debugEvent = function (tess) {
2893
- };
2894
- Sweep.addWinding = function (eDst, eSrc) {
2895
- eDst.winding += eSrc.winding;
2896
- eDst.Sym.winding += eSrc.Sym.winding;
2897
- };
2898
- Sweep.edgeLeq = function (tess, reg1, reg2) {
2899
- var ev = tess.event;
2900
- var e1 = reg1.eUp;
2901
- var e2 = reg2.eUp;
2902
- if (e1.Dst === ev) {
2903
- if (e2.Dst === ev) {
2904
- if (Geom.vertLeq(e1.Org, e2.Org)) {
2905
- return Geom.edgeSign(e2.Dst, e1.Org, e2.Org) <= 0;
2906
- }
2907
- return Geom.edgeSign(e1.Dst, e2.Org, e1.Org) >= 0;
2908
- }
2909
- return Geom.edgeSign(e2.Dst, ev, e2.Org) <= 0;
2910
- }
2911
- if (e2.Dst === ev) {
2912
- return Geom.edgeSign(e1.Dst, ev, e1.Org) >= 0;
2913
- }
2914
- var t1 = Geom.edgeEval(e1.Dst, ev, e1.Org);
2915
- var t2 = Geom.edgeEval(e2.Dst, ev, e2.Org);
2916
- return t1 >= t2;
2917
- };
2918
- Sweep.deleteRegion = function (tess, reg) {
2919
- if (reg.fixUpperEdge) {
2920
- assert(reg.eUp.winding === 0);
2921
- }
2922
- reg.eUp.activeRegion = null;
2923
- tess.dict.delete(reg.nodeUp);
2924
- };
2925
- Sweep.fixUpperEdge = function (tess, reg, newEdge) {
2926
- assert(reg.fixUpperEdge);
2927
- tess.mesh.delete(reg.eUp);
2928
- reg.fixUpperEdge = false;
2929
- reg.eUp = newEdge;
2930
- newEdge.activeRegion = reg;
2931
- };
2932
- Sweep.topLeftRegion = function (tess, reg) {
2933
- var org = reg.eUp.Org;
2934
- var e;
2935
- do {
2936
- reg = Sweep.regionAbove(reg);
2937
- } while (reg.eUp.Org === org);
2938
- if (reg.fixUpperEdge) {
2939
- e = tess.mesh.connect(Sweep.regionBelow(reg).eUp.Sym, reg.eUp.Lnext);
2940
- if (e === null)
2941
- return null;
2942
- Sweep.fixUpperEdge(tess, reg, e);
2943
- reg = Sweep.regionAbove(reg);
2944
- }
2945
- return reg;
2946
- };
2947
- Sweep.topRightRegion = function (reg) {
2948
- var dst = reg.eUp.Dst;
2949
- do {
2950
- reg = Sweep.regionAbove(reg);
2951
- } while (reg.eUp.Dst === dst);
2952
- return reg;
2953
- };
2954
- Sweep.addRegionBelow = function (tess, regAbove, eNewUp) {
2955
- var regNew = new ActiveRegion();
2956
- regNew.eUp = eNewUp;
2957
- regNew.nodeUp = tess.dict.insertBefore(regAbove.nodeUp, regNew);
2958
- regNew.fixUpperEdge = false;
2959
- regNew.sentinel = false;
2960
- regNew.dirty = false;
2961
- eNewUp.activeRegion = regNew;
2962
- return regNew;
2963
- };
2964
- Sweep.isWindingInside = function (tess, n) {
2965
- switch (tess.windingRule) {
2966
- case WINDING.ODD:
2967
- return (n & 1) !== 0;
2968
- case WINDING.NONZERO:
2969
- return n !== 0;
2970
- case WINDING.POSITIVE:
2971
- return n > 0;
2972
- case WINDING.NEGATIVE:
2973
- return n < 0;
2974
- case WINDING.ABS_GEQ_TWO:
2975
- return n >= 2 || n <= -2;
2976
- }
2977
- throw new Error("Invalid winding rulle");
2978
- };
2979
- Sweep.computeWinding = function (tess, reg) {
2980
- reg.windingNumber =
2981
- Sweep.regionAbove(reg).windingNumber + reg.eUp.winding;
2982
- reg.inside = Sweep.isWindingInside(tess, reg.windingNumber);
2983
- };
2984
- Sweep.finishRegion = function (tess, reg) {
2985
- var e = reg.eUp;
2986
- var f = e.Lface;
2987
- f.inside = reg.inside;
2988
- f.anEdge = e;
2989
- Sweep.deleteRegion(tess, reg);
2990
- };
2991
- Sweep.finishLeftRegions = function (tess, regFirst, regLast) {
2992
- var e;
2993
- var reg = null;
2994
- var regPrev = regFirst;
2995
- var ePrev = regFirst.eUp;
2996
- while (regPrev !== regLast) {
2997
- regPrev.fixUpperEdge = false;
2998
- reg = Sweep.regionBelow(regPrev);
2999
- e = reg.eUp;
3000
- if (e.Org != ePrev.Org) {
3001
- if (!reg.fixUpperEdge) {
3002
- Sweep.finishRegion(tess, regPrev);
3003
- break;
3004
- }
3005
- e = tess.mesh.connect(ePrev.Lprev, e.Sym);
3006
- Sweep.fixUpperEdge(tess, reg, e);
3007
- }
3008
- if (ePrev.Onext !== e) {
3009
- tess.mesh.splice(e.Oprev, e);
3010
- tess.mesh.splice(ePrev, e);
3011
- }
3012
- Sweep.finishRegion(tess, regPrev);
3013
- ePrev = reg.eUp;
3014
- regPrev = reg;
3015
- }
3016
- return ePrev;
3017
- };
3018
- Sweep.addRightEdges = function (tess, regUp, eFirst, eLast, eTopLeft, cleanUp) {
3019
- var reg, regPrev;
3020
- var e, ePrev;
3021
- var firstTime = true;
3022
- e = eFirst;
3023
- do {
3024
- assert(Geom.vertLeq(e.Org, e.Dst));
3025
- Sweep.addRegionBelow(tess, regUp, e.Sym);
3026
- e = e.Onext;
3027
- } while (e !== eLast);
3028
- if (eTopLeft === null) {
3029
- eTopLeft = Sweep.regionBelow(regUp).eUp.Rprev;
3030
- }
3031
- regPrev = regUp;
3032
- ePrev = eTopLeft;
3033
- for (;;) {
3034
- reg = Sweep.regionBelow(regPrev);
3035
- e = reg.eUp.Sym;
3036
- if (e.Org !== ePrev.Org)
3037
- break;
3038
- if (e.Onext !== ePrev) {
3039
- tess.mesh.splice(e.Oprev, e);
3040
- tess.mesh.splice(ePrev.Oprev, e);
3041
- }
3042
- reg.windingNumber = regPrev.windingNumber - e.winding;
3043
- reg.inside = Sweep.isWindingInside(tess, reg.windingNumber);
3044
- regPrev.dirty = true;
3045
- if (!firstTime && Sweep.checkForRightSplice(tess, regPrev)) {
3046
- Sweep.addWinding(e, ePrev);
3047
- Sweep.deleteRegion(tess, regPrev);
3048
- tess.mesh.delete(ePrev);
3049
- }
3050
- firstTime = false;
3051
- regPrev = reg;
3052
- ePrev = e;
3053
- }
3054
- regPrev.dirty = true;
3055
- assert(regPrev.windingNumber - e.winding === reg.windingNumber);
3056
- if (cleanUp) {
3057
- Sweep.walkDirtyRegions(tess, regPrev);
3058
- }
3059
- };
3060
- Sweep.spliceMergeVertices = function (tess, e1, e2) {
3061
- tess.mesh.splice(e1, e2);
3062
- };
3063
- Sweep.vertexWeights = function (isect, org, dst) {
3064
- var t1 = Geom.vertL1dist(org, isect);
3065
- var t2 = Geom.vertL1dist(dst, isect);
3066
- var w0 = (0.5 * t2) / (t1 + t2);
3067
- var w1 = (0.5 * t1) / (t1 + t2);
3068
- isect.coords[0] += w0 * org.coords[0] + w1 * dst.coords[0];
3069
- isect.coords[1] += w0 * org.coords[1] + w1 * dst.coords[1];
3070
- isect.coords[2] += w0 * org.coords[2] + w1 * dst.coords[2];
3071
- };
3072
- Sweep.getIntersectData = function (tess, isect, orgUp, dstUp, orgLo, dstLo) {
3073
- isect.coords[0] = isect.coords[1] = isect.coords[2] = 0;
3074
- isect.idx = -1;
3075
- Sweep.vertexWeights(isect, orgUp, dstUp);
3076
- Sweep.vertexWeights(isect, orgLo, dstLo);
3077
- };
3078
- Sweep.checkForRightSplice = function (tess, regUp) {
3079
- var regLo = Sweep.regionBelow(regUp);
3080
- var eUp = regUp.eUp;
3081
- var eLo = regLo.eUp;
3082
- if (Geom.vertLeq(eUp.Org, eLo.Org)) {
3083
- if (Geom.edgeSign(eLo.Dst, eUp.Org, eLo.Org) > 0)
3084
- return false;
3085
- if (!Geom.vertEq(eUp.Org, eLo.Org)) {
3086
- tess.mesh.splitEdge(eLo.Sym);
3087
- tess.mesh.splice(eUp, eLo.Oprev);
3088
- regUp.dirty = regLo.dirty = true;
3089
- }
3090
- else if (eUp.Org !== eLo.Org) {
3091
- tess.pq.delete(eUp.Org.pqHandle);
3092
- Sweep.spliceMergeVertices(tess, eLo.Oprev, eUp);
3093
- }
3094
- }
3095
- else {
3096
- if (Geom.edgeSign(eUp.Dst, eLo.Org, eUp.Org) < 0)
3097
- return false;
3098
- Sweep.regionAbove(regUp).dirty = regUp.dirty = true;
3099
- tess.mesh.splitEdge(eUp.Sym);
3100
- tess.mesh.splice(eLo.Oprev, eUp);
3101
- }
3102
- return true;
3103
- };
3104
- Sweep.checkForLeftSplice = function (tess, regUp) {
3105
- var regLo = Sweep.regionBelow(regUp);
3106
- var eUp = regUp.eUp;
3107
- var eLo = regLo.eUp;
3108
- var e;
3109
- assert(!Geom.vertEq(eUp.Dst, eLo.Dst));
3110
- if (Geom.vertLeq(eUp.Dst, eLo.Dst)) {
3111
- if (Geom.edgeSign(eUp.Dst, eLo.Dst, eUp.Org) < 0)
3112
- return false;
3113
- Sweep.regionAbove(regUp).dirty = regUp.dirty = true;
3114
- e = tess.mesh.splitEdge(eUp);
3115
- tess.mesh.splice(eLo.Sym, e);
3116
- e.Lface.inside = regUp.inside;
3117
- }
3118
- else {
3119
- if (Geom.edgeSign(eLo.Dst, eUp.Dst, eLo.Org) > 0)
3120
- return false;
3121
- regUp.dirty = regLo.dirty = true;
3122
- e = tess.mesh.splitEdge(eLo);
3123
- tess.mesh.splice(eUp.Lnext, eLo.Sym);
3124
- e.Rface.inside = regUp.inside;
3125
- }
3126
- return true;
3127
- };
3128
- Sweep.checkForIntersect = function (tess, regUp) {
3129
- var regLo = Sweep.regionBelow(regUp);
3130
- var eUp = regUp.eUp;
3131
- var eLo = regLo.eUp;
3132
- var orgUp = eUp.Org;
3133
- var orgLo = eLo.Org;
3134
- var dstUp = eUp.Dst;
3135
- var dstLo = eLo.Dst;
3136
- var tMinUp, tMaxLo;
3137
- var isect = new TESSvertex(), orgMin;
3138
- var e;
3139
- assert(!Geom.vertEq(dstLo, dstUp));
3140
- assert(Geom.edgeSign(dstUp, tess.event, orgUp) <= 0);
3141
- assert(Geom.edgeSign(dstLo, tess.event, orgLo) >= 0);
3142
- assert(orgUp !== tess.event && orgLo !== tess.event);
3143
- assert(!regUp.fixUpperEdge && !regLo.fixUpperEdge);
3144
- if (orgUp === orgLo)
3145
- return false;
3146
- tMinUp = Math.min(orgUp.t, dstUp.t);
3147
- tMaxLo = Math.max(orgLo.t, dstLo.t);
3148
- if (tMinUp > tMaxLo)
3149
- return false;
3150
- if (Geom.vertLeq(orgUp, orgLo)) {
3151
- if (Geom.edgeSign(dstLo, orgUp, orgLo) > 0)
3152
- return false;
3153
- }
3154
- else {
3155
- if (Geom.edgeSign(dstUp, orgLo, orgUp) < 0)
3156
- return false;
3157
- }
3158
- Sweep.debugEvent(tess);
3159
- Geom.intersect(dstUp, orgUp, dstLo, orgLo, isect);
3160
- assert(Math.min(orgUp.t, dstUp.t) <= isect.t);
3161
- assert(isect.t <= Math.max(orgLo.t, dstLo.t));
3162
- assert(Math.min(dstLo.s, dstUp.s) <= isect.s);
3163
- assert(isect.s <= Math.max(orgLo.s, orgUp.s));
3164
- if (Geom.vertLeq(isect, tess.event)) {
3165
- isect.s = tess.event.s;
3166
- isect.t = tess.event.t;
3167
- }
3168
- orgMin = Geom.vertLeq(orgUp, orgLo) ? orgUp : orgLo;
3169
- if (Geom.vertLeq(orgMin, isect)) {
3170
- isect.s = orgMin.s;
3171
- isect.t = orgMin.t;
3172
- }
3173
- if (Geom.vertEq(isect, orgUp) || Geom.vertEq(isect, orgLo)) {
3174
- Sweep.checkForRightSplice(tess, regUp);
3175
- return false;
3176
- }
3177
- if ((!Geom.vertEq(dstUp, tess.event) &&
3178
- Geom.edgeSign(dstUp, tess.event, isect) >= 0) ||
3179
- (!Geom.vertEq(dstLo, tess.event) &&
3180
- Geom.edgeSign(dstLo, tess.event, isect) <= 0)) {
3181
- if (dstLo === tess.event) {
3182
- tess.mesh.splitEdge(eUp.Sym);
3183
- tess.mesh.splice(eLo.Sym, eUp);
3184
- regUp = Sweep.topLeftRegion(tess, regUp);
3185
- eUp = Sweep.regionBelow(regUp).eUp;
3186
- Sweep.finishLeftRegions(tess, Sweep.regionBelow(regUp), regLo);
3187
- Sweep.addRightEdges(tess, regUp, eUp.Oprev, eUp, eUp, true);
3188
- return true;
3189
- }
3190
- if (dstUp === tess.event) {
3191
- tess.mesh.splitEdge(eLo.Sym);
3192
- tess.mesh.splice(eUp.Lnext, eLo.Oprev);
3193
- regLo = regUp;
3194
- regUp = Sweep.topRightRegion(regUp);
3195
- e = Sweep.regionBelow(regUp).eUp.Rprev;
3196
- regLo.eUp = eLo.Oprev;
3197
- eLo = Sweep.finishLeftRegions(tess, regLo, null);
3198
- Sweep.addRightEdges(tess, regUp, eLo.Onext, eUp.Rprev, e, true);
3199
- return true;
3200
- }
3201
- if (Geom.edgeSign(dstUp, tess.event, isect) >= 0) {
3202
- Sweep.regionAbove(regUp).dirty = regUp.dirty = true;
3203
- tess.mesh.splitEdge(eUp.Sym);
3204
- eUp.Org.s = tess.event.s;
3205
- eUp.Org.t = tess.event.t;
3206
- }
3207
- if (Geom.edgeSign(dstLo, tess.event, isect) <= 0) {
3208
- regUp.dirty = regLo.dirty = true;
3209
- tess.mesh.splitEdge(eLo.Sym);
3210
- eLo.Org.s = tess.event.s;
3211
- eLo.Org.t = tess.event.t;
3212
- }
3213
- return false;
3214
- }
3215
- tess.mesh.splitEdge(eUp.Sym);
3216
- tess.mesh.splitEdge(eLo.Sym);
3217
- tess.mesh.splice(eLo.Oprev, eUp);
3218
- eUp.Org.s = isect.s;
3219
- eUp.Org.t = isect.t;
3220
- eUp.Org.pqHandle = tess.pq.insert(eUp.Org);
3221
- Sweep.getIntersectData(tess, eUp.Org, orgUp, dstUp, orgLo, dstLo);
3222
- Sweep.regionAbove(regUp).dirty = regUp.dirty = regLo.dirty = true;
3223
- return false;
3224
- };
3225
- Sweep.walkDirtyRegions = function (tess, regUp) {
3226
- var regLo = Sweep.regionBelow(regUp);
3227
- var eUp, eLo;
3228
- for (;;) {
3229
- while (regLo.dirty) {
3230
- regUp = regLo;
3231
- regLo = Sweep.regionBelow(regLo);
3232
- }
3233
- if (!regUp.dirty) {
3234
- regLo = regUp;
3235
- regUp = Sweep.regionAbove(regUp);
3236
- if (regUp === null || !regUp.dirty) {
3237
- return;
3238
- }
3239
- }
3240
- regUp.dirty = false;
3241
- eUp = regUp.eUp;
3242
- eLo = regLo.eUp;
3243
- if (eUp.Dst !== eLo.Dst) {
3244
- if (Sweep.checkForLeftSplice(tess, regUp)) {
3245
- if (regLo.fixUpperEdge) {
3246
- Sweep.deleteRegion(tess, regLo);
3247
- tess.mesh.delete(eLo);
3248
- regLo = Sweep.regionBelow(regUp);
3249
- eLo = regLo.eUp;
3250
- }
3251
- else if (regUp.fixUpperEdge) {
3252
- Sweep.deleteRegion(tess, regUp);
3253
- tess.mesh.delete(eUp);
3254
- regUp = Sweep.regionAbove(regLo);
3255
- eUp = regUp.eUp;
3256
- }
3257
- }
3258
- }
3259
- if (eUp.Org !== eLo.Org) {
3260
- if (eUp.Dst !== eLo.Dst &&
3261
- !regUp.fixUpperEdge &&
3262
- !regLo.fixUpperEdge &&
3263
- (eUp.Dst === tess.event || eLo.Dst === tess.event)) {
3264
- if (Sweep.checkForIntersect(tess, regUp)) {
3265
- return;
3266
- }
3267
- }
3268
- else {
3269
- Sweep.checkForRightSplice(tess, regUp);
3270
- }
3271
- }
3272
- if (eUp.Org === eLo.Org && eUp.Dst === eLo.Dst) {
3273
- Sweep.addWinding(eLo, eUp);
3274
- Sweep.deleteRegion(tess, regUp);
3275
- tess.mesh.delete(eUp);
3276
- regUp = Sweep.regionAbove(regLo);
3277
- }
3278
- }
3279
- };
3280
- Sweep.connectRightVertex = function (tess, regUp, eBottomLeft) {
3281
- var eNew;
3282
- var eTopLeft = eBottomLeft.Onext;
3283
- var regLo = Sweep.regionBelow(regUp);
3284
- var eUp = regUp.eUp;
3285
- var eLo = regLo.eUp;
3286
- var degenerate = false;
3287
- if (eUp.Dst !== eLo.Dst) {
3288
- Sweep.checkForIntersect(tess, regUp);
3289
- }
3290
- if (Geom.vertEq(eUp.Org, tess.event)) {
3291
- tess.mesh.splice(eTopLeft.Oprev, eUp);
3292
- regUp = Sweep.topLeftRegion(tess, regUp);
3293
- eTopLeft = Sweep.regionBelow(regUp).eUp;
3294
- Sweep.finishLeftRegions(tess, Sweep.regionBelow(regUp), regLo);
3295
- degenerate = true;
3296
- }
3297
- if (Geom.vertEq(eLo.Org, tess.event)) {
3298
- tess.mesh.splice(eBottomLeft, eLo.Oprev);
3299
- eBottomLeft = Sweep.finishLeftRegions(tess, regLo, null);
3300
- degenerate = true;
3301
- }
3302
- if (degenerate) {
3303
- Sweep.addRightEdges(tess, regUp, eBottomLeft.Onext, eTopLeft, eTopLeft, true);
3304
- return;
3305
- }
3306
- if (Geom.vertLeq(eLo.Org, eUp.Org)) {
3307
- eNew = eLo.Oprev;
3308
- }
3309
- else {
3310
- eNew = eUp;
3311
- }
3312
- eNew = tess.mesh.connect(eBottomLeft.Lprev, eNew);
3313
- Sweep.addRightEdges(tess, regUp, eNew, eNew.Onext, eNew.Onext, false);
3314
- eNew.Sym.activeRegion.fixUpperEdge = true;
3315
- Sweep.walkDirtyRegions(tess, regUp);
3316
- };
3317
- Sweep.connectLeftDegenerate = function (tess, regUp, vEvent) {
3318
- var e, eTopLeft, eTopRight, eLast;
3319
- var reg;
3320
- e = regUp.eUp;
3321
- if (Geom.vertEq(e.Org, vEvent)) {
3322
- assert(false);
3323
- Sweep.spliceMergeVertices(tess, e, vEvent.anEdge);
3324
- return;
3325
- }
3326
- if (!Geom.vertEq(e.Dst, vEvent)) {
3327
- tess.mesh.splitEdge(e.Sym);
3328
- if (regUp.fixUpperEdge) {
3329
- tess.mesh.delete(e.Onext);
3330
- regUp.fixUpperEdge = false;
3331
- }
3332
- tess.mesh.splice(vEvent.anEdge, e);
3333
- Sweep.sweepEvent(tess, vEvent);
3334
- return;
3335
- }
3336
- assert(false);
3337
- regUp = Sweep.topRightRegion(regUp);
3338
- reg = Sweep.regionBelow(regUp);
3339
- eTopRight = reg.eUp.Sym;
3340
- eTopLeft = eLast = eTopRight.Onext;
3341
- if (reg.fixUpperEdge) {
3342
- assert(eTopLeft !== eTopRight);
3343
- Sweep.deleteRegion(tess, reg);
3344
- tess.mesh.delete(eTopRight);
3345
- eTopRight = eTopLeft.Oprev;
3346
- }
3347
- tess.mesh.splice(vEvent.anEdge, eTopRight);
3348
- if (!Geom.edgeGoesLeft(eTopLeft)) {
3349
- eTopLeft = null;
3350
- }
3351
- Sweep.addRightEdges(tess, regUp, eTopRight.Onext, eLast, eTopLeft, true);
3352
- };
3353
- Sweep.connectLeftVertex = function (tess, vEvent) {
3354
- var regUp, regLo, reg;
3355
- var eUp, eLo, eNew;
3356
- var tmp = new ActiveRegion();
3357
- tmp.eUp = vEvent.anEdge.Sym;
3358
- regUp = tess.dict.search(tmp).key;
3359
- regLo = Sweep.regionBelow(regUp);
3360
- if (!regLo) {
3361
- return;
3362
- }
3363
- eUp = regUp.eUp;
3364
- eLo = regLo.eUp;
3365
- if (Geom.edgeSign(eUp.Dst, vEvent, eUp.Org) === 0.0) {
3366
- Sweep.connectLeftDegenerate(tess, regUp, vEvent);
3367
- return;
3368
- }
3369
- reg = Geom.vertLeq(eLo.Dst, eUp.Dst) ? regUp : regLo;
3370
- if (regUp.inside || reg.fixUpperEdge) {
3371
- if (reg === regUp) {
3372
- eNew = tess.mesh.connect(vEvent.anEdge.Sym, eUp.Lnext);
3373
- }
3374
- else {
3375
- var tempHalfEdge = tess.mesh.connect(eLo.Dnext, vEvent.anEdge);
3376
- eNew = tempHalfEdge.Sym;
3377
- }
3378
- if (reg.fixUpperEdge) {
3379
- Sweep.fixUpperEdge(tess, reg, eNew);
3380
- }
3381
- else {
3382
- Sweep.computeWinding(tess, Sweep.addRegionBelow(tess, regUp, eNew));
3383
- }
3384
- Sweep.sweepEvent(tess, vEvent);
3385
- }
3386
- else {
3387
- Sweep.addRightEdges(tess, regUp, vEvent.anEdge, vEvent.anEdge, null, true);
3388
- }
3389
- };
3390
- Sweep.sweepEvent = function (tess, vEvent) {
3391
- tess.event = vEvent;
3392
- Sweep.debugEvent(tess);
3393
- var e = vEvent.anEdge;
3394
- while (e.activeRegion === null) {
3395
- e = e.Onext;
3396
- if (e === vEvent.anEdge) {
3397
- Sweep.connectLeftVertex(tess, vEvent);
3398
- return;
3399
- }
3400
- }
3401
- var regUp = Sweep.topLeftRegion(tess, e.activeRegion);
3402
- assert(regUp !== null);
3403
- var reg = Sweep.regionBelow(regUp);
3404
- var eTopLeft = reg.eUp;
3405
- var eBottomLeft = Sweep.finishLeftRegions(tess, reg, null);
3406
- if (eBottomLeft.Onext === eTopLeft) {
3407
- Sweep.connectRightVertex(tess, regUp, eBottomLeft);
3408
- }
3409
- else {
3410
- Sweep.addRightEdges(tess, regUp, eBottomLeft.Onext, eTopLeft, eTopLeft, true);
3411
- }
3412
- };
3413
- Sweep.addSentinel = function (tess, smin, smax, t) {
3414
- var reg = new ActiveRegion();
3415
- var e = tess.mesh.makeEdge();
3416
- e.Org.s = smax;
3417
- e.Org.t = t;
3418
- e.Dst.s = smin;
3419
- e.Dst.t = t;
3420
- tess.event = e.Dst;
3421
- reg.eUp = e;
3422
- reg.windingNumber = 0;
3423
- reg.inside = false;
3424
- reg.fixUpperEdge = false;
3425
- reg.sentinel = true;
3426
- reg.dirty = false;
3427
- reg.nodeUp = tess.dict.insert(reg);
3428
- };
3429
- Sweep.initEdgeDict = function (tess) {
3430
- tess.dict = new Dict(tess, Sweep.edgeLeq);
3431
- var w = tess.bmax[0] - tess.bmin[0];
3432
- var h = tess.bmax[1] - tess.bmin[1];
3433
- var smin = tess.bmin[0] - w;
3434
- var smax = tess.bmax[0] + w;
3435
- var tmin = tess.bmin[1] - h;
3436
- var tmax = tess.bmax[1] + h;
3437
- Sweep.addSentinel(tess, smin, smax, tmin);
3438
- Sweep.addSentinel(tess, smin, smax, tmax);
3439
- };
3440
- Sweep.doneEdgeDict = function (tess) {
3441
- var reg;
3442
- var fixedEdges = 0;
3443
- while ((reg = tess.dict.min().key) !== null) {
3444
- if (!reg.sentinel) {
3445
- assert(reg.fixUpperEdge);
3446
- assert(++fixedEdges === 1);
3447
- }
3448
- assert(reg.windingNumber === 0);
3449
- Sweep.deleteRegion(tess, reg);
3450
- }
3451
- };
3452
- Sweep.removeDegenerateEdges = function (tess) {
3453
- var e, eNext, eLnext;
3454
- var eHead = tess.mesh.eHead;
3455
- for (e = eHead.next; e !== eHead; e = eNext) {
3456
- eNext = e.next;
3457
- eLnext = e.Lnext;
3458
- if (Geom.vertEq(e.Org, e.Dst) && e.Lnext.Lnext !== e) {
3459
- Sweep.spliceMergeVertices(tess, eLnext, e);
3460
- tess.mesh.delete(e);
3461
- e = eLnext;
3462
- eLnext = e.Lnext;
3463
- }
3464
- if (eLnext.Lnext === e) {
3465
- if (eLnext !== e) {
3466
- if (eLnext === eNext || eLnext === eNext.Sym) {
3467
- eNext = eNext.next;
3468
- }
3469
- tess.mesh.delete(eLnext);
3470
- }
3471
- if (e === eNext || e === eNext.Sym) {
3472
- eNext = eNext.next;
3473
- }
3474
- tess.mesh.delete(e);
3475
- }
3476
- }
3477
- };
3478
- Sweep.initPriorityQ = function (tess) {
3479
- var pq;
3480
- var v, vHead;
3481
- var vertexCount = 0;
3482
- vHead = tess.mesh.vHead;
3483
- for (v = vHead.next; v !== vHead; v = v.next) {
3484
- vertexCount++;
3485
- }
3486
- vertexCount += 8;
3487
- pq = tess.pq = new PriorityQ(vertexCount, Geom.vertLeq);
3488
- vHead = tess.mesh.vHead;
3489
- for (v = vHead.next; v !== vHead; v = v.next) {
3490
- v.pqHandle = pq.insert(v);
3491
- }
3492
- if (v !== vHead) {
3493
- return false;
3494
- }
3495
- pq.init();
3496
- return true;
3497
- };
3498
- Sweep.donePriorityQ = function (tess) {
3499
- tess.pq = null;
3500
- };
3501
- Sweep.removeDegenerateFaces = function (tess, mesh) {
3502
- var f, fNext;
3503
- var e;
3504
- for (f = mesh.fHead.next; f !== mesh.fHead; f = fNext) {
3505
- fNext = f.next;
3506
- e = f.anEdge;
3507
- assert(e.Lnext !== e);
3508
- if (e.Lnext.Lnext === e) {
3509
- Sweep.addWinding(e.Onext, e);
3510
- tess.mesh.delete(e);
3511
- }
3512
- }
3513
- return true;
3514
- };
3515
- Sweep.computeInterior = function (tess, validate) {
3516
- if (validate === void 0) { validate = true; }
3517
- var v, vNext;
3518
- Sweep.removeDegenerateEdges(tess);
3519
- if (!Sweep.initPriorityQ(tess)) {
3520
- return false;
3521
- }
3522
- Sweep.initEdgeDict(tess);
3523
- while ((v = tess.pq.extractMin()) !== null) {
3524
- for (;;) {
3525
- vNext = tess.pq.min();
3526
- if (vNext === null || !Geom.vertEq(vNext, v))
3527
- break;
3528
- vNext = tess.pq.extractMin();
3529
- Sweep.spliceMergeVertices(tess, v.anEdge, vNext.anEdge);
3530
- }
3531
- Sweep.sweepEvent(tess, v);
3532
- }
3533
- tess.event = tess.dict.min().key.eUp.Org;
3534
- Sweep.debugEvent(tess);
3535
- Sweep.doneEdgeDict(tess);
3536
- Sweep.donePriorityQ(tess);
3537
- if (!Sweep.removeDegenerateFaces(tess, tess.mesh)) {
3538
- return false;
3539
- }
3540
- if (validate) {
3541
- tess.mesh.check();
3542
- }
3543
- return true;
3544
- };
3545
- return Sweep;
3546
- }());
2052
+ Original Code. The Original Code is: OpenGL Sample Implementation,
2053
+ Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
2054
+ Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
2055
+ Copyright in any portions created by third parties is as indicated
2056
+ elsewhere herein. All Rights Reserved.
2057
+ */
3547
2058
 
3548
- var Tesselator = (function () {
3549
- function Tesselator() {
3550
- this.mesh = new TESSmesh();
3551
- this.normal = [0.0, 0.0, 0.0];
3552
- this.sUnit = [0.0, 0.0, 0.0];
3553
- this.tUnit = [0.0, 0.0, 0.0];
3554
- this.bmin = [0.0, 0.0];
3555
- this.bmax = [0.0, 0.0];
3556
- this.windingRule = WINDING.ODD;
3557
- this.dict = null;
3558
- this.pq = null;
3559
- this.event = null;
3560
- this.vertexIndexCounter = 0;
3561
- this.vertices = [];
3562
- this.vertexIndices = [];
3563
- this.vertexCount = 0;
3564
- this.elements = [];
3565
- this.elementCount = 0;
3566
- }
3567
- Tesselator.prototype.dot_ = function (u, v) {
3568
- return u[0] * v[0] + u[1] * v[1] + u[2] * v[2];
3569
- };
3570
- Tesselator.prototype.normalize_ = function (v) {
3571
- var len = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
3572
- if (!len) {
3573
- throw "Zero-size vector!";
3574
- }
3575
- len = Math.sqrt(len);
3576
- v[0] /= len;
3577
- v[1] /= len;
3578
- v[2] /= len;
3579
- };
3580
- Tesselator.prototype.longAxis_ = function (v) {
3581
- var i = 0;
3582
- if (Math.abs(v[1]) > Math.abs(v[0])) {
3583
- i = 1;
3584
- }
3585
- if (Math.abs(v[2]) > Math.abs(v[i])) {
3586
- i = 2;
3587
- }
3588
- return i;
3589
- };
3590
- Tesselator.prototype.computeNormal_ = function (norm) {
3591
- var v, v1, v2;
3592
- var c, tLen2, maxLen2;
3593
- var maxVal = [0, 0, 0], minVal = [0, 0, 0], d1 = [0, 0, 0], d2 = [0, 0, 0], tNorm = [0, 0, 0];
3594
- var maxVert = [null, null, null], minVert = [null, null, null];
3595
- var vHead = this.mesh.vHead;
3596
- v = vHead.next;
3597
- for (var i_1 = 0; i_1 < 3; ++i_1) {
3598
- c = v.coords[i_1];
3599
- minVal[i_1] = c;
3600
- minVert[i_1] = v;
3601
- maxVal[i_1] = c;
3602
- maxVert[i_1] = v;
3603
- }
3604
- for (v = vHead.next; v !== vHead; v = v.next) {
3605
- for (var i_2 = 0; i_2 < 3; ++i_2) {
3606
- c = v.coords[i_2];
3607
- if (c < minVal[i_2]) {
3608
- minVal[i_2] = c;
3609
- minVert[i_2] = v;
3610
- }
3611
- if (c > maxVal[i_2]) {
3612
- maxVal[i_2] = c;
3613
- maxVert[i_2] = v;
3614
- }
3615
- }
3616
- }
3617
- var i = 0;
3618
- if (maxVal[1] - minVal[1] > maxVal[0] - minVal[0]) {
3619
- i = 1;
3620
- }
3621
- if (maxVal[2] - minVal[2] > maxVal[i] - minVal[i]) {
3622
- i = 2;
3623
- }
3624
- if (minVal[i] >= maxVal[i]) {
3625
- norm[0] = 0;
3626
- norm[1] = 0;
3627
- norm[2] = 1;
3628
- return;
3629
- }
3630
- maxLen2 = 0;
3631
- v1 = minVert[i];
3632
- v2 = maxVert[i];
3633
- d1[0] = v1.coords[0] - v2.coords[0];
3634
- d1[1] = v1.coords[1] - v2.coords[1];
3635
- d1[2] = v1.coords[2] - v2.coords[2];
3636
- for (v = vHead.next; v !== vHead; v = v.next) {
3637
- d2[0] = v.coords[0] - v2.coords[0];
3638
- d2[1] = v.coords[1] - v2.coords[1];
3639
- d2[2] = v.coords[2] - v2.coords[2];
3640
- tNorm[0] = d1[1] * d2[2] - d1[2] * d2[1];
3641
- tNorm[1] = d1[2] * d2[0] - d1[0] * d2[2];
3642
- tNorm[2] = d1[0] * d2[1] - d1[1] * d2[0];
3643
- tLen2 = tNorm[0] * tNorm[0] + tNorm[1] * tNorm[1] + tNorm[2] * tNorm[2];
3644
- if (tLen2 > maxLen2) {
3645
- maxLen2 = tLen2;
3646
- norm[0] = tNorm[0];
3647
- norm[1] = tNorm[1];
3648
- norm[2] = tNorm[2];
3649
- }
3650
- }
3651
- if (maxLen2 <= 0) {
3652
- norm[0] = norm[1] = norm[2] = 0;
3653
- norm[this.longAxis_(d1)] = 1;
3654
- }
3655
- };
3656
- Tesselator.prototype.checkOrientation_ = function () {
3657
- var fHead = this.mesh.fHead;
3658
- var v, vHead = this.mesh.vHead;
3659
- var e;
3660
- var area = 0;
3661
- for (var f_1 = fHead.next; f_1 !== fHead; f_1 = f_1.next) {
3662
- e = f_1.anEdge;
3663
- if (e.winding <= 0)
3664
- continue;
3665
- do {
3666
- area += (e.Org.s - e.Dst.s) * (e.Org.t + e.Dst.t);
3667
- e = e.Lnext;
3668
- } while (e !== f_1.anEdge);
3669
- }
3670
- if (area < 0) {
3671
- for (v = vHead.next; v !== vHead; v = v.next) {
3672
- v.t = -v.t;
3673
- }
3674
- this.tUnit[0] = -this.tUnit[0];
3675
- this.tUnit[1] = -this.tUnit[1];
3676
- this.tUnit[2] = -this.tUnit[2];
3677
- }
3678
- };
3679
- Tesselator.prototype.projectPolygon_ = function () {
3680
- var vHead = this.mesh.vHead;
3681
- var norm = [0, 0, 0];
3682
- var sUnit, tUnit;
3683
- var computedNormal = false;
3684
- norm[0] = this.normal[0];
3685
- norm[1] = this.normal[1];
3686
- norm[2] = this.normal[2];
3687
- if (!norm[0] && !norm[1] && !norm[2]) {
3688
- this.computeNormal_(norm);
3689
- computedNormal = true;
3690
- }
3691
- sUnit = this.sUnit;
3692
- tUnit = this.tUnit;
3693
- var axis = this.longAxis_(norm);
3694
- sUnit[axis] = 0;
3695
- sUnit[(axis + 1) % 3] = 1.0;
3696
- sUnit[(axis + 2) % 3] = 0.0;
3697
- tUnit[axis] = 0;
3698
- tUnit[(axis + 1) % 3] = 0.0;
3699
- tUnit[(axis + 2) % 3] = norm[axis] > 0 ? 1.0 : -1.0;
3700
- for (var v_1 = vHead.next; v_1 !== vHead; v_1 = v_1.next) {
3701
- v_1.s = this.dot_(v_1.coords, sUnit);
3702
- v_1.t = this.dot_(v_1.coords, tUnit);
3703
- }
3704
- if (computedNormal) {
3705
- this.checkOrientation_();
3706
- }
3707
- var first = true;
3708
- for (var v_2 = vHead.next; v_2 !== vHead; v_2 = v_2.next) {
3709
- if (first) {
3710
- this.bmin[0] = this.bmax[0] = v_2.s;
3711
- this.bmin[1] = this.bmax[1] = v_2.t;
3712
- first = false;
3713
- }
3714
- else {
3715
- if (v_2.s < this.bmin[0])
3716
- this.bmin[0] = v_2.s;
3717
- if (v_2.s > this.bmax[0])
3718
- this.bmax[0] = v_2.s;
3719
- if (v_2.t < this.bmin[1])
3720
- this.bmin[1] = v_2.t;
3721
- if (v_2.t > this.bmax[1])
3722
- this.bmax[1] = v_2.t;
3723
- }
3724
- }
3725
- };
3726
- Tesselator.prototype.addWinding_ = function (eDst, eSrc) {
3727
- eDst.winding += eSrc.winding;
3728
- eDst.Sym.winding += eSrc.Sym.winding;
3729
- };
3730
- Tesselator.prototype.tessellateMonoRegion_ = function (mesh, face) {
3731
- var up, lo;
3732
- up = face.anEdge;
3733
- if (!(up.Lnext !== up && up.Lnext.Lnext !== up)) {
3734
- throw "Mono region invalid";
3735
- }
3736
- for (; Geom.vertLeq(up.Dst, up.Org); up = up.Lprev)
3737
- ;
3738
- for (; Geom.vertLeq(up.Org, up.Dst); up = up.Lnext)
3739
- ;
3740
- lo = up.Lprev;
3741
- var tempHalfEdge = undefined;
3742
- while (up.Lnext !== lo) {
3743
- if (Geom.vertLeq(up.Dst, lo.Org)) {
3744
- while (lo.Lnext !== up &&
3745
- (Geom.edgeGoesLeft(lo.Lnext) ||
3746
- Geom.edgeSign(lo.Org, lo.Dst, lo.Lnext.Dst) <= 0.0)) {
3747
- tempHalfEdge = mesh.connect(lo.Lnext, lo);
3748
- lo = tempHalfEdge.Sym;
3749
- }
3750
- lo = lo.Lprev;
3751
- }
3752
- else {
3753
- while (lo.Lnext !== up &&
3754
- (Geom.edgeGoesRight(up.Lprev) ||
3755
- Geom.edgeSign(up.Dst, up.Org, up.Lprev.Org) >= 0.0)) {
3756
- tempHalfEdge = mesh.connect(up, up.Lprev);
3757
- up = tempHalfEdge.Sym;
3758
- }
3759
- up = up.Lnext;
3760
- }
3761
- }
3762
- if (lo.Lnext === up) {
3763
- throw "Mono region invalid";
3764
- }
3765
- while (lo.Lnext.Lnext !== up) {
3766
- tempHalfEdge = mesh.connect(lo.Lnext, lo);
3767
- lo = tempHalfEdge.Sym;
3768
- }
3769
- return true;
3770
- };
3771
- Tesselator.prototype.tessellateInterior_ = function (mesh) {
3772
- var next;
3773
- for (var f = mesh.fHead.next; f !== mesh.fHead; f = next) {
3774
- next = f.next;
3775
- if (f.inside) {
3776
- if (!this.tessellateMonoRegion_(mesh, f)) {
3777
- return false;
3778
- }
3779
- }
3780
- }
3781
- return true;
3782
- };
3783
- Tesselator.prototype.discardExterior_ = function (mesh) {
3784
- var next;
3785
- for (var f = mesh.fHead.next; f !== mesh.fHead; f = next) {
3786
- next = f.next;
3787
- if (!f.inside) {
3788
- mesh.zapFace(f);
3789
- }
3790
- }
3791
- };
3792
- Tesselator.prototype.setWindingNumber_ = function (mesh, value, keepOnlyBoundary) {
3793
- var eNext;
3794
- for (var e = mesh.eHead.next; e !== mesh.eHead; e = eNext) {
3795
- eNext = e.next;
3796
- if (e.Rface.inside !== e.Lface.inside) {
3797
- e.winding = e.Lface.inside ? value : -value;
3798
- }
3799
- else {
3800
- if (!keepOnlyBoundary) {
3801
- e.winding = 0;
3802
- }
3803
- else {
3804
- mesh.delete(e);
3805
- }
3806
- }
3807
- }
3808
- };
3809
- Tesselator.prototype.getNeighbourFace_ = function (edge) {
3810
- if (!edge.Rface)
3811
- return -1;
3812
- if (!edge.Rface.inside)
3813
- return -1;
3814
- return edge.Rface.n;
3815
- };
3816
- Tesselator.prototype.outputPolymesh_ = function (mesh, elementType, polySize, vertexSize) {
3817
- var edge;
3818
- var maxFaceCount = 0;
3819
- var maxVertexCount = 0;
3820
- var faceVerts;
3821
- if (polySize > 3) {
3822
- mesh.mergeConvexFaces(polySize);
3823
- }
3824
- for (var v = mesh.vHead.next; v !== mesh.vHead; v = v.next) {
3825
- v.n = -1;
3826
- }
3827
- for (var f = mesh.fHead.next; f !== mesh.fHead; f = f.next) {
3828
- f.n = -1;
3829
- if (!f.inside) {
3830
- continue;
3831
- }
3832
- edge = f.anEdge;
3833
- faceVerts = 0;
3834
- do {
3835
- var v = edge.Org;
3836
- if (v.n === -1) {
3837
- v.n = maxVertexCount;
3838
- maxVertexCount++;
3839
- }
3840
- faceVerts++;
3841
- edge = edge.Lnext;
3842
- } while (edge !== f.anEdge);
3843
- if ((faceVerts > polySize)) {
3844
- throw "Face vertex greater that support polygon";
3845
- }
3846
- f.n = maxFaceCount;
3847
- ++maxFaceCount;
3848
- }
3849
- this.elementCount = maxFaceCount;
3850
- if (elementType === ELEMENT.CONNECTED_POLYGONS) {
3851
- maxFaceCount *= 2;
3852
- }
3853
- this.elements = [];
3854
- this.elements.length = maxFaceCount * polySize;
3855
- this.vertexCount = maxVertexCount;
3856
- this.vertices = [];
3857
- this.vertices.length = maxVertexCount * vertexSize;
3858
- this.vertexIndices = [];
3859
- this.vertexIndices.length = maxVertexCount;
3860
- for (var v = mesh.vHead.next; v !== mesh.vHead; v = v.next) {
3861
- if (v.n !== -1) {
3862
- var idx = v.n * vertexSize;
3863
- this.vertices[idx + 0] = v.coords[0];
3864
- this.vertices[idx + 1] = v.coords[1];
3865
- if (vertexSize > 2) {
3866
- this.vertices[idx + 2] = v.coords[2];
3867
- }
3868
- this.vertexIndices[v.n] = v.idx;
3869
- }
3870
- }
3871
- var nel = 0;
3872
- for (var f = mesh.fHead.next; f !== mesh.fHead; f = f.next) {
3873
- if (!f.inside)
3874
- continue;
3875
- edge = f.anEdge;
3876
- faceVerts = 0;
3877
- do {
3878
- var v = edge.Org;
3879
- this.elements[nel++] = v.n;
3880
- faceVerts++;
3881
- edge = edge.Lnext;
3882
- } while (edge !== f.anEdge);
3883
- for (var i_3 = faceVerts; i_3 < polySize; ++i_3) {
3884
- this.elements[nel++] = -1;
3885
- }
3886
- if (elementType === ELEMENT.CONNECTED_POLYGONS) {
3887
- edge = f.anEdge;
3888
- do {
3889
- this.elements[nel++] = this.getNeighbourFace_(edge);
3890
- edge = edge.Lnext;
3891
- } while (edge !== f.anEdge);
3892
- for (var i_4 = faceVerts; i_4 < polySize; ++i_4) {
3893
- this.elements[nel++] = -1;
3894
- }
3895
- }
3896
- }
3897
- };
3898
- Tesselator.prototype.outputContours_ = function (mesh, vertexSize) {
3899
- var edge;
3900
- var start;
3901
- var startVert = 0;
3902
- var vertCount = 0;
3903
- this.vertexCount = 0;
3904
- this.elementCount = 0;
3905
- for (var f = mesh.fHead.next; f !== mesh.fHead; f = f.next) {
3906
- if (!f.inside) {
3907
- continue;
3908
- }
3909
- start = edge = f.anEdge;
3910
- do {
3911
- this.vertexCount++;
3912
- edge = edge.Lnext;
3913
- } while (edge !== start);
3914
- this.elementCount++;
3915
- }
3916
- this.elements = [];
3917
- this.elements.length = this.elementCount * 2;
3918
- this.vertices = [];
3919
- this.vertices.length = this.vertexCount * vertexSize;
3920
- this.vertexIndices = [];
3921
- this.vertexIndices.length = this.vertexCount;
3922
- var nv = 0;
3923
- var nvi = 0;
3924
- var nel = 0;
3925
- startVert = 0;
3926
- for (var f = mesh.fHead.next; f !== mesh.fHead; f = f.next) {
3927
- if (!f.inside) {
3928
- continue;
3929
- }
3930
- vertCount = 0;
3931
- start = edge = f.anEdge;
3932
- do {
3933
- this.vertices[nv++] = edge.Org.coords[0];
3934
- this.vertices[nv++] = edge.Org.coords[1];
3935
- if (vertexSize > 2) {
3936
- this.vertices[nv++] = edge.Org.coords[2];
3937
- }
3938
- this.vertexIndices[nvi++] = edge.Org.idx;
3939
- vertCount++;
3940
- edge = edge.Lnext;
3941
- } while (edge !== start);
3942
- this.elements[nel++] = startVert;
3943
- this.elements[nel++] = vertCount;
3944
- startVert += vertCount;
3945
- }
3946
- };
3947
- Tesselator.prototype.addContour = function (size, vertices) {
3948
- if (this.mesh === null) {
3949
- this.mesh = new TESSmesh();
3950
- }
3951
- if (size < 2) {
3952
- size = 2;
3953
- }
3954
- if (size > 3) {
3955
- size = 3;
3956
- }
3957
- var e = null;
3958
- for (var i = 0; i < vertices.length; i += size) {
3959
- if (e === null) {
3960
- e = this.mesh.makeEdge();
3961
- this.mesh.splice(e, e.Sym);
3962
- }
3963
- else {
3964
- this.mesh.splitEdge(e);
3965
- e = e.Lnext;
3966
- }
3967
- e.Org.coords[0] = vertices[i + 0];
3968
- e.Org.coords[1] = vertices[i + 1];
3969
- if (size > 2) {
3970
- e.Org.coords[2] = vertices[i + 2];
3971
- }
3972
- else {
3973
- e.Org.coords[2] = 0.0;
3974
- }
3975
- e.Org.idx = this.vertexIndexCounter++;
3976
- e.winding = 1;
3977
- e.Sym.winding = -1;
3978
- }
3979
- };
3980
- Tesselator.prototype.tesselate = function (windingRule, elementType, polySize, vertexSize, normal, validate) {
3981
- if (windingRule === void 0) { windingRule = WINDING.ODD; }
3982
- if (elementType === void 0) { elementType = ELEMENT.POLYGONS; }
3983
- if (validate === void 0) { validate = true; }
3984
- this.vertices = [];
3985
- this.elements = [];
3986
- this.vertexIndices = [];
3987
- this.vertexIndexCounter = 0;
3988
- if (normal) {
3989
- this.normal[0] = normal[0];
3990
- this.normal[1] = normal[1];
3991
- this.normal[2] = normal[2];
3992
- }
3993
- this.windingRule = windingRule;
3994
- if (vertexSize < 2) {
3995
- vertexSize = 2;
3996
- }
3997
- if (vertexSize > 3) {
3998
- vertexSize = 3;
3999
- }
4000
- if (!this.mesh) {
4001
- return false;
4002
- }
4003
- this.projectPolygon_();
4004
- Sweep.computeInterior(this, validate);
4005
- var mesh = this.mesh;
4006
- if (elementType === ELEMENT.BOUNDARY_CONTOURS) {
4007
- this.setWindingNumber_(mesh, 1, true);
4008
- }
4009
- else {
4010
- this.tessellateInterior_(mesh);
4011
- }
4012
- if (validate) {
4013
- mesh.check();
4014
- }
4015
- if (elementType === ELEMENT.BOUNDARY_CONTOURS) {
4016
- this.outputContours_(mesh, vertexSize);
4017
- }
4018
- else {
4019
- this.outputPolymesh_(mesh, elementType, polySize, vertexSize);
4020
- }
4021
- return true;
4022
- };
4023
- return Tesselator;
4024
- }());
2059
+ (function (module) {
2060
+ var n;function t(a,b){return a.b===b.b&&a.a===b.a}function u(a,b){return a.b<b.b||a.b===b.b&&a.a<=b.a}function v(a,b,c){var d=b.b-a.b,e=c.b-b.b;return 0<d+e?d<e?b.a-a.a+d/(d+e)*(a.a-c.a):b.a-c.a+e/(d+e)*(c.a-a.a):0}function x(a,b,c){var d=b.b-a.b,e=c.b-b.b;return 0<d+e?(b.a-c.a)*d+(b.a-a.a)*e:0}function z(a,b){return a.a<b.a||a.a===b.a&&a.b<=b.b}function aa(a,b,c){var d=b.a-a.a,e=c.a-b.a;return 0<d+e?d<e?b.b-a.b+d/(d+e)*(a.b-c.b):b.b-c.b+e/(d+e)*(c.b-a.b):0}
2061
+ function ba(a,b,c){var d=b.a-a.a,e=c.a-b.a;return 0<d+e?(b.b-c.b)*d+(b.b-a.b)*e:0}function ca(a){return u(a.b.a,a.a)}function da(a){return u(a.a,a.b.a)}function A(a,b,c,d){a=0>a?0:a;c=0>c?0:c;return a<=c?0===c?(b+d)/2:b+a/(a+c)*(d-b):d+c/(a+c)*(b-d)}function ea(a){var b=B(a.b);C(b,a.c);C(b.b,a.c);D(b,a.a);return b}function E(a,b){var c=!1,d=!1;a!==b&&(b.a!==a.a&&(d=!0,F(b.a,a.a)),b.d!==a.d&&(c=!0,G(b.d,a.d)),H(b,a),d||(C(b,a.a),a.a.c=a),c||(D(b,a.d),a.d.a=a));}function I(a){var b=a.b,c=!1;a.d!==a.b.d&&(c=!0,G(a.d,a.b.d));a.c===a?F(a.a,null):(a.b.d.a=J(a),a.a.c=a.c,H(a,J(a)),c||D(a,a.d));b.c===b?(F(b.a,null),G(b.d,null)):(a.d.a=J(b),b.a.c=b.c,H(b,J(b)));fa(a);}
2062
+ function K(a){var b=B(a),c=b.b;H(b,a.e);b.a=a.b.a;C(c,b.a);b.d=c.d=a.d;b=b.b;H(a.b,J(a.b));H(a.b,b);a.b.a=b.a;b.b.a.c=b.b;b.b.d=a.b.d;b.f=a.f;b.b.f=a.b.f;return b}function L(a,b){var c=!1,d=B(a),e=d.b;b.d!==a.d&&(c=!0,G(b.d,a.d));H(d,a.e);H(e,b);d.a=a.b.a;e.a=b.a;d.d=e.d=a.d;a.d.a=e;c||D(d,a.d);return d}function B(a){var b=new M,c=new M,d=a.b.h;c.h=d;d.b.h=b;b.h=a;a.b.h=c;b.b=c;b.c=b;b.e=c;c.b=b;c.c=c;return c.e=b}function H(a,b){var c=a.c,d=b.c;c.b.e=b;d.b.e=a;a.c=d;b.c=c;}
2063
+ function C(a,b){var c=b.f,d=new N(b,c);c.e=d;b.f=d;c=d.c=a;do c.a=d,c=c.c;while(c!==a)}function D(a,b){var c=b.d,d=new ga(b,c);c.b=d;b.d=d;d.a=a;d.c=b.c;c=a;do c.d=d,c=c.e;while(c!==a)}function fa(a){var b=a.h;a=a.b.h;b.b.h=a;a.b.h=b;}function F(a,b){var c=a.c,d=c;do d.a=b,d=d.c;while(d!==c);c=a.f;d=a.e;d.f=c;c.e=d;}function G(a,b){var c=a.a,d=c;do d.d=b,d=d.e;while(d!==c);c=a.d;d=a.b;d.d=c;c.b=d;}function ha(a){var b=0;Math.abs(a[1])>Math.abs(a[0])&&(b=1);Math.abs(a[2])>Math.abs(a[b])&&(b=2);return b}var O=4*1E150;function P(a,b){a.f+=b.f;a.b.f+=b.b.f;}function ia(a,b,c){a=a.a;b=b.a;c=c.a;if(b.b.a===a)return c.b.a===a?u(b.a,c.a)?0>=x(c.b.a,b.a,c.a):0<=x(b.b.a,c.a,b.a):0>=x(c.b.a,a,c.a);if(c.b.a===a)return 0<=x(b.b.a,a,b.a);b=v(b.b.a,a,b.a);a=v(c.b.a,a,c.a);return b>=a}function Q(a){a.a.i=null;var b=a.e;b.a.c=b.c;b.c.a=b.a;a.e=null;}function ja(a,b){I(a.a);a.c=!1;a.a=b;b.i=a;}function ka(a){var b=a.a.a;do a=R(a);while(a.a.a===b);a.c&&(b=L(S(a).a.b,a.a.e),ja(a,b),a=R(a));return a}
2064
+ function la(a,b,c){var d=new ma;d.a=c;d.e=na(a.f,b.e,d);return c.i=d}function oa(a,b){switch(a.s){case 100130:return 0!==(b&1);case 100131:return 0!==b;case 100132:return 0<b;case 100133:return 0>b;case 100134:return 2<=b||-2>=b}return !1}function pa(a){var b=a.a,c=b.d;c.c=a.d;c.a=b;Q(a);}function T(a,b,c){a=b;for(b=b.a;a!==c;){a.c=!1;var d=S(a),e=d.a;if(e.a!==b.a){if(!d.c){pa(a);break}e=L(b.c.b,e.b);ja(d,e);}b.c!==e&&(E(J(e),e),E(b,e));pa(a);b=d.a;a=d;}return b}
2065
+ function U(a,b,c,d,e,f){var g=!0;do la(a,b,c.b),c=c.c;while(c!==d);for(null===e&&(e=S(b).a.b.c);;){d=S(b);c=d.a.b;if(c.a!==e.a)break;c.c!==e&&(E(J(c),c),E(J(e),c));d.f=b.f-c.f;d.d=oa(a,d.f);b.b=!0;!g&&qa(a,b)&&(P(c,e),Q(b),I(e));g=!1;b=d;e=c;}b.b=!0;f&&ra(a,b);}function sa(a,b,c,d,e){var f=[b.g[0],b.g[1],b.g[2]];b.d=null;b.d=a.o?a.o(f,c,d,a.c)||null:null;null===b.d&&(e?a.n||(V(a,100156),a.n=!0):b.d=c[0]);}
2066
+ function ta(a,b,c){var d=[null,null,null,null];d[0]=b.a.d;d[1]=c.a.d;sa(a,b.a,d,[.5,.5,0,0],!1);E(b,c);}function ua(a,b,c,d,e){var f=Math.abs(b.b-a.b)+Math.abs(b.a-a.a),g=Math.abs(c.b-a.b)+Math.abs(c.a-a.a),h=e+1;d[e]=.5*g/(f+g);d[h]=.5*f/(f+g);a.g[0]+=d[e]*b.g[0]+d[h]*c.g[0];a.g[1]+=d[e]*b.g[1]+d[h]*c.g[1];a.g[2]+=d[e]*b.g[2]+d[h]*c.g[2];}
2067
+ function qa(a,b){var c=S(b),d=b.a,e=c.a;if(u(d.a,e.a)){if(0<x(e.b.a,d.a,e.a))return !1;if(!t(d.a,e.a))K(e.b),E(d,J(e)),b.b=c.b=!0;else if(d.a!==e.a){var c=a.e,f=d.a.h;if(0<=f){var c=c.b,g=c.d,h=c.e,k=c.c,l=k[f];g[l]=g[c.a];k[g[l]]=l;l<=--c.a&&(1>=l?W(c,l):u(h[g[l>>1]],h[g[l]])?W(c,l):va(c,l));h[f]=null;k[f]=c.b;c.b=f;}else for(c.c[-(f+1)]=null;0<c.a&&null===c.c[c.d[c.a-1]];)--c.a;ta(a,J(e),d);}}else {if(0>x(d.b.a,e.a,d.a))return !1;R(b).b=b.b=!0;K(d.b);E(J(e),d);}return !0}
2068
+ function wa(a,b){var c=S(b),d=b.a,e=c.a,f=d.a,g=e.a,h=d.b.a,k=e.b.a,l=new N;x(h,a.a,f);x(k,a.a,g);if(f===g||Math.min(f.a,h.a)>Math.max(g.a,k.a))return !1;if(u(f,g)){if(0<x(k,f,g))return !1}else if(0>x(h,g,f))return !1;var r=h,p=f,q=k,y=g,m,w;u(r,p)||(m=r,r=p,p=m);u(q,y)||(m=q,q=y,y=m);u(r,q)||(m=r,r=q,q=m,m=p,p=y,y=m);u(q,p)?u(p,y)?(m=v(r,q,p),w=v(q,p,y),0>m+w&&(m=-m,w=-w),l.b=A(m,q.b,w,p.b)):(m=x(r,q,p),w=-x(r,y,p),0>m+w&&(m=-m,w=-w),l.b=A(m,q.b,w,y.b)):l.b=(q.b+p.b)/2;z(r,p)||(m=r,r=p,p=m);z(q,y)||
2069
+ (m=q,q=y,y=m);z(r,q)||(m=r,r=q,q=m,m=p,p=y,y=m);z(q,p)?z(p,y)?(m=aa(r,q,p),w=aa(q,p,y),0>m+w&&(m=-m,w=-w),l.a=A(m,q.a,w,p.a)):(m=ba(r,q,p),w=-ba(r,y,p),0>m+w&&(m=-m,w=-w),l.a=A(m,q.a,w,y.a)):l.a=(q.a+p.a)/2;u(l,a.a)&&(l.b=a.a.b,l.a=a.a.a);r=u(f,g)?f:g;u(r,l)&&(l.b=r.b,l.a=r.a);if(t(l,f)||t(l,g))return qa(a,b),!1;if(!t(h,a.a)&&0<=x(h,a.a,l)||!t(k,a.a)&&0>=x(k,a.a,l)){if(k===a.a)return K(d.b),E(e.b,d),b=ka(b),d=S(b).a,T(a,S(b),c),U(a,b,J(d),d,d,!0),!0;if(h===a.a){K(e.b);E(d.e,J(e));f=c=b;g=f.a.b.a;
2070
+ do f=R(f);while(f.a.b.a===g);b=f;f=S(b).a.b.c;c.a=J(e);e=T(a,c,null);U(a,b,e.c,d.b.c,f,!0);return !0}0<=x(h,a.a,l)&&(R(b).b=b.b=!0,K(d.b),d.a.b=a.a.b,d.a.a=a.a.a);0>=x(k,a.a,l)&&(b.b=c.b=!0,K(e.b),e.a.b=a.a.b,e.a.a=a.a.a);return !1}K(d.b);K(e.b);E(J(e),d);d.a.b=l.b;d.a.a=l.a;d.a.h=xa(a.e,d.a);d=d.a;e=[0,0,0,0];l=[f.d,h.d,g.d,k.d];d.g[0]=d.g[1]=d.g[2]=0;ua(d,f,h,e,0);ua(d,g,k,e,2);sa(a,d,l,e,!0);R(b).b=b.b=c.b=!0;return !1}
2071
+ function ra(a,b){for(var c=S(b);;){for(;c.b;)b=c,c=S(c);if(!b.b&&(c=b,b=R(b),null===b||!b.b))break;b.b=!1;var d=b.a,e=c.a,f;if(f=d.b.a!==e.b.a)a:{f=b;var g=S(f),h=f.a,k=g.a,l=void 0;if(u(h.b.a,k.b.a)){if(0>x(h.b.a,k.b.a,h.a)){f=!1;break a}R(f).b=f.b=!0;l=K(h);E(k.b,l);l.d.c=f.d;}else {if(0<x(k.b.a,h.b.a,k.a)){f=!1;break a}f.b=g.b=!0;l=K(k);E(h.e,k.b);l.b.d.c=f.d;}f=!0;}f&&(c.c?(Q(c),I(e),c=S(b),e=c.a):b.c&&(Q(b),I(d),b=R(c),d=b.a));if(d.a!==e.a)if(d.b.a===e.b.a||b.c||c.c||d.b.a!==a.a&&e.b.a!==a.a)qa(a,
2072
+ b);else if(wa(a,b))break;d.a===e.a&&d.b.a===e.b.a&&(P(e,d),Q(b),I(d),b=R(c));}}
2073
+ function ya(a,b){a.a=b;for(var c=b.c;null===c.i;)if(c=c.c,c===b.c){var c=a,d=b,e=new ma;e.a=d.c.b;var f=c.f,g=f.a;do g=g.a;while(null!==g.b&&!f.c(f.b,e,g.b));var f=g.b,h=S(f),e=f.a,g=h.a;if(0===x(e.b.a,d,e.a))e=f.a,t(e.a,d)||t(e.b.a,d)||(K(e.b),f.c&&(I(e.c),f.c=!1),E(d.c,e),ya(c,d));else {var k=u(g.b.a,e.b.a)?f:h,h=void 0;f.d||k.c?(k===f?h=L(d.c.b,e.e):h=L(g.b.c.b,d.c).b,k.c?ja(k,h):(e=c,f=la(c,f,h),f.f=R(f).f+f.a.f,f.d=oa(e,f.f)),ya(c,d)):U(c,f,d.c,d.c,null,!0);}return}c=ka(c.i);e=S(c);f=e.a;e=T(a,
2074
+ e,null);if(e.c===f){var f=e,e=f.c,g=S(c),h=c.a,k=g.a,l=!1;h.b.a!==k.b.a&&wa(a,c);t(h.a,a.a)&&(E(J(e),h),c=ka(c),e=S(c).a,T(a,S(c),g),l=!0);t(k.a,a.a)&&(E(f,J(k)),f=T(a,g,null),l=!0);l?U(a,c,f.c,e,e,!0):(u(k.a,h.a)?d=J(k):d=h,d=L(f.c.b,d),U(a,c,d,d.c,d.c,!1),d.b.i.c=!0,ra(a,c));}else U(a,c,e.c,f,f,!0);}function za(a,b){var c=new ma,d=ea(a.b);d.a.b=O;d.a.a=b;d.b.a.b=-O;d.b.a.a=b;a.a=d.b.a;c.a=d;c.f=0;c.d=!1;c.c=!1;c.h=!0;c.b=!1;d=a.f;d=na(d,d.a,c);c.e=d;}function Aa(a){this.a=new Ba;this.b=a;this.c=ia;}function na(a,b,c){do b=b.c;while(null!==b.b&&!a.c(a.b,b.b,c));a=new Ba(c,b.a,b);b.a.c=a;return b.a=a}function Ba(a,b,c){this.b=a||null;this.a=b||this;this.c=c||this;}function X(){this.d=Y;this.p=this.b=this.q=null;this.j=[0,0,0];this.s=100130;this.n=!1;this.o=this.a=this.e=this.f=null;this.m=!1;this.c=this.r=this.i=this.k=this.l=this.h=null;}var Y=0;n=X.prototype;n.x=function(){Z(this,Y);};n.B=function(a,b){switch(a){case 100142:return;case 100140:switch(b){case 100130:case 100131:case 100132:case 100133:case 100134:this.s=b;return}break;case 100141:this.m=!!b;return;default:V(this,100900);return}V(this,100901);};
2075
+ n.y=function(a){switch(a){case 100142:return 0;case 100140:return this.s;case 100141:return this.m;default:V(this,100900);}return !1};n.A=function(a,b,c){this.j[0]=a;this.j[1]=b;this.j[2]=c;};
2076
+ n.z=function(a,b){var c=b?b:null;switch(a){case 100100:case 100106:this.h=c;break;case 100104:case 100110:this.l=c;break;case 100101:case 100107:this.k=c;break;case 100102:case 100108:this.i=c;break;case 100103:case 100109:this.p=c;break;case 100105:case 100111:this.o=c;break;case 100112:this.r=c;break;default:V(this,100900);}};
2077
+ n.C=function(a,b){var c=!1,d=[0,0,0];Z(this,2);for(var e=0;3>e;++e){var f=a[e];-1E150>f&&(f=-1E150,c=!0);1E150<f&&(f=1E150,c=!0);d[e]=f;}c&&V(this,100155);c=this.q;null===c?(c=ea(this.b),E(c,c.b)):(K(c),c=c.e);c.a.d=b;c.a.g[0]=d[0];c.a.g[1]=d[1];c.a.g[2]=d[2];c.f=1;c.b.f=-1;this.q=c;};n.u=function(a){Z(this,Y);this.d=1;this.b=new Ca;this.c=a;};n.t=function(){Z(this,1);this.d=2;this.q=null;};n.v=function(){Z(this,2);this.d=1;};
2078
+ n.w=function(){Z(this,1);this.d=Y;var a=this.j[0],b=this.j[1],c=this.j[2],d=!1,e=[a,b,c];if(0===a&&0===b&&0===c){for(var b=[-2*1E150,-2*1E150,-2*1E150],f=[2*1E150,2*1E150,2*1E150],c=[],g=[],d=this.b.c,a=d.e;a!==d;a=a.e)for(var h=0;3>h;++h){var k=a.g[h];k<f[h]&&(f[h]=k,g[h]=a);k>b[h]&&(b[h]=k,c[h]=a);}a=0;b[1]-f[1]>b[0]-f[0]&&(a=1);b[2]-f[2]>b[a]-f[a]&&(a=2);if(f[a]>=b[a])e[0]=0,e[1]=0,e[2]=1;else {b=0;f=g[a];c=c[a];g=[0,0,0];f=[f.g[0]-c.g[0],f.g[1]-c.g[1],f.g[2]-c.g[2]];h=[0,0,0];for(a=d.e;a!==d;a=
2079
+ a.e)h[0]=a.g[0]-c.g[0],h[1]=a.g[1]-c.g[1],h[2]=a.g[2]-c.g[2],g[0]=f[1]*h[2]-f[2]*h[1],g[1]=f[2]*h[0]-f[0]*h[2],g[2]=f[0]*h[1]-f[1]*h[0],k=g[0]*g[0]+g[1]*g[1]+g[2]*g[2],k>b&&(b=k,e[0]=g[0],e[1]=g[1],e[2]=g[2]);0>=b&&(e[0]=e[1]=e[2]=0,e[ha(f)]=1);}d=!0;}g=ha(e);a=this.b.c;b=(g+1)%3;c=(g+2)%3;g=0<e[g]?1:-1;for(e=a.e;e!==a;e=e.e)e.b=e.g[b],e.a=g*e.g[c];if(d){e=0;d=this.b.a;for(a=d.b;a!==d;a=a.b)if(b=a.a,!(0>=b.f)){do e+=(b.a.b-b.b.a.b)*(b.a.a+b.b.a.a),b=b.e;while(b!==a.a)}if(0>e)for(e=this.b.c,d=e.e;d!==
2080
+ e;d=d.e)d.a=-d.a;}this.n=!1;e=this.b.b;for(a=e.h;a!==e;a=d)if(d=a.h,b=a.e,t(a.a,a.b.a)&&a.e.e!==a&&(ta(this,b,a),I(a),a=b,b=a.e),b.e===a){if(b!==a){if(b===d||b===d.b)d=d.h;I(b);}if(a===d||a===d.b)d=d.h;I(a);}this.e=e=new Da;d=this.b.c;for(a=d.e;a!==d;a=a.e)a.h=xa(e,a);Ea(e);this.f=new Aa(this);za(this,-O);for(za(this,O);null!==(e=Fa(this.e));){for(;;){a:if(a=this.e,0===a.a)d=Ga(a.b);else if(d=a.c[a.d[a.a-1]],0!==a.b.a&&(a=Ga(a.b),u(a,d))){d=a;break a}if(null===d||!t(d,e))break;d=Fa(this.e);ta(this,e.c,
2081
+ d.c);}ya(this,e);}this.a=this.f.a.a.b.a.a;for(e=0;null!==(d=this.f.a.a.b);)d.h||++e,Q(d);this.f=null;e=this.e;e.b=null;e.d=null;this.e=e.c=null;e=this.b;for(a=e.a.b;a!==e.a;a=d)d=a.b,a=a.a,a.e.e===a&&(P(a.c,a),I(a));if(!this.n){e=this.b;if(this.m)for(a=e.b.h;a!==e.b;a=d)d=a.h,a.b.d.c!==a.d.c?a.f=a.d.c?1:-1:I(a);else for(a=e.a.b;a!==e.a;a=d)if(d=a.b,a.c){for(a=a.a;u(a.b.a,a.a);a=a.c.b);for(;u(a.a,a.b.a);a=a.e);b=a.c.b;for(c=void 0;a.e!==b;)if(u(a.b.a,b.a)){for(;b.e!==a&&(ca(b.e)||0>=x(b.a,b.b.a,b.e.b.a));)c=
2082
+ L(b.e,b),b=c.b;b=b.c.b;}else {for(;b.e!==a&&(da(a.c.b)||0<=x(a.b.a,a.a,a.c.b.a));)c=L(a,a.c.b),a=c.b;a=a.e;}for(;b.e.e!==a;)c=L(b.e,b),b=c.b;}if(this.h||this.i||this.k||this.l)if(this.m)for(e=this.b,d=e.a.b;d!==e.a;d=d.b){if(d.c){this.h&&this.h(2,this.c);a=d.a;do this.k&&this.k(a.a.d,this.c),a=a.e;while(a!==d.a);this.i&&this.i(this.c);}}else {e=this.b;d=!!this.l;a=!1;b=-1;for(c=e.a.d;c!==e.a;c=c.d)if(c.c){a||(this.h&&this.h(4,this.c),a=!0);g=c.a;do d&&(f=g.b.d.c?0:1,b!==f&&(b=f,this.l&&this.l(!!b,this.c))),
2083
+ this.k&&this.k(g.a.d,this.c),g=g.e;while(g!==c.a)}a&&this.i&&this.i(this.c);}if(this.r){e=this.b;for(a=e.a.b;a!==e.a;a=d)if(d=a.b,!a.c){b=a.a;c=b.e;g=void 0;do g=c,c=g.e,g.d=null,null===g.b.d&&(g.c===g?F(g.a,null):(g.a.c=g.c,H(g,J(g))),f=g.b,f.c===f?F(f.a,null):(f.a.c=f.c,H(f,J(f))),fa(g));while(g!==b);b=a.d;a=a.b;a.d=b;b.b=a;}this.r(this.b);this.c=this.b=null;return}}this.b=this.c=null;};
2084
+ function Z(a,b){if(a.d!==b)for(;a.d!==b;)if(a.d<b)switch(a.d){case Y:V(a,100151);a.u(null);break;case 1:V(a,100152),a.t();}else switch(a.d){case 2:V(a,100154);a.v();break;case 1:V(a,100153),a.w();}}function V(a,b){a.p&&a.p(b,a.c);}function ga(a,b){this.b=a||this;this.d=b||this;this.a=null;this.c=!1;}function M(){this.h=this;this.i=this.d=this.a=this.e=this.c=this.b=null;this.f=0;}function J(a){return a.b.e}function Ca(){this.c=new N;this.a=new ga;this.b=new M;this.d=new M;this.b.b=this.d;this.d.b=this.b;}function N(a,b){this.e=a||this;this.f=b||this;this.d=this.c=null;this.g=[0,0,0];this.h=this.a=this.b=0;}function Da(){this.c=[];this.d=null;this.a=0;this.e=!1;this.b=new Ha;}function Ea(a){a.d=[];for(var b=0;b<a.a;b++)a.d[b]=b;a.d.sort(function(a){return function(b,e){return u(a[b],a[e])?1:-1}}(a.c));a.e=!0;Ia(a.b);}function xa(a,b){if(a.e){var c=a.b,d=++c.a;2*d>c.f&&(c.f*=2,c.c=Ja(c.c,c.f+1));var e;0===c.b?e=d:(e=c.b,c.b=c.c[c.b]);c.e[e]=b;c.c[e]=d;c.d[d]=e;c.h&&va(c,d);return e}c=a.a++;a.c[c]=b;return -(c+1)}
2085
+ function Fa(a){if(0===a.a)return Ka(a.b);var b=a.c[a.d[a.a-1]];if(0!==a.b.a&&u(Ga(a.b),b))return Ka(a.b);do--a.a;while(0<a.a&&null===a.c[a.d[a.a-1]]);return b}function Ha(){this.d=Ja([0],33);this.e=[null,null];this.c=[0,0];this.a=0;this.f=32;this.b=0;this.h=!1;this.d[1]=1;}function Ja(a,b){for(var c=Array(b),d=0;d<a.length;d++)c[d]=a[d];for(;d<b;d++)c[d]=0;return c}function Ia(a){for(var b=a.a;1<=b;--b)W(a,b);a.h=!0;}function Ga(a){return a.e[a.d[1]]}function Ka(a){var b=a.d,c=a.e,d=a.c,e=b[1],f=c[e];0<a.a&&(b[1]=b[a.a],d[b[1]]=1,c[e]=null,d[e]=a.b,a.b=e,0<--a.a&&W(a,1));return f}
2086
+ function W(a,b){for(var c=a.d,d=a.e,e=a.c,f=b,g=c[f];;){var h=f<<1;h<a.a&&u(d[c[h+1]],d[c[h]])&&(h+=1);var k=c[h];if(h>a.a||u(d[g],d[k])){c[f]=g;e[g]=f;break}c[f]=k;e[k]=f;f=h;}}function va(a,b){for(var c=a.d,d=a.e,e=a.c,f=b,g=c[f];;){var h=f>>1,k=c[h];if(0===h||u(d[k],d[g])){c[f]=g;e[g]=f;break}c[f]=k;e[k]=f;f=h;}}function ma(){this.e=this.a=null;this.f=0;this.c=this.b=this.h=this.d=!1;}function S(a){return a.e.c.b}function R(a){return a.e.a.b}commonjsGlobal.libtess={GluTesselator:X,windingRule:{GLU_TESS_WINDING_ODD:100130,GLU_TESS_WINDING_NONZERO:100131,GLU_TESS_WINDING_POSITIVE:100132,GLU_TESS_WINDING_NEGATIVE:100133,GLU_TESS_WINDING_ABS_GEQ_TWO:100134},primitiveType:{GL_LINE_LOOP:2,GL_TRIANGLES:4,GL_TRIANGLE_STRIP:5,GL_TRIANGLE_FAN:6},errorType:{GLU_TESS_MISSING_BEGIN_POLYGON:100151,GLU_TESS_MISSING_END_POLYGON:100153,GLU_TESS_MISSING_BEGIN_CONTOUR:100152,GLU_TESS_MISSING_END_CONTOUR:100154,GLU_TESS_COORD_TOO_LARGE:100155,GLU_TESS_NEED_COMBINE_CALLBACK:100156},
2087
+ gluEnum:{GLU_TESS_MESH:100112,GLU_TESS_TOLERANCE:100142,GLU_TESS_WINDING_RULE:100140,GLU_TESS_BOUNDARY_ONLY:100141,GLU_INVALID_ENUM:100900,GLU_INVALID_VALUE:100901,GLU_TESS_BEGIN:100100,GLU_TESS_VERTEX:100101,GLU_TESS_END:100102,GLU_TESS_ERROR:100103,GLU_TESS_EDGE_FLAG:100104,GLU_TESS_COMBINE:100105,GLU_TESS_BEGIN_DATA:100106,GLU_TESS_VERTEX_DATA:100107,GLU_TESS_END_DATA:100108,GLU_TESS_ERROR_DATA:100109,GLU_TESS_EDGE_FLAG_DATA:100110,GLU_TESS_COMBINE_DATA:100111}};X.prototype.gluDeleteTess=X.prototype.x;
2088
+ X.prototype.gluTessProperty=X.prototype.B;X.prototype.gluGetTessProperty=X.prototype.y;X.prototype.gluTessNormal=X.prototype.A;X.prototype.gluTessCallback=X.prototype.z;X.prototype.gluTessVertex=X.prototype.C;X.prototype.gluTessBeginPolygon=X.prototype.u;X.prototype.gluTessBeginContour=X.prototype.t;X.prototype.gluTessEndContour=X.prototype.v;X.prototype.gluTessEndPolygon=X.prototype.w; { module.exports = commonjsGlobal.libtess; }
2089
+ } (libtess_min));
4025
2090
 
4026
- function tesselate(_a) {
4027
- var _b = _a.windingRule, windingRule = _b === void 0 ? WINDING.ODD : _b, _c = _a.elementType, elementType = _c === void 0 ? ELEMENT.POLYGONS : _c, _d = _a.polySize, polySize = _d === void 0 ? 3 : _d, _e = _a.vertexSize, vertexSize = _e === void 0 ? 2 : _e, _f = _a.normal, normal = _f === void 0 ? [0, 0, 1] : _f, _g = _a.contours, contours = _g === void 0 ? [] : _g, _h = _a.strict, strict = _h === void 0 ? true : _h, _j = _a.debug, debug = _j === void 0 ? false : _j;
4028
- if (!contours && strict) {
4029
- throw new Error("Contours can't be empty");
4030
- }
4031
- if (!contours) {
4032
- return undefined;
4033
- }
4034
- var tess = new Tesselator();
4035
- for (var i = 0; i < contours.length; i++) {
4036
- tess.addContour(vertexSize || 2, contours[i]);
4037
- }
4038
- tess.tesselate(windingRule, elementType, polySize, vertexSize, normal, strict);
4039
- return {
4040
- vertices: tess.vertices,
4041
- vertexIndices: tess.vertexIndices,
4042
- vertexCount: tess.vertexCount,
4043
- elements: tess.elements,
4044
- elementCount: tess.elementCount,
4045
- mesh: debug ? tess.mesh : undefined,
4046
- };
4047
- }
4048
- WINDING.ODD;
4049
- WINDING.NONZERO;
4050
- WINDING.POSITIVE;
4051
- WINDING.NEGATIVE;
4052
- WINDING.ABS_GEQ_TWO;
4053
- ELEMENT.POLYGONS;
4054
- ELEMENT.CONNECTED_POLYGONS;
4055
- ELEMENT.BOUNDARY_CONTOURS;
2091
+ var libtess_minExports = libtess_min.exports;
4056
2092
 
4057
2093
  class Tessellator {
4058
2094
  process(paths, removeOverlaps = true, isCFF = false) {
@@ -4075,9 +2111,9 @@
4075
2111
  if (removeOverlaps) {
4076
2112
  debugLogger.log('Two-pass: boundary extraction then triangulation');
4077
2113
  // Extract boundaries to remove overlaps
4078
- const boundaryResult = this.performTessellation(contours, ELEMENT.BOUNDARY_CONTOURS);
2114
+ const boundaryResult = this.performTessellation(contours, 'boundary');
4079
2115
  if (!boundaryResult) {
4080
- debugLogger.warn('Tess2 returned empty result from boundary pass');
2116
+ debugLogger.warn('libtess returned empty result from boundary pass');
4081
2117
  return { triangles: { vertices: [], indices: [] }, contours: [] };
4082
2118
  }
4083
2119
  // Convert boundary elements back to contours
@@ -4087,19 +2123,19 @@
4087
2123
  else {
4088
2124
  debugLogger.log(`Single-pass triangulation for ${isCFF ? 'CFF' : 'TTF'}`);
4089
2125
  }
4090
- // Triangulate the (possibly cleaned) contours
4091
- const triangleResult = this.performTessellation(contours, ELEMENT.POLYGONS);
2126
+ // Triangulate the contours
2127
+ const triangleResult = this.performTessellation(contours, 'triangles');
4092
2128
  if (!triangleResult) {
4093
2129
  const warning = removeOverlaps
4094
- ? 'Tess2 returned empty result from triangulation pass'
4095
- : 'Tess2 returned empty result from single-pass triangulation';
2130
+ ? 'libtess returned empty result from triangulation pass'
2131
+ : 'libtess returned empty result from single-pass triangulation';
4096
2132
  debugLogger.warn(warning);
4097
2133
  return { triangles: { vertices: [], indices: [] }, contours };
4098
2134
  }
4099
2135
  return {
4100
2136
  triangles: {
4101
- vertices: Array.from(triangleResult.vertices),
4102
- indices: Array.from(triangleResult.elements)
2137
+ vertices: triangleResult.vertices,
2138
+ indices: triangleResult.indices || []
4103
2139
  },
4104
2140
  contours
4105
2141
  };
@@ -4113,27 +2149,75 @@
4113
2149
  return contour;
4114
2150
  });
4115
2151
  }
4116
- performTessellation(contours, elementType) {
4117
- const result = tesselate({
4118
- contours,
4119
- windingRule: WINDING.NONZERO,
4120
- elementType,
4121
- polySize: 3,
4122
- vertexSize: 2,
4123
- strict: false
2152
+ performTessellation(contours, mode) {
2153
+ const tess = new libtess_minExports.GluTesselator();
2154
+ // Set winding rule to NON-ZERO
2155
+ tess.gluTessProperty(libtess_minExports.gluEnum.GLU_TESS_WINDING_RULE, libtess_minExports.windingRule.GLU_TESS_WINDING_NONZERO);
2156
+ const vertices = [];
2157
+ const indices = [];
2158
+ const contourIndices = [];
2159
+ let currentContour = [];
2160
+ if (mode === 'boundary') {
2161
+ tess.gluTessProperty(libtess_minExports.gluEnum.GLU_TESS_BOUNDARY_ONLY, true);
2162
+ }
2163
+ if (mode === 'triangles') {
2164
+ tess.gluTessCallback(libtess_minExports.gluEnum.GLU_TESS_VERTEX_DATA, (data) => {
2165
+ indices.push(data);
2166
+ });
2167
+ }
2168
+ else {
2169
+ tess.gluTessCallback(libtess_minExports.gluEnum.GLU_TESS_BEGIN, () => {
2170
+ currentContour = [];
2171
+ });
2172
+ tess.gluTessCallback(libtess_minExports.gluEnum.GLU_TESS_VERTEX_DATA, (data) => {
2173
+ currentContour.push(data);
2174
+ });
2175
+ tess.gluTessCallback(libtess_minExports.gluEnum.GLU_TESS_END, () => {
2176
+ if (currentContour.length > 0) {
2177
+ contourIndices.push([...currentContour]);
2178
+ }
2179
+ });
2180
+ }
2181
+ tess.gluTessCallback(libtess_minExports.gluEnum.GLU_TESS_COMBINE, (coords) => {
2182
+ const idx = vertices.length / 2;
2183
+ vertices.push(coords[0], coords[1]);
2184
+ return idx;
4124
2185
  });
4125
- return result?.vertices && result?.elements ? result : null;
2186
+ tess.gluTessCallback(libtess_minExports.gluEnum.GLU_TESS_ERROR, (errno) => {
2187
+ debugLogger.warn(`libtess error: ${errno}`);
2188
+ });
2189
+ tess.gluTessNormal(0, 0, 1);
2190
+ tess.gluTessBeginPolygon(null);
2191
+ for (const contour of contours) {
2192
+ tess.gluTessBeginContour();
2193
+ for (let i = 0; i < contour.length; i += 2) {
2194
+ const idx = vertices.length / 2;
2195
+ vertices.push(contour[i], contour[i + 1]);
2196
+ tess.gluTessVertex([contour[i], contour[i + 1], 0], idx);
2197
+ }
2198
+ tess.gluTessEndContour();
2199
+ }
2200
+ tess.gluTessEndPolygon();
2201
+ if (vertices.length === 0) {
2202
+ return null;
2203
+ }
2204
+ if (mode === 'triangles') {
2205
+ return { vertices, indices };
2206
+ }
2207
+ else {
2208
+ return { vertices, contourIndices };
2209
+ }
4126
2210
  }
4127
2211
  boundaryToContours(boundaryResult) {
2212
+ if (!boundaryResult.contourIndices) {
2213
+ return [];
2214
+ }
4128
2215
  const contours = [];
4129
- // Elements format: [start_index, vertex_count, start_index, vertex_count, ...]
4130
- for (let i = 0; i < boundaryResult.elements.length; i += 2) {
4131
- const start = boundaryResult.elements[i];
4132
- const count = boundaryResult.elements[i + 1];
2216
+ for (const indices of boundaryResult.contourIndices) {
4133
2217
  const contour = [];
4134
- for (let j = 0; j < count; j++) {
4135
- const idx = (start + j) * 2;
4136
- contour.push(boundaryResult.vertices[idx], boundaryResult.vertices[idx + 1]);
2218
+ for (const idx of indices) {
2219
+ const vertIdx = idx * 2;
2220
+ contour.push(boundaryResult.vertices[vertIdx], boundaryResult.vertices[vertIdx + 1]);
4137
2221
  }
4138
2222
  // Ensure contour is closed for side wall generation
4139
2223
  if (contour.length > 2) {
@@ -5664,35 +3748,6 @@
5664
3748
  }
5665
3749
  const globalGlyphCache = new GlyphCache(DEFAULT_CACHE_SIZE_MB);
5666
3750
 
5667
- function getDefaultExportFromCjs (x) {
5668
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5669
- }
5670
-
5671
- function getAugmentedNamespace(n) {
5672
- if (n.__esModule) return n;
5673
- var f = n.default;
5674
- if (typeof f == "function") {
5675
- var a = function a () {
5676
- if (this instanceof a) {
5677
- return Reflect.construct(f, arguments, this.constructor);
5678
- }
5679
- return f.apply(this, arguments);
5680
- };
5681
- a.prototype = f.prototype;
5682
- } else a = {};
5683
- Object.defineProperty(a, '__esModule', {value: true});
5684
- Object.keys(n).forEach(function (k) {
5685
- var d = Object.getOwnPropertyDescriptor(n, k);
5686
- Object.defineProperty(a, k, d.get ? d : {
5687
- enumerable: true,
5688
- get: function () {
5689
- return n[k];
5690
- }
5691
- });
5692
- });
5693
- return a;
5694
- }
5695
-
5696
3751
  var hb = {exports: {}};
5697
3752
 
5698
3753
  var fs = {}; const readFileSync = () => { throw new Error('fs not available in browser'); };