@mui/x-charts-vendor 7.12.0
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/README.md +76 -0
- package/d3-color.d.ts +5 -0
- package/d3-color.js +7 -0
- package/d3-delaunay.d.ts +5 -0
- package/d3-delaunay.js +7 -0
- package/d3-interpolate.d.ts +5 -0
- package/d3-interpolate.js +7 -0
- package/d3-scale.d.ts +5 -0
- package/d3-scale.js +7 -0
- package/d3-shape.d.ts +5 -0
- package/d3-shape.js +7 -0
- package/d3-time.d.ts +5 -0
- package/d3-time.js +7 -0
- package/es/d3-array.js +6 -0
- package/es/d3-color.js +6 -0
- package/es/d3-delaunay.js +6 -0
- package/es/d3-format.js +6 -0
- package/es/d3-interpolate.js +6 -0
- package/es/d3-path.js +6 -0
- package/es/d3-scale.js +6 -0
- package/es/d3-shape.js +6 -0
- package/es/d3-time-format.js +6 -0
- package/es/d3-time.js +6 -0
- package/es/delaunator.js +6 -0
- package/es/internmap.js +6 -0
- package/es/robust-predicates.js +6 -0
- package/lib/d3-array.js +6 -0
- package/lib/d3-color.js +6 -0
- package/lib/d3-delaunay.js +6 -0
- package/lib/d3-format.js +6 -0
- package/lib/d3-interpolate.js +6 -0
- package/lib/d3-path.js +6 -0
- package/lib/d3-scale.js +6 -0
- package/lib/d3-shape.js +6 -0
- package/lib/d3-time-format.js +6 -0
- package/lib/d3-time.js +6 -0
- package/lib/delaunator.js +6 -0
- package/lib/internmap.js +6 -0
- package/lib/robust-predicates.js +6 -0
- package/lib-vendor/d3-array/LICENSE +13 -0
- package/lib-vendor/d3-array/dist/d3-array.js +1349 -0
- package/lib-vendor/d3-array/dist/d3-array.min.js +777 -0
- package/lib-vendor/d3-array/src/array.js +9 -0
- package/lib-vendor/d3-array/src/ascending.js +9 -0
- package/lib-vendor/d3-array/src/bin.js +126 -0
- package/lib-vendor/d3-array/src/bisect.js +15 -0
- package/lib-vendor/d3-array/src/bisector.js +59 -0
- package/lib-vendor/d3-array/src/blur.js +122 -0
- package/lib-vendor/d3-array/src/constant.js +9 -0
- package/lib-vendor/d3-array/src/count.js +24 -0
- package/lib-vendor/d3-array/src/cross.js +35 -0
- package/lib-vendor/d3-array/src/cumsum.js +11 -0
- package/lib-vendor/d3-array/src/descending.js +9 -0
- package/lib-vendor/d3-array/src/deviation.js +12 -0
- package/lib-vendor/d3-array/src/difference.js +16 -0
- package/lib-vendor/d3-array/src/disjoint.js +24 -0
- package/lib-vendor/d3-array/src/every.js +16 -0
- package/lib-vendor/d3-array/src/extent.js +35 -0
- package/lib-vendor/d3-array/src/filter.js +17 -0
- package/lib-vendor/d3-array/src/fsum.js +77 -0
- package/lib-vendor/d3-array/src/greatest.js +31 -0
- package/lib-vendor/d3-array/src/greatestIndex.js +23 -0
- package/lib-vendor/d3-array/src/group.js +67 -0
- package/lib-vendor/d3-array/src/groupSort.js +15 -0
- package/lib-vendor/d3-array/src/identity.js +9 -0
- package/lib-vendor/d3-array/src/index.js +539 -0
- package/lib-vendor/d3-array/src/intersection.js +23 -0
- package/lib-vendor/d3-array/src/least.js +31 -0
- package/lib-vendor/d3-array/src/leastIndex.js +23 -0
- package/lib-vendor/d3-array/src/map.js +11 -0
- package/lib-vendor/d3-array/src/max.js +24 -0
- package/lib-vendor/d3-array/src/maxIndex.js +26 -0
- package/lib-vendor/d3-array/src/mean.js +25 -0
- package/lib-vendor/d3-array/src/median.js +16 -0
- package/lib-vendor/d3-array/src/merge.js +14 -0
- package/lib-vendor/d3-array/src/min.js +24 -0
- package/lib-vendor/d3-array/src/minIndex.js +26 -0
- package/lib-vendor/d3-array/src/mode.js +33 -0
- package/lib-vendor/d3-array/src/nice.js +23 -0
- package/lib-vendor/d3-array/src/number.js +26 -0
- package/lib-vendor/d3-array/src/pairs.js +21 -0
- package/lib-vendor/d3-array/src/permute.js +9 -0
- package/lib-vendor/d3-array/src/quantile.js +55 -0
- package/lib-vendor/d3-array/src/quickselect.js +47 -0
- package/lib-vendor/d3-array/src/range.js +16 -0
- package/lib-vendor/d3-array/src/rank.js +30 -0
- package/lib-vendor/d3-array/src/reduce.js +28 -0
- package/lib-vendor/d3-array/src/reverse.js +10 -0
- package/lib-vendor/d3-array/src/scan.js +12 -0
- package/lib-vendor/d3-array/src/shuffle.js +20 -0
- package/lib-vendor/d3-array/src/some.js +16 -0
- package/lib-vendor/d3-array/src/sort.js +45 -0
- package/lib-vendor/d3-array/src/subset.js +11 -0
- package/lib-vendor/d3-array/src/sum.js +24 -0
- package/lib-vendor/d3-array/src/superset.js +28 -0
- package/lib-vendor/d3-array/src/threshold/freedmanDiaconis.js +14 -0
- package/lib-vendor/d3-array/src/threshold/scott.js +14 -0
- package/lib-vendor/d3-array/src/threshold/sturges.js +11 -0
- package/lib-vendor/d3-array/src/ticks.js +60 -0
- package/lib-vendor/d3-array/src/transpose.js +20 -0
- package/lib-vendor/d3-array/src/union.js +16 -0
- package/lib-vendor/d3-array/src/variance.js +31 -0
- package/lib-vendor/d3-array/src/zip.js +11 -0
- package/lib-vendor/d3-color/LICENSE +13 -0
- package/lib-vendor/d3-color/dist/d3-color.js +532 -0
- package/lib-vendor/d3-color/dist/d3-color.min.js +446 -0
- package/lib-vendor/d3-color/src/color.js +366 -0
- package/lib-vendor/d3-color/src/cubehelix.js +61 -0
- package/lib-vendor/d3-color/src/define.js +16 -0
- package/lib-vendor/d3-color/src/index.js +59 -0
- package/lib-vendor/d3-color/src/lab.js +117 -0
- package/lib-vendor/d3-color/src/math.js +8 -0
- package/lib-vendor/d3-delaunay/LICENSE +14 -0
- package/lib-vendor/d3-delaunay/dist/d3-delaunay.js +1398 -0
- package/lib-vendor/d3-delaunay/dist/d3-delaunay.min.js +853 -0
- package/lib-vendor/d3-delaunay/src/delaunay.js +282 -0
- package/lib-vendor/d3-delaunay/src/index.js +20 -0
- package/lib-vendor/d3-delaunay/src/path.js +43 -0
- package/lib-vendor/d3-delaunay/src/polygon.js +24 -0
- package/lib-vendor/d3-delaunay/src/voronoi.js +390 -0
- package/lib-vendor/d3-format/LICENSE +13 -0
- package/lib-vendor/d3-format/dist/d3-format.js +313 -0
- package/lib-vendor/d3-format/dist/d3-format.min.js +193 -0
- package/lib-vendor/d3-format/src/defaultLocale.js +23 -0
- package/lib-vendor/d3-format/src/exponent.js +10 -0
- package/lib-vendor/d3-format/src/formatDecimal.js +23 -0
- package/lib-vendor/d3-format/src/formatGroup.js +22 -0
- package/lib-vendor/d3-format/src/formatNumerals.js +13 -0
- package/lib-vendor/d3-format/src/formatPrefixAuto.js +18 -0
- package/lib-vendor/d3-format/src/formatRounded.js +14 -0
- package/lib-vendor/d3-format/src/formatSpecifier.js +42 -0
- package/lib-vendor/d3-format/src/formatTrim.js +25 -0
- package/lib-vendor/d3-format/src/formatTypes.js +25 -0
- package/lib-vendor/d3-format/src/identity.js +9 -0
- package/lib-vendor/d3-format/src/index.js +68 -0
- package/lib-vendor/d3-format/src/locale.js +152 -0
- package/lib-vendor/d3-format/src/precisionFixed.js +11 -0
- package/lib-vendor/d3-format/src/precisionPrefix.js +11 -0
- package/lib-vendor/d3-format/src/precisionRound.js +12 -0
- package/lib-vendor/d3-interpolate/LICENSE +13 -0
- package/lib-vendor/d3-interpolate/dist/d3-interpolate.js +543 -0
- package/lib-vendor/d3-interpolate/dist/d3-interpolate.min.js +362 -0
- package/lib-vendor/d3-interpolate/src/array.js +28 -0
- package/lib-vendor/d3-interpolate/src/basis.js +23 -0
- package/lib-vendor/d3-interpolate/src/basisClosed.js +18 -0
- package/lib-vendor/d3-interpolate/src/color.js +33 -0
- package/lib-vendor/d3-interpolate/src/constant.js +8 -0
- package/lib-vendor/d3-interpolate/src/cubehelix.js +32 -0
- package/lib-vendor/d3-interpolate/src/date.js +12 -0
- package/lib-vendor/d3-interpolate/src/discrete.js +12 -0
- package/lib-vendor/d3-interpolate/src/hcl.js +27 -0
- package/lib-vendor/d3-interpolate/src/hsl.js +27 -0
- package/lib-vendor/d3-interpolate/src/hue.js +14 -0
- package/lib-vendor/d3-interpolate/src/index.js +191 -0
- package/lib-vendor/d3-interpolate/src/lab.js +22 -0
- package/lib-vendor/d3-interpolate/src/number.js +11 -0
- package/lib-vendor/d3-interpolate/src/numberArray.js +20 -0
- package/lib-vendor/d3-interpolate/src/object.js +26 -0
- package/lib-vendor/d3-interpolate/src/piecewise.js +20 -0
- package/lib-vendor/d3-interpolate/src/quantize.js +11 -0
- package/lib-vendor/d3-interpolate/src/rgb.js +59 -0
- package/lib-vendor/d3-interpolate/src/round.js +11 -0
- package/lib-vendor/d3-interpolate/src/string.js +75 -0
- package/lib-vendor/d3-interpolate/src/transform/decompose.js +31 -0
- package/lib-vendor/d3-interpolate/src/transform/index.js +83 -0
- package/lib-vendor/d3-interpolate/src/transform/parse.js +25 -0
- package/lib-vendor/d3-interpolate/src/value.js +23 -0
- package/lib-vendor/d3-interpolate/src/zoom.js +66 -0
- package/lib-vendor/d3-path/LICENSE +13 -0
- package/lib-vendor/d3-path/dist/d3-path.js +161 -0
- package/lib-vendor/d3-path/dist/d3-path.min.js +92 -0
- package/lib-vendor/d3-path/src/index.js +24 -0
- package/lib-vendor/d3-path/src/path.js +158 -0
- package/lib-vendor/d3-scale/LICENSE +13 -0
- package/lib-vendor/d3-scale/dist/d3-scale.js +944 -0
- package/lib-vendor/d3-scale/dist/d3-scale.min.js +690 -0
- package/lib-vendor/d3-scale/src/band.js +87 -0
- package/lib-vendor/d3-scale/src/colors.js +11 -0
- package/lib-vendor/d3-scale/src/constant.js +11 -0
- package/lib-vendor/d3-scale/src/continuous.js +116 -0
- package/lib-vendor/d3-scale/src/diverging.js +91 -0
- package/lib-vendor/d3-scale/src/identity.js +27 -0
- package/lib-vendor/d3-scale/src/index.js +193 -0
- package/lib-vendor/d3-scale/src/init.js +38 -0
- package/lib-vendor/d3-scale/src/linear.js +67 -0
- package/lib-vendor/d3-scale/src/log.js +123 -0
- package/lib-vendor/d3-scale/src/nice.js +21 -0
- package/lib-vendor/d3-scale/src/number.js +9 -0
- package/lib-vendor/d3-scale/src/ordinal.js +44 -0
- package/lib-vendor/d3-scale/src/pow.js +44 -0
- package/lib-vendor/d3-scale/src/quantile.js +48 -0
- package/lib-vendor/d3-scale/src/quantize.js +46 -0
- package/lib-vendor/d3-scale/src/radial.js +53 -0
- package/lib-vendor/d3-scale/src/sequential.js +90 -0
- package/lib-vendor/d3-scale/src/sequentialQuantile.js +38 -0
- package/lib-vendor/d3-scale/src/symlog.js +35 -0
- package/lib-vendor/d3-scale/src/threshold.js +34 -0
- package/lib-vendor/d3-scale/src/tickFormat.js +37 -0
- package/lib-vendor/d3-scale/src/time.js +62 -0
- package/lib-vendor/d3-scale/src/utcTime.js +13 -0
- package/lib-vendor/d3-shape/LICENSE +13 -0
- package/lib-vendor/d3-shape/dist/d3-shape.js +2004 -0
- package/lib-vendor/d3-shape/dist/d3-shape.min.js +1389 -0
- package/lib-vendor/d3-shape/src/arc.js +250 -0
- package/lib-vendor/d3-shape/src/area.js +98 -0
- package/lib-vendor/d3-shape/src/areaRadial.js +42 -0
- package/lib-vendor/d3-shape/src/array.js +12 -0
- package/lib-vendor/d3-shape/src/constant.js +11 -0
- package/lib-vendor/d3-shape/src/curve/basis.js +62 -0
- package/lib-vendor/d3-shape/src/curve/basisClosed.js +70 -0
- package/lib-vendor/d3-shape/src/curve/basisOpen.js +54 -0
- package/lib-vendor/d3-shape/src/curve/bump.js +81 -0
- package/lib-vendor/d3-shape/src/curve/bundle.js +50 -0
- package/lib-vendor/d3-shape/src/curve/cardinal.js +69 -0
- package/lib-vendor/d3-shape/src/curve/cardinalClosed.js +76 -0
- package/lib-vendor/d3-shape/src/curve/cardinalOpen.js +60 -0
- package/lib-vendor/d3-shape/src/curve/catmullRom.js +92 -0
- package/lib-vendor/d3-shape/src/curve/catmullRomClosed.js +83 -0
- package/lib-vendor/d3-shape/src/curve/catmullRomOpen.js +67 -0
- package/lib-vendor/d3-shape/src/curve/linear.js +42 -0
- package/lib-vendor/d3-shape/src/curve/linearClosed.js +28 -0
- package/lib-vendor/d3-shape/src/curve/monotone.js +121 -0
- package/lib-vendor/d3-shape/src/curve/natural.js +67 -0
- package/lib-vendor/d3-shape/src/curve/radial.js +37 -0
- package/lib-vendor/d3-shape/src/curve/step.js +63 -0
- package/lib-vendor/d3-shape/src/descending.js +9 -0
- package/lib-vendor/d3-shape/src/identity.js +9 -0
- package/lib-vendor/d3-shape/src/index.js +436 -0
- package/lib-vendor/d3-shape/src/line.js +52 -0
- package/lib-vendor/d3-shape/src/lineRadial.js +24 -0
- package/lib-vendor/d3-shape/src/link.js +70 -0
- package/lib-vendor/d3-shape/src/math.js +26 -0
- package/lib-vendor/d3-shape/src/noop.js +7 -0
- package/lib-vendor/d3-shape/src/offset/diverging.js +20 -0
- package/lib-vendor/d3-shape/src/offset/expand.js +16 -0
- package/lib-vendor/d3-shape/src/offset/none.js +15 -0
- package/lib-vendor/d3-shape/src/offset/silhouette.js +16 -0
- package/lib-vendor/d3-shape/src/offset/wiggle.js +30 -0
- package/lib-vendor/d3-shape/src/order/appearance.js +23 -0
- package/lib-vendor/d3-shape/src/order/ascending.js +23 -0
- package/lib-vendor/d3-shape/src/order/descending.js +11 -0
- package/lib-vendor/d3-shape/src/order/insideOut.js +31 -0
- package/lib-vendor/d3-shape/src/order/none.js +12 -0
- package/lib-vendor/d3-shape/src/order/reverse.js +11 -0
- package/lib-vendor/d3-shape/src/path.js +22 -0
- package/lib-vendor/d3-shape/src/pie.js +79 -0
- package/lib-vendor/d3-shape/src/point.js +13 -0
- package/lib-vendor/d3-shape/src/pointRadial.js +9 -0
- package/lib-vendor/d3-shape/src/stack.js +55 -0
- package/lib-vendor/d3-shape/src/symbol/asterisk.js +21 -0
- package/lib-vendor/d3-shape/src/symbol/circle.js +14 -0
- package/lib-vendor/d3-shape/src/symbol/cross.js +25 -0
- package/lib-vendor/d3-shape/src/symbol/diamond.js +20 -0
- package/lib-vendor/d3-shape/src/symbol/diamond2.js +17 -0
- package/lib-vendor/d3-shape/src/symbol/plus.js +16 -0
- package/lib-vendor/d3-shape/src/symbol/square.js +14 -0
- package/lib-vendor/d3-shape/src/symbol/square2.js +17 -0
- package/lib-vendor/d3-shape/src/symbol/star.js +28 -0
- package/lib-vendor/d3-shape/src/symbol/times.js +16 -0
- package/lib-vendor/d3-shape/src/symbol/triangle.js +17 -0
- package/lib-vendor/d3-shape/src/symbol/triangle2.js +19 -0
- package/lib-vendor/d3-shape/src/symbol/wye.js +32 -0
- package/lib-vendor/d3-shape/src/symbol.js +50 -0
- package/lib-vendor/d3-time/LICENSE +13 -0
- package/lib-vendor/d3-time/dist/d3-time.js +367 -0
- package/lib-vendor/d3-time/dist/d3-time.min.js +190 -0
- package/lib-vendor/d3-time/src/day.js +30 -0
- package/lib-vendor/d3-time/src/duration.js +13 -0
- package/lib-vendor/d3-time/src/hour.js +28 -0
- package/lib-vendor/d3-time/src/index.js +417 -0
- package/lib-vendor/d3-time/src/interval.js +61 -0
- package/lib-vendor/d3-time/src/millisecond.js +29 -0
- package/lib-vendor/d3-time/src/minute.js +28 -0
- package/lib-vendor/d3-time/src/month.js +29 -0
- package/lib-vendor/d3-time/src/second.js +18 -0
- package/lib-vendor/d3-time/src/ticks.js +41 -0
- package/lib-vendor/d3-time/src/week.js +56 -0
- package/lib-vendor/d3-time/src/year.js +51 -0
- package/lib-vendor/d3-time-format/LICENSE +13 -0
- package/lib-vendor/d3-time-format/dist/d3-time-format.js +648 -0
- package/lib-vendor/d3-time-format/dist/d3-time-format.min.js +528 -0
- package/lib-vendor/d3-time-format/src/defaultLocale.js +32 -0
- package/lib-vendor/d3-time-format/src/index.js +60 -0
- package/lib-vendor/d3-time-format/src/isoFormat.js +13 -0
- package/lib-vendor/d3-time-format/src/isoParse.js +14 -0
- package/lib-vendor/d3-time-format/src/locale.js +606 -0
- package/lib-vendor/delaunator/LICENSE +15 -0
- package/lib-vendor/delaunator/delaunator.js +688 -0
- package/lib-vendor/delaunator/delaunator.min.js +316 -0
- package/lib-vendor/delaunator/index.js +440 -0
- package/lib-vendor/internmap/LICENSE +13 -0
- package/lib-vendor/internmap/dist/internmap.js +93 -0
- package/lib-vendor/internmap/dist/internmap.min.js +81 -0
- package/lib-vendor/internmap/src/index.js +87 -0
- package/lib-vendor/robust-predicates/LICENSE +24 -0
- package/lib-vendor/robust-predicates/esm/incircle.js +667 -0
- package/lib-vendor/robust-predicates/esm/insphere.js +693 -0
- package/lib-vendor/robust-predicates/esm/orient2d.js +174 -0
- package/lib-vendor/robust-predicates/esm/orient3d.js +422 -0
- package/lib-vendor/robust-predicates/esm/util.js +147 -0
- package/lib-vendor/robust-predicates/index.js +57 -0
- package/lib-vendor/robust-predicates/umd/incircle.js +798 -0
- package/lib-vendor/robust-predicates/umd/incircle.min.js +170 -0
- package/lib-vendor/robust-predicates/umd/insphere.js +828 -0
- package/lib-vendor/robust-predicates/umd/insphere.min.js +223 -0
- package/lib-vendor/robust-predicates/umd/orient2d.js +260 -0
- package/lib-vendor/robust-predicates/umd/orient2d.min.js +69 -0
- package/lib-vendor/robust-predicates/umd/orient3d.js +550 -0
- package/lib-vendor/robust-predicates/umd/orient3d.min.js +133 -0
- package/lib-vendor/robust-predicates/umd/predicates.js +2073 -0
- package/lib-vendor/robust-predicates/umd/predicates.min.js +468 -0
- package/package.json +63 -0
|
@@ -0,0 +1,688 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
(function (global, factory) {
|
|
4
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Delaunator = factory());
|
|
5
|
+
})(this, function () {
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const epsilon = 1.1102230246251565e-16;
|
|
9
|
+
const splitter = 134217729;
|
|
10
|
+
const resulterrbound = (3 + 8 * epsilon) * epsilon;
|
|
11
|
+
|
|
12
|
+
// fast_expansion_sum_zeroelim routine from oritinal code
|
|
13
|
+
function sum(elen, e, flen, f, h) {
|
|
14
|
+
let Q, Qnew, hh, bvirt;
|
|
15
|
+
let enow = e[0];
|
|
16
|
+
let fnow = f[0];
|
|
17
|
+
let eindex = 0;
|
|
18
|
+
let findex = 0;
|
|
19
|
+
if (fnow > enow === fnow > -enow) {
|
|
20
|
+
Q = enow;
|
|
21
|
+
enow = e[++eindex];
|
|
22
|
+
} else {
|
|
23
|
+
Q = fnow;
|
|
24
|
+
fnow = f[++findex];
|
|
25
|
+
}
|
|
26
|
+
let hindex = 0;
|
|
27
|
+
if (eindex < elen && findex < flen) {
|
|
28
|
+
if (fnow > enow === fnow > -enow) {
|
|
29
|
+
Qnew = enow + Q;
|
|
30
|
+
hh = Q - (Qnew - enow);
|
|
31
|
+
enow = e[++eindex];
|
|
32
|
+
} else {
|
|
33
|
+
Qnew = fnow + Q;
|
|
34
|
+
hh = Q - (Qnew - fnow);
|
|
35
|
+
fnow = f[++findex];
|
|
36
|
+
}
|
|
37
|
+
Q = Qnew;
|
|
38
|
+
if (hh !== 0) {
|
|
39
|
+
h[hindex++] = hh;
|
|
40
|
+
}
|
|
41
|
+
while (eindex < elen && findex < flen) {
|
|
42
|
+
if (fnow > enow === fnow > -enow) {
|
|
43
|
+
Qnew = Q + enow;
|
|
44
|
+
bvirt = Qnew - Q;
|
|
45
|
+
hh = Q - (Qnew - bvirt) + (enow - bvirt);
|
|
46
|
+
enow = e[++eindex];
|
|
47
|
+
} else {
|
|
48
|
+
Qnew = Q + fnow;
|
|
49
|
+
bvirt = Qnew - Q;
|
|
50
|
+
hh = Q - (Qnew - bvirt) + (fnow - bvirt);
|
|
51
|
+
fnow = f[++findex];
|
|
52
|
+
}
|
|
53
|
+
Q = Qnew;
|
|
54
|
+
if (hh !== 0) {
|
|
55
|
+
h[hindex++] = hh;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
while (eindex < elen) {
|
|
60
|
+
Qnew = Q + enow;
|
|
61
|
+
bvirt = Qnew - Q;
|
|
62
|
+
hh = Q - (Qnew - bvirt) + (enow - bvirt);
|
|
63
|
+
enow = e[++eindex];
|
|
64
|
+
Q = Qnew;
|
|
65
|
+
if (hh !== 0) {
|
|
66
|
+
h[hindex++] = hh;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
while (findex < flen) {
|
|
70
|
+
Qnew = Q + fnow;
|
|
71
|
+
bvirt = Qnew - Q;
|
|
72
|
+
hh = Q - (Qnew - bvirt) + (fnow - bvirt);
|
|
73
|
+
fnow = f[++findex];
|
|
74
|
+
Q = Qnew;
|
|
75
|
+
if (hh !== 0) {
|
|
76
|
+
h[hindex++] = hh;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (Q !== 0 || hindex === 0) {
|
|
80
|
+
h[hindex++] = Q;
|
|
81
|
+
}
|
|
82
|
+
return hindex;
|
|
83
|
+
}
|
|
84
|
+
function estimate(elen, e) {
|
|
85
|
+
let Q = e[0];
|
|
86
|
+
for (let i = 1; i < elen; i++) Q += e[i];
|
|
87
|
+
return Q;
|
|
88
|
+
}
|
|
89
|
+
function vec(n) {
|
|
90
|
+
return new Float64Array(n);
|
|
91
|
+
}
|
|
92
|
+
const ccwerrboundA = (3 + 16 * epsilon) * epsilon;
|
|
93
|
+
const ccwerrboundB = (2 + 12 * epsilon) * epsilon;
|
|
94
|
+
const ccwerrboundC = (9 + 64 * epsilon) * epsilon * epsilon;
|
|
95
|
+
const B = vec(4);
|
|
96
|
+
const C1 = vec(8);
|
|
97
|
+
const C2 = vec(12);
|
|
98
|
+
const D = vec(16);
|
|
99
|
+
const u = vec(4);
|
|
100
|
+
function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
|
|
101
|
+
let acxtail, acytail, bcxtail, bcytail;
|
|
102
|
+
let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
|
|
103
|
+
const acx = ax - cx;
|
|
104
|
+
const bcx = bx - cx;
|
|
105
|
+
const acy = ay - cy;
|
|
106
|
+
const bcy = by - cy;
|
|
107
|
+
s1 = acx * bcy;
|
|
108
|
+
c = splitter * acx;
|
|
109
|
+
ahi = c - (c - acx);
|
|
110
|
+
alo = acx - ahi;
|
|
111
|
+
c = splitter * bcy;
|
|
112
|
+
bhi = c - (c - bcy);
|
|
113
|
+
blo = bcy - bhi;
|
|
114
|
+
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
115
|
+
t1 = acy * bcx;
|
|
116
|
+
c = splitter * acy;
|
|
117
|
+
ahi = c - (c - acy);
|
|
118
|
+
alo = acy - ahi;
|
|
119
|
+
c = splitter * bcx;
|
|
120
|
+
bhi = c - (c - bcx);
|
|
121
|
+
blo = bcx - bhi;
|
|
122
|
+
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
123
|
+
_i = s0 - t0;
|
|
124
|
+
bvirt = s0 - _i;
|
|
125
|
+
B[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
|
126
|
+
_j = s1 + _i;
|
|
127
|
+
bvirt = _j - s1;
|
|
128
|
+
_0 = s1 - (_j - bvirt) + (_i - bvirt);
|
|
129
|
+
_i = _0 - t1;
|
|
130
|
+
bvirt = _0 - _i;
|
|
131
|
+
B[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
|
132
|
+
u3 = _j + _i;
|
|
133
|
+
bvirt = u3 - _j;
|
|
134
|
+
B[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
|
135
|
+
B[3] = u3;
|
|
136
|
+
let det = estimate(4, B);
|
|
137
|
+
let errbound = ccwerrboundB * detsum;
|
|
138
|
+
if (det >= errbound || -det >= errbound) {
|
|
139
|
+
return det;
|
|
140
|
+
}
|
|
141
|
+
bvirt = ax - acx;
|
|
142
|
+
acxtail = ax - (acx + bvirt) + (bvirt - cx);
|
|
143
|
+
bvirt = bx - bcx;
|
|
144
|
+
bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
|
|
145
|
+
bvirt = ay - acy;
|
|
146
|
+
acytail = ay - (acy + bvirt) + (bvirt - cy);
|
|
147
|
+
bvirt = by - bcy;
|
|
148
|
+
bcytail = by - (bcy + bvirt) + (bvirt - cy);
|
|
149
|
+
if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
|
|
150
|
+
return det;
|
|
151
|
+
}
|
|
152
|
+
errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
|
|
153
|
+
det += acx * bcytail + bcy * acxtail - (acy * bcxtail + bcx * acytail);
|
|
154
|
+
if (det >= errbound || -det >= errbound) return det;
|
|
155
|
+
s1 = acxtail * bcy;
|
|
156
|
+
c = splitter * acxtail;
|
|
157
|
+
ahi = c - (c - acxtail);
|
|
158
|
+
alo = acxtail - ahi;
|
|
159
|
+
c = splitter * bcy;
|
|
160
|
+
bhi = c - (c - bcy);
|
|
161
|
+
blo = bcy - bhi;
|
|
162
|
+
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
163
|
+
t1 = acytail * bcx;
|
|
164
|
+
c = splitter * acytail;
|
|
165
|
+
ahi = c - (c - acytail);
|
|
166
|
+
alo = acytail - ahi;
|
|
167
|
+
c = splitter * bcx;
|
|
168
|
+
bhi = c - (c - bcx);
|
|
169
|
+
blo = bcx - bhi;
|
|
170
|
+
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
171
|
+
_i = s0 - t0;
|
|
172
|
+
bvirt = s0 - _i;
|
|
173
|
+
u[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
|
174
|
+
_j = s1 + _i;
|
|
175
|
+
bvirt = _j - s1;
|
|
176
|
+
_0 = s1 - (_j - bvirt) + (_i - bvirt);
|
|
177
|
+
_i = _0 - t1;
|
|
178
|
+
bvirt = _0 - _i;
|
|
179
|
+
u[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
|
180
|
+
u3 = _j + _i;
|
|
181
|
+
bvirt = u3 - _j;
|
|
182
|
+
u[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
|
183
|
+
u[3] = u3;
|
|
184
|
+
const C1len = sum(4, B, 4, u, C1);
|
|
185
|
+
s1 = acx * bcytail;
|
|
186
|
+
c = splitter * acx;
|
|
187
|
+
ahi = c - (c - acx);
|
|
188
|
+
alo = acx - ahi;
|
|
189
|
+
c = splitter * bcytail;
|
|
190
|
+
bhi = c - (c - bcytail);
|
|
191
|
+
blo = bcytail - bhi;
|
|
192
|
+
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
193
|
+
t1 = acy * bcxtail;
|
|
194
|
+
c = splitter * acy;
|
|
195
|
+
ahi = c - (c - acy);
|
|
196
|
+
alo = acy - ahi;
|
|
197
|
+
c = splitter * bcxtail;
|
|
198
|
+
bhi = c - (c - bcxtail);
|
|
199
|
+
blo = bcxtail - bhi;
|
|
200
|
+
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
201
|
+
_i = s0 - t0;
|
|
202
|
+
bvirt = s0 - _i;
|
|
203
|
+
u[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
|
204
|
+
_j = s1 + _i;
|
|
205
|
+
bvirt = _j - s1;
|
|
206
|
+
_0 = s1 - (_j - bvirt) + (_i - bvirt);
|
|
207
|
+
_i = _0 - t1;
|
|
208
|
+
bvirt = _0 - _i;
|
|
209
|
+
u[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
|
210
|
+
u3 = _j + _i;
|
|
211
|
+
bvirt = u3 - _j;
|
|
212
|
+
u[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
|
213
|
+
u[3] = u3;
|
|
214
|
+
const C2len = sum(C1len, C1, 4, u, C2);
|
|
215
|
+
s1 = acxtail * bcytail;
|
|
216
|
+
c = splitter * acxtail;
|
|
217
|
+
ahi = c - (c - acxtail);
|
|
218
|
+
alo = acxtail - ahi;
|
|
219
|
+
c = splitter * bcytail;
|
|
220
|
+
bhi = c - (c - bcytail);
|
|
221
|
+
blo = bcytail - bhi;
|
|
222
|
+
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
223
|
+
t1 = acytail * bcxtail;
|
|
224
|
+
c = splitter * acytail;
|
|
225
|
+
ahi = c - (c - acytail);
|
|
226
|
+
alo = acytail - ahi;
|
|
227
|
+
c = splitter * bcxtail;
|
|
228
|
+
bhi = c - (c - bcxtail);
|
|
229
|
+
blo = bcxtail - bhi;
|
|
230
|
+
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
231
|
+
_i = s0 - t0;
|
|
232
|
+
bvirt = s0 - _i;
|
|
233
|
+
u[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
|
234
|
+
_j = s1 + _i;
|
|
235
|
+
bvirt = _j - s1;
|
|
236
|
+
_0 = s1 - (_j - bvirt) + (_i - bvirt);
|
|
237
|
+
_i = _0 - t1;
|
|
238
|
+
bvirt = _0 - _i;
|
|
239
|
+
u[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
|
240
|
+
u3 = _j + _i;
|
|
241
|
+
bvirt = u3 - _j;
|
|
242
|
+
u[2] = _j - (u3 - bvirt) + (_i - bvirt);
|
|
243
|
+
u[3] = u3;
|
|
244
|
+
const Dlen = sum(C2len, C2, 4, u, D);
|
|
245
|
+
return D[Dlen - 1];
|
|
246
|
+
}
|
|
247
|
+
function orient2d(ax, ay, bx, by, cx, cy) {
|
|
248
|
+
const detleft = (ay - cy) * (bx - cx);
|
|
249
|
+
const detright = (ax - cx) * (by - cy);
|
|
250
|
+
const det = detleft - detright;
|
|
251
|
+
const detsum = Math.abs(detleft + detright);
|
|
252
|
+
if (Math.abs(det) >= ccwerrboundA * detsum) return det;
|
|
253
|
+
return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
|
|
254
|
+
}
|
|
255
|
+
const EPSILON = Math.pow(2, -52);
|
|
256
|
+
const EDGE_STACK = new Uint32Array(512);
|
|
257
|
+
class Delaunator {
|
|
258
|
+
static from(points, getX = defaultGetX, getY = defaultGetY) {
|
|
259
|
+
const n = points.length;
|
|
260
|
+
const coords = new Float64Array(n * 2);
|
|
261
|
+
for (let i = 0; i < n; i++) {
|
|
262
|
+
const p = points[i];
|
|
263
|
+
coords[2 * i] = getX(p);
|
|
264
|
+
coords[2 * i + 1] = getY(p);
|
|
265
|
+
}
|
|
266
|
+
return new Delaunator(coords);
|
|
267
|
+
}
|
|
268
|
+
constructor(coords) {
|
|
269
|
+
const n = coords.length >> 1;
|
|
270
|
+
if (n > 0 && typeof coords[0] !== 'number') throw new Error('Expected coords to contain numbers.');
|
|
271
|
+
this.coords = coords;
|
|
272
|
+
|
|
273
|
+
// arrays that will store the triangulation graph
|
|
274
|
+
const maxTriangles = Math.max(2 * n - 5, 0);
|
|
275
|
+
this._triangles = new Uint32Array(maxTriangles * 3);
|
|
276
|
+
this._halfedges = new Int32Array(maxTriangles * 3);
|
|
277
|
+
|
|
278
|
+
// temporary arrays for tracking the edges of the advancing convex hull
|
|
279
|
+
this._hashSize = Math.ceil(Math.sqrt(n));
|
|
280
|
+
this._hullPrev = new Uint32Array(n); // edge to prev edge
|
|
281
|
+
this._hullNext = new Uint32Array(n); // edge to next edge
|
|
282
|
+
this._hullTri = new Uint32Array(n); // edge to adjacent triangle
|
|
283
|
+
this._hullHash = new Int32Array(this._hashSize); // angular edge hash
|
|
284
|
+
|
|
285
|
+
// temporary arrays for sorting points
|
|
286
|
+
this._ids = new Uint32Array(n);
|
|
287
|
+
this._dists = new Float64Array(n);
|
|
288
|
+
this.update();
|
|
289
|
+
}
|
|
290
|
+
update() {
|
|
291
|
+
const {
|
|
292
|
+
coords,
|
|
293
|
+
_hullPrev: hullPrev,
|
|
294
|
+
_hullNext: hullNext,
|
|
295
|
+
_hullTri: hullTri,
|
|
296
|
+
_hullHash: hullHash
|
|
297
|
+
} = this;
|
|
298
|
+
const n = coords.length >> 1;
|
|
299
|
+
|
|
300
|
+
// populate an array of point indices; calculate input data bbox
|
|
301
|
+
let minX = Infinity;
|
|
302
|
+
let minY = Infinity;
|
|
303
|
+
let maxX = -Infinity;
|
|
304
|
+
let maxY = -Infinity;
|
|
305
|
+
for (let i = 0; i < n; i++) {
|
|
306
|
+
const x = coords[2 * i];
|
|
307
|
+
const y = coords[2 * i + 1];
|
|
308
|
+
if (x < minX) minX = x;
|
|
309
|
+
if (y < minY) minY = y;
|
|
310
|
+
if (x > maxX) maxX = x;
|
|
311
|
+
if (y > maxY) maxY = y;
|
|
312
|
+
this._ids[i] = i;
|
|
313
|
+
}
|
|
314
|
+
const cx = (minX + maxX) / 2;
|
|
315
|
+
const cy = (minY + maxY) / 2;
|
|
316
|
+
let i0, i1, i2;
|
|
317
|
+
|
|
318
|
+
// pick a seed point close to the center
|
|
319
|
+
for (let i = 0, minDist = Infinity; i < n; i++) {
|
|
320
|
+
const d = dist(cx, cy, coords[2 * i], coords[2 * i + 1]);
|
|
321
|
+
if (d < minDist) {
|
|
322
|
+
i0 = i;
|
|
323
|
+
minDist = d;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const i0x = coords[2 * i0];
|
|
327
|
+
const i0y = coords[2 * i0 + 1];
|
|
328
|
+
|
|
329
|
+
// find the point closest to the seed
|
|
330
|
+
for (let i = 0, minDist = Infinity; i < n; i++) {
|
|
331
|
+
if (i === i0) continue;
|
|
332
|
+
const d = dist(i0x, i0y, coords[2 * i], coords[2 * i + 1]);
|
|
333
|
+
if (d < minDist && d > 0) {
|
|
334
|
+
i1 = i;
|
|
335
|
+
minDist = d;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
let i1x = coords[2 * i1];
|
|
339
|
+
let i1y = coords[2 * i1 + 1];
|
|
340
|
+
let minRadius = Infinity;
|
|
341
|
+
|
|
342
|
+
// find the third point which forms the smallest circumcircle with the first two
|
|
343
|
+
for (let i = 0; i < n; i++) {
|
|
344
|
+
if (i === i0 || i === i1) continue;
|
|
345
|
+
const r = circumradius(i0x, i0y, i1x, i1y, coords[2 * i], coords[2 * i + 1]);
|
|
346
|
+
if (r < minRadius) {
|
|
347
|
+
i2 = i;
|
|
348
|
+
minRadius = r;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
let i2x = coords[2 * i2];
|
|
352
|
+
let i2y = coords[2 * i2 + 1];
|
|
353
|
+
if (minRadius === Infinity) {
|
|
354
|
+
// order collinear points by dx (or dy if all x are identical)
|
|
355
|
+
// and return the list as a hull
|
|
356
|
+
for (let i = 0; i < n; i++) {
|
|
357
|
+
this._dists[i] = coords[2 * i] - coords[0] || coords[2 * i + 1] - coords[1];
|
|
358
|
+
}
|
|
359
|
+
quicksort(this._ids, this._dists, 0, n - 1);
|
|
360
|
+
const hull = new Uint32Array(n);
|
|
361
|
+
let j = 0;
|
|
362
|
+
for (let i = 0, d0 = -Infinity; i < n; i++) {
|
|
363
|
+
const id = this._ids[i];
|
|
364
|
+
const d = this._dists[id];
|
|
365
|
+
if (d > d0) {
|
|
366
|
+
hull[j++] = id;
|
|
367
|
+
d0 = d;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
this.hull = hull.subarray(0, j);
|
|
371
|
+
this.triangles = new Uint32Array(0);
|
|
372
|
+
this.halfedges = new Uint32Array(0);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// swap the order of the seed points for counter-clockwise orientation
|
|
377
|
+
if (orient2d(i0x, i0y, i1x, i1y, i2x, i2y) < 0) {
|
|
378
|
+
const i = i1;
|
|
379
|
+
const x = i1x;
|
|
380
|
+
const y = i1y;
|
|
381
|
+
i1 = i2;
|
|
382
|
+
i1x = i2x;
|
|
383
|
+
i1y = i2y;
|
|
384
|
+
i2 = i;
|
|
385
|
+
i2x = x;
|
|
386
|
+
i2y = y;
|
|
387
|
+
}
|
|
388
|
+
const center = circumcenter(i0x, i0y, i1x, i1y, i2x, i2y);
|
|
389
|
+
this._cx = center.x;
|
|
390
|
+
this._cy = center.y;
|
|
391
|
+
for (let i = 0; i < n; i++) {
|
|
392
|
+
this._dists[i] = dist(coords[2 * i], coords[2 * i + 1], center.x, center.y);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// sort the points by distance from the seed triangle circumcenter
|
|
396
|
+
quicksort(this._ids, this._dists, 0, n - 1);
|
|
397
|
+
|
|
398
|
+
// set up the seed triangle as the starting hull
|
|
399
|
+
this._hullStart = i0;
|
|
400
|
+
let hullSize = 3;
|
|
401
|
+
hullNext[i0] = hullPrev[i2] = i1;
|
|
402
|
+
hullNext[i1] = hullPrev[i0] = i2;
|
|
403
|
+
hullNext[i2] = hullPrev[i1] = i0;
|
|
404
|
+
hullTri[i0] = 0;
|
|
405
|
+
hullTri[i1] = 1;
|
|
406
|
+
hullTri[i2] = 2;
|
|
407
|
+
hullHash.fill(-1);
|
|
408
|
+
hullHash[this._hashKey(i0x, i0y)] = i0;
|
|
409
|
+
hullHash[this._hashKey(i1x, i1y)] = i1;
|
|
410
|
+
hullHash[this._hashKey(i2x, i2y)] = i2;
|
|
411
|
+
this.trianglesLen = 0;
|
|
412
|
+
this._addTriangle(i0, i1, i2, -1, -1, -1);
|
|
413
|
+
for (let k = 0, xp, yp; k < this._ids.length; k++) {
|
|
414
|
+
const i = this._ids[k];
|
|
415
|
+
const x = coords[2 * i];
|
|
416
|
+
const y = coords[2 * i + 1];
|
|
417
|
+
|
|
418
|
+
// skip near-duplicate points
|
|
419
|
+
if (k > 0 && Math.abs(x - xp) <= EPSILON && Math.abs(y - yp) <= EPSILON) continue;
|
|
420
|
+
xp = x;
|
|
421
|
+
yp = y;
|
|
422
|
+
|
|
423
|
+
// skip seed triangle points
|
|
424
|
+
if (i === i0 || i === i1 || i === i2) continue;
|
|
425
|
+
|
|
426
|
+
// find a visible edge on the convex hull using edge hash
|
|
427
|
+
let start = 0;
|
|
428
|
+
for (let j = 0, key = this._hashKey(x, y); j < this._hashSize; j++) {
|
|
429
|
+
start = hullHash[(key + j) % this._hashSize];
|
|
430
|
+
if (start !== -1 && start !== hullNext[start]) break;
|
|
431
|
+
}
|
|
432
|
+
start = hullPrev[start];
|
|
433
|
+
let e = start,
|
|
434
|
+
q;
|
|
435
|
+
while (q = hullNext[e], orient2d(x, y, coords[2 * e], coords[2 * e + 1], coords[2 * q], coords[2 * q + 1]) >= 0) {
|
|
436
|
+
e = q;
|
|
437
|
+
if (e === start) {
|
|
438
|
+
e = -1;
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (e === -1) continue; // likely a near-duplicate point; skip it
|
|
443
|
+
|
|
444
|
+
// add the first triangle from the point
|
|
445
|
+
let t = this._addTriangle(e, i, hullNext[e], -1, -1, hullTri[e]);
|
|
446
|
+
|
|
447
|
+
// recursively flip triangles from the point until they satisfy the Delaunay condition
|
|
448
|
+
hullTri[i] = this._legalize(t + 2);
|
|
449
|
+
hullTri[e] = t; // keep track of boundary triangles on the hull
|
|
450
|
+
hullSize++;
|
|
451
|
+
|
|
452
|
+
// walk forward through the hull, adding more triangles and flipping recursively
|
|
453
|
+
let n = hullNext[e];
|
|
454
|
+
while (q = hullNext[n], orient2d(x, y, coords[2 * n], coords[2 * n + 1], coords[2 * q], coords[2 * q + 1]) < 0) {
|
|
455
|
+
t = this._addTriangle(n, i, q, hullTri[i], -1, hullTri[n]);
|
|
456
|
+
hullTri[i] = this._legalize(t + 2);
|
|
457
|
+
hullNext[n] = n; // mark as removed
|
|
458
|
+
hullSize--;
|
|
459
|
+
n = q;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// walk backward from the other side, adding more triangles and flipping
|
|
463
|
+
if (e === start) {
|
|
464
|
+
while (q = hullPrev[e], orient2d(x, y, coords[2 * q], coords[2 * q + 1], coords[2 * e], coords[2 * e + 1]) < 0) {
|
|
465
|
+
t = this._addTriangle(q, i, e, -1, hullTri[e], hullTri[q]);
|
|
466
|
+
this._legalize(t + 2);
|
|
467
|
+
hullTri[q] = t;
|
|
468
|
+
hullNext[e] = e; // mark as removed
|
|
469
|
+
hullSize--;
|
|
470
|
+
e = q;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// update the hull indices
|
|
475
|
+
this._hullStart = hullPrev[i] = e;
|
|
476
|
+
hullNext[e] = hullPrev[n] = i;
|
|
477
|
+
hullNext[i] = n;
|
|
478
|
+
|
|
479
|
+
// save the two new edges in the hash table
|
|
480
|
+
hullHash[this._hashKey(x, y)] = i;
|
|
481
|
+
hullHash[this._hashKey(coords[2 * e], coords[2 * e + 1])] = e;
|
|
482
|
+
}
|
|
483
|
+
this.hull = new Uint32Array(hullSize);
|
|
484
|
+
for (let i = 0, e = this._hullStart; i < hullSize; i++) {
|
|
485
|
+
this.hull[i] = e;
|
|
486
|
+
e = hullNext[e];
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// trim typed triangle mesh arrays
|
|
490
|
+
this.triangles = this._triangles.subarray(0, this.trianglesLen);
|
|
491
|
+
this.halfedges = this._halfedges.subarray(0, this.trianglesLen);
|
|
492
|
+
}
|
|
493
|
+
_hashKey(x, y) {
|
|
494
|
+
return Math.floor(pseudoAngle(x - this._cx, y - this._cy) * this._hashSize) % this._hashSize;
|
|
495
|
+
}
|
|
496
|
+
_legalize(a) {
|
|
497
|
+
const {
|
|
498
|
+
_triangles: triangles,
|
|
499
|
+
_halfedges: halfedges,
|
|
500
|
+
coords
|
|
501
|
+
} = this;
|
|
502
|
+
let i = 0;
|
|
503
|
+
let ar = 0;
|
|
504
|
+
|
|
505
|
+
// recursion eliminated with a fixed-size stack
|
|
506
|
+
while (true) {
|
|
507
|
+
const b = halfedges[a];
|
|
508
|
+
|
|
509
|
+
/* if the pair of triangles doesn't satisfy the Delaunay condition
|
|
510
|
+
* (p1 is inside the circumcircle of [p0, pl, pr]), flip them,
|
|
511
|
+
* then do the same check/flip recursively for the new pair of triangles
|
|
512
|
+
*
|
|
513
|
+
* pl pl
|
|
514
|
+
* /||\ / \
|
|
515
|
+
* al/ || \bl al/ \a
|
|
516
|
+
* / || \ / \
|
|
517
|
+
* / a||b \ flip /___ar___\
|
|
518
|
+
* p0\ || /p1 => p0\---bl---/p1
|
|
519
|
+
* \ || / \ /
|
|
520
|
+
* ar\ || /br b\ /br
|
|
521
|
+
* \||/ \ /
|
|
522
|
+
* pr pr
|
|
523
|
+
*/
|
|
524
|
+
const a0 = a - a % 3;
|
|
525
|
+
ar = a0 + (a + 2) % 3;
|
|
526
|
+
if (b === -1) {
|
|
527
|
+
// convex hull edge
|
|
528
|
+
if (i === 0) break;
|
|
529
|
+
a = EDGE_STACK[--i];
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
const b0 = b - b % 3;
|
|
533
|
+
const al = a0 + (a + 1) % 3;
|
|
534
|
+
const bl = b0 + (b + 2) % 3;
|
|
535
|
+
const p0 = triangles[ar];
|
|
536
|
+
const pr = triangles[a];
|
|
537
|
+
const pl = triangles[al];
|
|
538
|
+
const p1 = triangles[bl];
|
|
539
|
+
const illegal = inCircle(coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr], coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1], coords[2 * p1 + 1]);
|
|
540
|
+
if (illegal) {
|
|
541
|
+
triangles[a] = p1;
|
|
542
|
+
triangles[b] = p0;
|
|
543
|
+
const hbl = halfedges[bl];
|
|
544
|
+
|
|
545
|
+
// edge swapped on the other side of the hull (rare); fix the halfedge reference
|
|
546
|
+
if (hbl === -1) {
|
|
547
|
+
let e = this._hullStart;
|
|
548
|
+
do {
|
|
549
|
+
if (this._hullTri[e] === bl) {
|
|
550
|
+
this._hullTri[e] = a;
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
e = this._hullPrev[e];
|
|
554
|
+
} while (e !== this._hullStart);
|
|
555
|
+
}
|
|
556
|
+
this._link(a, hbl);
|
|
557
|
+
this._link(b, halfedges[ar]);
|
|
558
|
+
this._link(ar, bl);
|
|
559
|
+
const br = b0 + (b + 1) % 3;
|
|
560
|
+
|
|
561
|
+
// don't worry about hitting the cap: it can only happen on extremely degenerate input
|
|
562
|
+
if (i < EDGE_STACK.length) {
|
|
563
|
+
EDGE_STACK[i++] = br;
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
if (i === 0) break;
|
|
567
|
+
a = EDGE_STACK[--i];
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return ar;
|
|
571
|
+
}
|
|
572
|
+
_link(a, b) {
|
|
573
|
+
this._halfedges[a] = b;
|
|
574
|
+
if (b !== -1) this._halfedges[b] = a;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// add a new triangle given vertex indices and adjacent half-edge ids
|
|
578
|
+
_addTriangle(i0, i1, i2, a, b, c) {
|
|
579
|
+
const t = this.trianglesLen;
|
|
580
|
+
this._triangles[t] = i0;
|
|
581
|
+
this._triangles[t + 1] = i1;
|
|
582
|
+
this._triangles[t + 2] = i2;
|
|
583
|
+
this._link(t, a);
|
|
584
|
+
this._link(t + 1, b);
|
|
585
|
+
this._link(t + 2, c);
|
|
586
|
+
this.trianglesLen += 3;
|
|
587
|
+
return t;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// monotonically increases with real angle, but doesn't need expensive trigonometry
|
|
592
|
+
function pseudoAngle(dx, dy) {
|
|
593
|
+
const p = dx / (Math.abs(dx) + Math.abs(dy));
|
|
594
|
+
return (dy > 0 ? 3 - p : 1 + p) / 4; // [0..1]
|
|
595
|
+
}
|
|
596
|
+
function dist(ax, ay, bx, by) {
|
|
597
|
+
const dx = ax - bx;
|
|
598
|
+
const dy = ay - by;
|
|
599
|
+
return dx * dx + dy * dy;
|
|
600
|
+
}
|
|
601
|
+
function inCircle(ax, ay, bx, by, cx, cy, px, py) {
|
|
602
|
+
const dx = ax - px;
|
|
603
|
+
const dy = ay - py;
|
|
604
|
+
const ex = bx - px;
|
|
605
|
+
const ey = by - py;
|
|
606
|
+
const fx = cx - px;
|
|
607
|
+
const fy = cy - py;
|
|
608
|
+
const ap = dx * dx + dy * dy;
|
|
609
|
+
const bp = ex * ex + ey * ey;
|
|
610
|
+
const cp = fx * fx + fy * fy;
|
|
611
|
+
return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;
|
|
612
|
+
}
|
|
613
|
+
function circumradius(ax, ay, bx, by, cx, cy) {
|
|
614
|
+
const dx = bx - ax;
|
|
615
|
+
const dy = by - ay;
|
|
616
|
+
const ex = cx - ax;
|
|
617
|
+
const ey = cy - ay;
|
|
618
|
+
const bl = dx * dx + dy * dy;
|
|
619
|
+
const cl = ex * ex + ey * ey;
|
|
620
|
+
const d = 0.5 / (dx * ey - dy * ex);
|
|
621
|
+
const x = (ey * bl - dy * cl) * d;
|
|
622
|
+
const y = (dx * cl - ex * bl) * d;
|
|
623
|
+
return x * x + y * y;
|
|
624
|
+
}
|
|
625
|
+
function circumcenter(ax, ay, bx, by, cx, cy) {
|
|
626
|
+
const dx = bx - ax;
|
|
627
|
+
const dy = by - ay;
|
|
628
|
+
const ex = cx - ax;
|
|
629
|
+
const ey = cy - ay;
|
|
630
|
+
const bl = dx * dx + dy * dy;
|
|
631
|
+
const cl = ex * ex + ey * ey;
|
|
632
|
+
const d = 0.5 / (dx * ey - dy * ex);
|
|
633
|
+
const x = ax + (ey * bl - dy * cl) * d;
|
|
634
|
+
const y = ay + (dx * cl - ex * bl) * d;
|
|
635
|
+
return {
|
|
636
|
+
x,
|
|
637
|
+
y
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
function quicksort(ids, dists, left, right) {
|
|
641
|
+
if (right - left <= 20) {
|
|
642
|
+
for (let i = left + 1; i <= right; i++) {
|
|
643
|
+
const temp = ids[i];
|
|
644
|
+
const tempDist = dists[temp];
|
|
645
|
+
let j = i - 1;
|
|
646
|
+
while (j >= left && dists[ids[j]] > tempDist) ids[j + 1] = ids[j--];
|
|
647
|
+
ids[j + 1] = temp;
|
|
648
|
+
}
|
|
649
|
+
} else {
|
|
650
|
+
const median = left + right >> 1;
|
|
651
|
+
let i = left + 1;
|
|
652
|
+
let j = right;
|
|
653
|
+
swap(ids, median, i);
|
|
654
|
+
if (dists[ids[left]] > dists[ids[right]]) swap(ids, left, right);
|
|
655
|
+
if (dists[ids[i]] > dists[ids[right]]) swap(ids, i, right);
|
|
656
|
+
if (dists[ids[left]] > dists[ids[i]]) swap(ids, left, i);
|
|
657
|
+
const temp = ids[i];
|
|
658
|
+
const tempDist = dists[temp];
|
|
659
|
+
while (true) {
|
|
660
|
+
do i++; while (dists[ids[i]] < tempDist);
|
|
661
|
+
do j--; while (dists[ids[j]] > tempDist);
|
|
662
|
+
if (j < i) break;
|
|
663
|
+
swap(ids, i, j);
|
|
664
|
+
}
|
|
665
|
+
ids[left + 1] = ids[j];
|
|
666
|
+
ids[j] = temp;
|
|
667
|
+
if (right - i + 1 >= j - left) {
|
|
668
|
+
quicksort(ids, dists, i, right);
|
|
669
|
+
quicksort(ids, dists, left, j - 1);
|
|
670
|
+
} else {
|
|
671
|
+
quicksort(ids, dists, left, j - 1);
|
|
672
|
+
quicksort(ids, dists, i, right);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function swap(arr, i, j) {
|
|
677
|
+
const tmp = arr[i];
|
|
678
|
+
arr[i] = arr[j];
|
|
679
|
+
arr[j] = tmp;
|
|
680
|
+
}
|
|
681
|
+
function defaultGetX(p) {
|
|
682
|
+
return p[0];
|
|
683
|
+
}
|
|
684
|
+
function defaultGetY(p) {
|
|
685
|
+
return p[1];
|
|
686
|
+
}
|
|
687
|
+
return Delaunator;
|
|
688
|
+
});
|