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