three-text 0.2.3 → 0.2.5

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