@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,390 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _path = _interopRequireDefault(require("./path.js"));
|
|
9
|
+
var _polygon = _interopRequireDefault(require("./polygon.js"));
|
|
10
|
+
class Voronoi {
|
|
11
|
+
constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) {
|
|
12
|
+
if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds");
|
|
13
|
+
this.delaunay = delaunay;
|
|
14
|
+
this._circumcenters = new Float64Array(delaunay.points.length * 2);
|
|
15
|
+
this.vectors = new Float64Array(delaunay.points.length * 2);
|
|
16
|
+
this.xmax = xmax, this.xmin = xmin;
|
|
17
|
+
this.ymax = ymax, this.ymin = ymin;
|
|
18
|
+
this._init();
|
|
19
|
+
}
|
|
20
|
+
update() {
|
|
21
|
+
this.delaunay.update();
|
|
22
|
+
this._init();
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
_init() {
|
|
26
|
+
const {
|
|
27
|
+
delaunay: {
|
|
28
|
+
points,
|
|
29
|
+
hull,
|
|
30
|
+
triangles
|
|
31
|
+
},
|
|
32
|
+
vectors
|
|
33
|
+
} = this;
|
|
34
|
+
let bx, by; // lazily computed barycenter of the hull
|
|
35
|
+
|
|
36
|
+
// Compute circumcenters.
|
|
37
|
+
const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2);
|
|
38
|
+
for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
|
|
39
|
+
const t1 = triangles[i] * 2;
|
|
40
|
+
const t2 = triangles[i + 1] * 2;
|
|
41
|
+
const t3 = triangles[i + 2] * 2;
|
|
42
|
+
const x1 = points[t1];
|
|
43
|
+
const y1 = points[t1 + 1];
|
|
44
|
+
const x2 = points[t2];
|
|
45
|
+
const y2 = points[t2 + 1];
|
|
46
|
+
const x3 = points[t3];
|
|
47
|
+
const y3 = points[t3 + 1];
|
|
48
|
+
const dx = x2 - x1;
|
|
49
|
+
const dy = y2 - y1;
|
|
50
|
+
const ex = x3 - x1;
|
|
51
|
+
const ey = y3 - y1;
|
|
52
|
+
const ab = (dx * ey - dy * ex) * 2;
|
|
53
|
+
if (Math.abs(ab) < 1e-9) {
|
|
54
|
+
// For a degenerate triangle, the circumcenter is at the infinity, in a
|
|
55
|
+
// direction orthogonal to the halfedge and away from the “center” of
|
|
56
|
+
// the diagram <bx, by>, defined as the hull’s barycenter.
|
|
57
|
+
if (bx === undefined) {
|
|
58
|
+
bx = by = 0;
|
|
59
|
+
for (const i of hull) bx += points[i * 2], by += points[i * 2 + 1];
|
|
60
|
+
bx /= hull.length, by /= hull.length;
|
|
61
|
+
}
|
|
62
|
+
const a = 1e9 * Math.sign((bx - x1) * ey - (by - y1) * ex);
|
|
63
|
+
x = (x1 + x3) / 2 - a * ey;
|
|
64
|
+
y = (y1 + y3) / 2 + a * ex;
|
|
65
|
+
} else {
|
|
66
|
+
const d = 1 / ab;
|
|
67
|
+
const bl = dx * dx + dy * dy;
|
|
68
|
+
const cl = ex * ex + ey * ey;
|
|
69
|
+
x = x1 + (ey * bl - dy * cl) * d;
|
|
70
|
+
y = y1 + (dx * cl - ex * bl) * d;
|
|
71
|
+
}
|
|
72
|
+
circumcenters[j] = x;
|
|
73
|
+
circumcenters[j + 1] = y;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Compute exterior cell rays.
|
|
77
|
+
let h = hull[hull.length - 1];
|
|
78
|
+
let p0,
|
|
79
|
+
p1 = h * 4;
|
|
80
|
+
let x0,
|
|
81
|
+
x1 = points[2 * h];
|
|
82
|
+
let y0,
|
|
83
|
+
y1 = points[2 * h + 1];
|
|
84
|
+
vectors.fill(0);
|
|
85
|
+
for (let i = 0; i < hull.length; ++i) {
|
|
86
|
+
h = hull[i];
|
|
87
|
+
p0 = p1, x0 = x1, y0 = y1;
|
|
88
|
+
p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1];
|
|
89
|
+
vectors[p0 + 2] = vectors[p1] = y0 - y1;
|
|
90
|
+
vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
render(context) {
|
|
94
|
+
const buffer = context == null ? context = new _path.default() : undefined;
|
|
95
|
+
const {
|
|
96
|
+
delaunay: {
|
|
97
|
+
halfedges,
|
|
98
|
+
inedges,
|
|
99
|
+
hull
|
|
100
|
+
},
|
|
101
|
+
circumcenters,
|
|
102
|
+
vectors
|
|
103
|
+
} = this;
|
|
104
|
+
if (hull.length <= 1) return null;
|
|
105
|
+
for (let i = 0, n = halfedges.length; i < n; ++i) {
|
|
106
|
+
const j = halfedges[i];
|
|
107
|
+
if (j < i) continue;
|
|
108
|
+
const ti = Math.floor(i / 3) * 2;
|
|
109
|
+
const tj = Math.floor(j / 3) * 2;
|
|
110
|
+
const xi = circumcenters[ti];
|
|
111
|
+
const yi = circumcenters[ti + 1];
|
|
112
|
+
const xj = circumcenters[tj];
|
|
113
|
+
const yj = circumcenters[tj + 1];
|
|
114
|
+
this._renderSegment(xi, yi, xj, yj, context);
|
|
115
|
+
}
|
|
116
|
+
let h0,
|
|
117
|
+
h1 = hull[hull.length - 1];
|
|
118
|
+
for (let i = 0; i < hull.length; ++i) {
|
|
119
|
+
h0 = h1, h1 = hull[i];
|
|
120
|
+
const t = Math.floor(inedges[h1] / 3) * 2;
|
|
121
|
+
const x = circumcenters[t];
|
|
122
|
+
const y = circumcenters[t + 1];
|
|
123
|
+
const v = h0 * 4;
|
|
124
|
+
const p = this._project(x, y, vectors[v + 2], vectors[v + 3]);
|
|
125
|
+
if (p) this._renderSegment(x, y, p[0], p[1], context);
|
|
126
|
+
}
|
|
127
|
+
return buffer && buffer.value();
|
|
128
|
+
}
|
|
129
|
+
renderBounds(context) {
|
|
130
|
+
const buffer = context == null ? context = new _path.default() : undefined;
|
|
131
|
+
context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin);
|
|
132
|
+
return buffer && buffer.value();
|
|
133
|
+
}
|
|
134
|
+
renderCell(i, context) {
|
|
135
|
+
const buffer = context == null ? context = new _path.default() : undefined;
|
|
136
|
+
const points = this._clip(i);
|
|
137
|
+
if (points === null || !points.length) return;
|
|
138
|
+
context.moveTo(points[0], points[1]);
|
|
139
|
+
let n = points.length;
|
|
140
|
+
while (points[0] === points[n - 2] && points[1] === points[n - 1] && n > 1) n -= 2;
|
|
141
|
+
for (let i = 2; i < n; i += 2) {
|
|
142
|
+
if (points[i] !== points[i - 2] || points[i + 1] !== points[i - 1]) context.lineTo(points[i], points[i + 1]);
|
|
143
|
+
}
|
|
144
|
+
context.closePath();
|
|
145
|
+
return buffer && buffer.value();
|
|
146
|
+
}
|
|
147
|
+
*cellPolygons() {
|
|
148
|
+
const {
|
|
149
|
+
delaunay: {
|
|
150
|
+
points
|
|
151
|
+
}
|
|
152
|
+
} = this;
|
|
153
|
+
for (let i = 0, n = points.length / 2; i < n; ++i) {
|
|
154
|
+
const cell = this.cellPolygon(i);
|
|
155
|
+
if (cell) cell.index = i, yield cell;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
cellPolygon(i) {
|
|
159
|
+
const polygon = new _polygon.default();
|
|
160
|
+
this.renderCell(i, polygon);
|
|
161
|
+
return polygon.value();
|
|
162
|
+
}
|
|
163
|
+
_renderSegment(x0, y0, x1, y1, context) {
|
|
164
|
+
let S;
|
|
165
|
+
const c0 = this._regioncode(x0, y0);
|
|
166
|
+
const c1 = this._regioncode(x1, y1);
|
|
167
|
+
if (c0 === 0 && c1 === 0) {
|
|
168
|
+
context.moveTo(x0, y0);
|
|
169
|
+
context.lineTo(x1, y1);
|
|
170
|
+
} else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) {
|
|
171
|
+
context.moveTo(S[0], S[1]);
|
|
172
|
+
context.lineTo(S[2], S[3]);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
contains(i, x, y) {
|
|
176
|
+
if ((x = +x, x !== x) || (y = +y, y !== y)) return false;
|
|
177
|
+
return this.delaunay._step(i, x, y) === i;
|
|
178
|
+
}
|
|
179
|
+
*neighbors(i) {
|
|
180
|
+
const ci = this._clip(i);
|
|
181
|
+
if (ci) for (const j of this.delaunay.neighbors(i)) {
|
|
182
|
+
const cj = this._clip(j);
|
|
183
|
+
// find the common edge
|
|
184
|
+
if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) {
|
|
185
|
+
for (let aj = 0, lj = cj.length; aj < lj; aj += 2) {
|
|
186
|
+
if (ci[ai] === cj[aj] && ci[ai + 1] === cj[aj + 1] && ci[(ai + 2) % li] === cj[(aj + lj - 2) % lj] && ci[(ai + 3) % li] === cj[(aj + lj - 1) % lj]) {
|
|
187
|
+
yield j;
|
|
188
|
+
break loop;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
_cell(i) {
|
|
195
|
+
const {
|
|
196
|
+
circumcenters,
|
|
197
|
+
delaunay: {
|
|
198
|
+
inedges,
|
|
199
|
+
halfedges,
|
|
200
|
+
triangles
|
|
201
|
+
}
|
|
202
|
+
} = this;
|
|
203
|
+
const e0 = inedges[i];
|
|
204
|
+
if (e0 === -1) return null; // coincident point
|
|
205
|
+
const points = [];
|
|
206
|
+
let e = e0;
|
|
207
|
+
do {
|
|
208
|
+
const t = Math.floor(e / 3);
|
|
209
|
+
points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]);
|
|
210
|
+
e = e % 3 === 2 ? e - 2 : e + 1;
|
|
211
|
+
if (triangles[e] !== i) break; // bad triangulation
|
|
212
|
+
e = halfedges[e];
|
|
213
|
+
} while (e !== e0 && e !== -1);
|
|
214
|
+
return points;
|
|
215
|
+
}
|
|
216
|
+
_clip(i) {
|
|
217
|
+
// degenerate case (1 valid point: return the box)
|
|
218
|
+
if (i === 0 && this.delaunay.hull.length === 1) {
|
|
219
|
+
return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
|
|
220
|
+
}
|
|
221
|
+
const points = this._cell(i);
|
|
222
|
+
if (points === null) return null;
|
|
223
|
+
const {
|
|
224
|
+
vectors: V
|
|
225
|
+
} = this;
|
|
226
|
+
const v = i * 4;
|
|
227
|
+
return this._simplify(V[v] || V[v + 1] ? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3]) : this._clipFinite(i, points));
|
|
228
|
+
}
|
|
229
|
+
_clipFinite(i, points) {
|
|
230
|
+
const n = points.length;
|
|
231
|
+
let P = null;
|
|
232
|
+
let x0,
|
|
233
|
+
y0,
|
|
234
|
+
x1 = points[n - 2],
|
|
235
|
+
y1 = points[n - 1];
|
|
236
|
+
let c0,
|
|
237
|
+
c1 = this._regioncode(x1, y1);
|
|
238
|
+
let e0,
|
|
239
|
+
e1 = 0;
|
|
240
|
+
for (let j = 0; j < n; j += 2) {
|
|
241
|
+
x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1];
|
|
242
|
+
c0 = c1, c1 = this._regioncode(x1, y1);
|
|
243
|
+
if (c0 === 0 && c1 === 0) {
|
|
244
|
+
e0 = e1, e1 = 0;
|
|
245
|
+
if (P) P.push(x1, y1);else P = [x1, y1];
|
|
246
|
+
} else {
|
|
247
|
+
let S, sx0, sy0, sx1, sy1;
|
|
248
|
+
if (c0 === 0) {
|
|
249
|
+
if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue;
|
|
250
|
+
[sx0, sy0, sx1, sy1] = S;
|
|
251
|
+
} else {
|
|
252
|
+
if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue;
|
|
253
|
+
[sx1, sy1, sx0, sy0] = S;
|
|
254
|
+
e0 = e1, e1 = this._edgecode(sx0, sy0);
|
|
255
|
+
if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
|
256
|
+
if (P) P.push(sx0, sy0);else P = [sx0, sy0];
|
|
257
|
+
}
|
|
258
|
+
e0 = e1, e1 = this._edgecode(sx1, sy1);
|
|
259
|
+
if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
|
260
|
+
if (P) P.push(sx1, sy1);else P = [sx1, sy1];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (P) {
|
|
264
|
+
e0 = e1, e1 = this._edgecode(P[0], P[1]);
|
|
265
|
+
if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
|
266
|
+
} else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
|
|
267
|
+
return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
|
|
268
|
+
}
|
|
269
|
+
return P;
|
|
270
|
+
}
|
|
271
|
+
_clipSegment(x0, y0, x1, y1, c0, c1) {
|
|
272
|
+
// for more robustness, always consider the segment in the same order
|
|
273
|
+
const flip = c0 < c1;
|
|
274
|
+
if (flip) [x0, y0, x1, y1, c0, c1] = [x1, y1, x0, y0, c1, c0];
|
|
275
|
+
while (true) {
|
|
276
|
+
if (c0 === 0 && c1 === 0) return flip ? [x1, y1, x0, y0] : [x0, y0, x1, y1];
|
|
277
|
+
if (c0 & c1) return null;
|
|
278
|
+
let x,
|
|
279
|
+
y,
|
|
280
|
+
c = c0 || c1;
|
|
281
|
+
if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax;else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin;else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax;else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin;
|
|
282
|
+
if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0);else x1 = x, y1 = y, c1 = this._regioncode(x1, y1);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
_clipInfinite(i, points, vx0, vy0, vxn, vyn) {
|
|
286
|
+
let P = Array.from(points),
|
|
287
|
+
p;
|
|
288
|
+
if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]);
|
|
289
|
+
if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]);
|
|
290
|
+
if (P = this._clipFinite(i, P)) {
|
|
291
|
+
for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) {
|
|
292
|
+
c0 = c1, c1 = this._edgecode(P[j], P[j + 1]);
|
|
293
|
+
if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length;
|
|
294
|
+
}
|
|
295
|
+
} else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
|
|
296
|
+
P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax];
|
|
297
|
+
}
|
|
298
|
+
return P;
|
|
299
|
+
}
|
|
300
|
+
_edge(i, e0, e1, P, j) {
|
|
301
|
+
while (e0 !== e1) {
|
|
302
|
+
let x, y;
|
|
303
|
+
switch (e0) {
|
|
304
|
+
case 0b0101:
|
|
305
|
+
e0 = 0b0100;
|
|
306
|
+
continue;
|
|
307
|
+
// top-left
|
|
308
|
+
case 0b0100:
|
|
309
|
+
e0 = 0b0110, x = this.xmax, y = this.ymin;
|
|
310
|
+
break;
|
|
311
|
+
// top
|
|
312
|
+
case 0b0110:
|
|
313
|
+
e0 = 0b0010;
|
|
314
|
+
continue;
|
|
315
|
+
// top-right
|
|
316
|
+
case 0b0010:
|
|
317
|
+
e0 = 0b1010, x = this.xmax, y = this.ymax;
|
|
318
|
+
break;
|
|
319
|
+
// right
|
|
320
|
+
case 0b1010:
|
|
321
|
+
e0 = 0b1000;
|
|
322
|
+
continue;
|
|
323
|
+
// bottom-right
|
|
324
|
+
case 0b1000:
|
|
325
|
+
e0 = 0b1001, x = this.xmin, y = this.ymax;
|
|
326
|
+
break;
|
|
327
|
+
// bottom
|
|
328
|
+
case 0b1001:
|
|
329
|
+
e0 = 0b0001;
|
|
330
|
+
continue;
|
|
331
|
+
// bottom-left
|
|
332
|
+
case 0b0001:
|
|
333
|
+
e0 = 0b0101, x = this.xmin, y = this.ymin;
|
|
334
|
+
break;
|
|
335
|
+
// left
|
|
336
|
+
}
|
|
337
|
+
// Note: this implicitly checks for out of bounds: if P[j] or P[j+1] are
|
|
338
|
+
// undefined, the conditional statement will be executed.
|
|
339
|
+
if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) {
|
|
340
|
+
P.splice(j, 0, x, y), j += 2;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return j;
|
|
344
|
+
}
|
|
345
|
+
_project(x0, y0, vx, vy) {
|
|
346
|
+
let t = Infinity,
|
|
347
|
+
c,
|
|
348
|
+
x,
|
|
349
|
+
y;
|
|
350
|
+
if (vy < 0) {
|
|
351
|
+
// top
|
|
352
|
+
if (y0 <= this.ymin) return null;
|
|
353
|
+
if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx;
|
|
354
|
+
} else if (vy > 0) {
|
|
355
|
+
// bottom
|
|
356
|
+
if (y0 >= this.ymax) return null;
|
|
357
|
+
if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx;
|
|
358
|
+
}
|
|
359
|
+
if (vx > 0) {
|
|
360
|
+
// right
|
|
361
|
+
if (x0 >= this.xmax) return null;
|
|
362
|
+
if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy;
|
|
363
|
+
} else if (vx < 0) {
|
|
364
|
+
// left
|
|
365
|
+
if (x0 <= this.xmin) return null;
|
|
366
|
+
if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy;
|
|
367
|
+
}
|
|
368
|
+
return [x, y];
|
|
369
|
+
}
|
|
370
|
+
_edgecode(x, y) {
|
|
371
|
+
return (x === this.xmin ? 0b0001 : x === this.xmax ? 0b0010 : 0b0000) | (y === this.ymin ? 0b0100 : y === this.ymax ? 0b1000 : 0b0000);
|
|
372
|
+
}
|
|
373
|
+
_regioncode(x, y) {
|
|
374
|
+
return (x < this.xmin ? 0b0001 : x > this.xmax ? 0b0010 : 0b0000) | (y < this.ymin ? 0b0100 : y > this.ymax ? 0b1000 : 0b0000);
|
|
375
|
+
}
|
|
376
|
+
_simplify(P) {
|
|
377
|
+
if (P && P.length > 4) {
|
|
378
|
+
for (let i = 0; i < P.length; i += 2) {
|
|
379
|
+
const j = (i + 2) % P.length,
|
|
380
|
+
k = (i + 4) % P.length;
|
|
381
|
+
if (P[i] === P[j] && P[j] === P[k] || P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1]) {
|
|
382
|
+
P.splice(j, 2), i -= 2;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (!P.length) P = null;
|
|
386
|
+
}
|
|
387
|
+
return P;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
exports.default = Voronoi;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2010-2021 Mike Bostock
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
4
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
5
|
+
and this permission notice appear in all copies.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
11
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
12
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
13
|
+
THIS SOFTWARE.
|