@d3plus/math 3.0.0-alpha.2 → 3.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/es/src/largestRect.js +2 -2
- package/package.json +1 -1
- package/umd/d3plus-math.full.js +3 -3
- package/umd/d3plus-math.full.js.map +1 -1
- package/umd/d3plus-math.full.min.js +3 -3
- package/umd/d3plus-math.js +3 -3
- package/umd/d3plus-math.js.map +1 -1
- package/umd/d3plus-math.min.js +3 -3
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ import modules from "@d3plus/math";
|
|
|
13
13
|
In vanilla JavaScript, a `d3plus` global is exported from the pre-bundled version:
|
|
14
14
|
|
|
15
15
|
```html
|
|
16
|
-
<script src="https://cdn.jsdelivr.net/npm/@d3plus/math@3.0.0-alpha.
|
|
16
|
+
<script src="https://cdn.jsdelivr.net/npm/@d3plus/math@3.0.0-alpha.4"></script>
|
|
17
17
|
<script>
|
|
18
18
|
console.log(d3plus);
|
|
19
19
|
</script>
|
|
@@ -42,7 +42,7 @@ Live examples can be found on [d3plus.org](https://d3plus.org/), which includes
|
|
|
42
42
|
* [largestRect](#largestRect) - Simplifies the points of a polygon using both the Ramer-Douglas-Peucker algorithm and basic distance-based simplification. Adapted to an ES6 module from the excellent [Simplify.js](http://mourner.github.io/simplify-js/).
|
|
43
43
|
|
|
44
44
|
#####
|
|
45
|
-
* [
|
|
45
|
+
* [largestRect](#largestRect) - The returned Object of the largestRect function.
|
|
46
46
|
|
|
47
47
|
---
|
|
48
48
|
|
|
@@ -190,8 +190,8 @@ This is a global function
|
|
|
190
190
|
|
|
191
191
|
---
|
|
192
192
|
|
|
193
|
-
<a name="
|
|
194
|
-
#### **
|
|
193
|
+
<a name="largestRect"></a>
|
|
194
|
+
#### **largestRect** [<>](https://github.com/d3plus/d3plus/blob/main/packages/math/src/largestRect.js#L16)
|
|
195
195
|
|
|
196
196
|
The returned Object of the largestRect function.
|
|
197
197
|
|
|
@@ -212,5 +212,3 @@ This is a global typedef
|
|
|
212
212
|
|
|
213
213
|
---
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
###### <sub>Documentation generated on Wed, 02 Apr 2025 20:59:31 GMT</sub>
|
package/es/src/largestRect.js
CHANGED
|
@@ -63,7 +63,7 @@ var aspectRatioStep = 0.5; // step size for the aspect ratio
|
|
|
63
63
|
var angleStep = 5; // step size for angles (in degrees); has linear impact on running time
|
|
64
64
|
var polyCache = {};
|
|
65
65
|
/**
|
|
66
|
-
@typedef {Object}
|
|
66
|
+
@typedef {Object} largestRect
|
|
67
67
|
@desc The returned Object of the largestRect function.
|
|
68
68
|
@property {Number} width The width of the rectangle
|
|
69
69
|
@property {Number} height The height of the rectangle
|
|
@@ -88,7 +88,7 @@ var polyCache = {};
|
|
|
88
88
|
@param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.
|
|
89
89
|
@param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.
|
|
90
90
|
@param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.
|
|
91
|
-
@return {
|
|
91
|
+
@return {largestRect}
|
|
92
92
|
*/ export default function(poly) {
|
|
93
93
|
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
94
94
|
if (poly.length < 3) {
|
package/package.json
CHANGED
package/umd/d3plus-math.full.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/math v3.0.0-alpha.
|
|
2
|
+
@d3plus/math v3.0.0-alpha.4
|
|
3
3
|
Mathematical functions to aid in calculating visualizations.
|
|
4
4
|
Copyright (c) 2025 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
@@ -679,7 +679,7 @@
|
|
|
679
679
|
const angleStep = 5; // step size for angles (in degrees); has linear impact on running time
|
|
680
680
|
const polyCache = {};
|
|
681
681
|
/**
|
|
682
|
-
@typedef {Object}
|
|
682
|
+
@typedef {Object} largestRect
|
|
683
683
|
@desc The returned Object of the largestRect function.
|
|
684
684
|
@property {Number} width The width of the rectangle
|
|
685
685
|
@property {Number} height The height of the rectangle
|
|
@@ -704,7 +704,7 @@
|
|
|
704
704
|
@param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.
|
|
705
705
|
@param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.
|
|
706
706
|
@param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.
|
|
707
|
-
@return {
|
|
707
|
+
@return {largestRect}
|
|
708
708
|
*/ function largestRect(poly, options = {}) {
|
|
709
709
|
if (poly.length < 3) {
|
|
710
710
|
if (options.verbose) console.error("polygon has to have at least 3 points", poly);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"d3plus-math.full.js","sources":["../src/ckmeans.js","../src/closest.js","../../../node_modules/d3-array/src/extent.js","../../../node_modules/d3-array/src/merge.js","../../../node_modules/d3-array/src/range.js","../../../node_modules/d3-polygon/src/area.js","../../../node_modules/d3-polygon/src/centroid.js","../../../node_modules/d3-polygon/src/contains.js","../src/lineIntersection.js","../src/segmentBoxContains.js","../src/segmentsIntersect.js","../src/polygonInside.js","../src/pointDistanceSquared.js","../src/polygonRayCast.js","../src/pointRotate.js","../src/polygonRotate.js","../src/simplify.js","../src/largestRect.js","../src/path2polygon.js","../src/pointDistance.js","../src/shapeEdgePoint.js"],"sourcesContent":["/**\n @desc Sort an array of numbers by their numeric value, ensuring that the array is not changed in place.\n\nThis is necessary because the default behavior of .sort in JavaScript is to sort arrays as string values\n\n[1, 10, 12, 102, 20].sort()\n// output\n[1, 10, 102, 12, 20]\n\n @param {Array<number>} array input array\n @return {Array<number>} sorted array\n @private\n @example\nnumericSort([3, 2, 1]) // => [1, 2, 3]\n*/\nfunction numericSort(array) {\n return array.slice().sort((a, b) => a - b);\n}\n\n/**\n For a sorted input, counting the number of unique values is possible in constant time and constant memory. This is a simple implementation of the algorithm.\n\n Values are compared with `===`, so objects and non-primitive objects are not handled in any special way.\n @private\n @param {Array} input an array of primitive values.\n @returns {number} count of unique values\n @example\nuniqueCountSorted([1, 2, 3]); // => 3\nuniqueCountSorted([1, 1, 1]); // => 1\n*/\nfunction uniqueCountSorted(input) {\n let lastSeenValue, uniqueValueCount = 0;\n for (let i = 0; i < input.length; i++) {\n if (i === 0 || input[i] !== lastSeenValue) {\n lastSeenValue = input[i];\n uniqueValueCount++;\n }\n }\n return uniqueValueCount;\n}\n\n/**\n Create a new column x row matrix.\n @private\n @param {number} columns\n @param {number} rows\n @return {Array<Array<number>>} matrix\n @example\nmakeMatrix(10, 10);\n*/\nfunction makeMatrix(columns, rows) {\n const matrix = [];\n for (let i = 0; i < columns; i++) {\n const column = [];\n for (let j = 0; j < rows; j++) column.push(0);\n matrix.push(column);\n }\n return matrix;\n}\n\n/**\n Generates incrementally computed values based on the sums and sums of squares for the data array\n @private\n @param {number} j\n @param {number} i\n @param {Array<number>} sums\n @param {Array<number>} sumsOfSquares\n @return {number}\n @example\nssq(0, 1, [-1, 0, 2], [1, 1, 5]);\n*/\nfunction ssq(j, i, sums, sumsOfSquares) {\n let sji; // s(j, i)\n\n if (j > 0) {\n const muji = (sums[i] - sums[j - 1]) / (i - j + 1); // mu(j, i)\n sji = sumsOfSquares[i] - sumsOfSquares[j - 1] - (i - j + 1) * muji * muji;\n }\n else sji = sumsOfSquares[i] - sums[i] * sums[i] / (i + 1);\n\n if (sji < 0) return 0;\n return sji;\n}\n\n/**\n Function that recursively divides and conquers computations for cluster j\n @private\n @param {number} iMin Minimum index in cluster to be computed\n @param {number} iMax Maximum index in cluster to be computed\n @param {number} cluster Index of the cluster currently being computed\n @param {Array<Array<number>>} matrix\n @param {Array<Array<number>>} backtrackMatrix\n @param {Array<number>} sums\n @param {Array<number>} sumsOfSquares\n*/\nfunction fillMatrixColumn(iMin, iMax, cluster, matrix, backtrackMatrix, sums, sumsOfSquares) {\n if (iMin > iMax) return;\n\n // Start at midpoint between iMin and iMax\n const i = Math.floor((iMin + iMax) / 2);\n\n matrix[cluster][i] = matrix[cluster - 1][i - 1];\n backtrackMatrix[cluster][i] = i;\n\n let jlow = cluster; // the lower end for j\n if (iMin > cluster) jlow = Math.max(jlow, backtrackMatrix[cluster][iMin - 1] || 0);\n jlow = Math.max(jlow, backtrackMatrix[cluster - 1][i] || 0);\n\n let jhigh = i - 1; // the upper end for j\n if (iMax < matrix.length - 1) jhigh = Math.min(jhigh, backtrackMatrix[cluster][iMax + 1] || 0);\n\n for (let j = jhigh; j >= jlow; --j) {\n const sji = ssq(j, i, sums, sumsOfSquares);\n\n if (sji + matrix[cluster - 1][jlow - 1] >= matrix[cluster][i]) break;\n\n // Examine the lower bound of the cluster border\n const sjlowi = ssq(jlow, i, sums, sumsOfSquares);\n\n const ssqjlow = sjlowi + matrix[cluster - 1][jlow - 1];\n\n if (ssqjlow < matrix[cluster][i]) {\n // Shrink the lower bound\n matrix[cluster][i] = ssqjlow;\n backtrackMatrix[cluster][i] = jlow;\n }\n jlow++;\n\n const ssqj = sji + matrix[cluster - 1][j - 1];\n if (ssqj < matrix[cluster][i]) {\n matrix[cluster][i] = ssqj;\n backtrackMatrix[cluster][i] = j;\n }\n }\n\n fillMatrixColumn(iMin, i - 1, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n fillMatrixColumn(i + 1, iMax, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n\n}\n\n/**\n Initializes the main matrices used in Ckmeans and kicks off the divide and conquer cluster computation strategy\n @private\n @param {Array<number>} data sorted array of values\n @param {Array<Array<number>>} matrix\n @param {Array<Array<number>>} backtrackMatrix\n*/\nfunction fillMatrices(data, matrix, backtrackMatrix) {\n const nValues = matrix[0] ? matrix[0].length : 0;\n\n // Shift values by the median to improve numeric stability\n const shift = data[Math.floor(nValues / 2)];\n\n // Cumulative sum and cumulative sum of squares for all values in data array\n const sums = [];\n const sumsOfSquares = [];\n\n // Initialize first column in matrix & backtrackMatrix\n for (let i = 0, shiftedValue = void 0; i < nValues; ++i) {\n shiftedValue = data[i] - shift;\n if (i === 0) {\n sums.push(shiftedValue);\n sumsOfSquares.push(shiftedValue * shiftedValue);\n }\n else {\n sums.push(sums[i - 1] + shiftedValue);\n sumsOfSquares.push(sumsOfSquares[i - 1] + shiftedValue * shiftedValue);\n }\n\n // Initialize for cluster = 0\n matrix[0][i] = ssq(0, i, sums, sumsOfSquares);\n backtrackMatrix[0][i] = 0;\n }\n\n // Initialize the rest of the columns\n for (let cluster = 1; cluster < matrix.length; ++cluster) {\n let iMin = nValues - 1;\n if (cluster < matrix.length - 1) iMin = cluster;\n fillMatrixColumn(iMin, nValues - 1, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n }\n}\n\n/**\n @module ckmeans\n @desc Ported to ES6 from the excellent [simple-statistics](https://github.com/simple-statistics/simple-statistics) packages.\n\nCkmeans clustering is an improvement on heuristic-based clustering approaches like Jenks. The algorithm was developed in [Haizhou Wang and Mingzhou Song](http://journal.r-project.org/archive/2011-2/RJournal_2011-2_Wang+Song.pdf) as a [dynamic programming](https://en.wikipedia.org/wiki/Dynamic_programming) approach to the problem of clustering numeric data into groups with the least within-group sum-of-squared-deviations.\n\nMinimizing the difference within groups - what Wang & Song refer to as `withinss`, or within sum-of-squares, means that groups are optimally homogenous within and the data is split into representative groups. This is very useful for visualization, where you may want to represent a continuous variable in discrete color or style groups. This function can provide groups that emphasize differences between data.\n\nBeing a dynamic approach, this algorithm is based on two matrices that store incrementally-computed values for squared deviations and backtracking indexes.\n\nThis implementation is based on Ckmeans 3.4.6, which introduced a new divide and conquer approach that improved runtime from O(kn^2) to O(kn log(n)).\n\nUnlike the [original implementation](https://cran.r-project.org/web/packages/Ckmeans.1d.dp/index.html), this implementation does not include any code to automatically determine the optimal number of clusters: this information needs to be explicitly provided.\n\n### References\n_Ckmeans.1d.dp: Optimal k-means Clustering in One Dimension by Dynamic\nProgramming_ Haizhou Wang and Mingzhou Song ISSN 2073-4859 from The R Journal Vol. 3/2, December 2011\n @param {Array<number>} data input data, as an array of number values\n @param {number} nClusters number of desired classes. This cannot be greater than the number of values in the data array.\n @returns {Array<Array<number>>} clustered input\n @private\n @example\nckmeans([-1, 2, -1, 2, 4, 5, 6, -1, 2, -1], 3);\n// The input, clustered into groups of similar numbers.\n//= [[-1, -1, -1, -1], [2, 2, 2], [4, 5, 6]]);\n*/\nexport default function(data, nClusters) {\n\n if (nClusters > data.length) {\n throw new Error(\"Cannot generate more classes than there are data values\");\n }\n\n const sorted = numericSort(data);\n\n // we'll use this as the maximum number of clusters\n const uniqueCount = uniqueCountSorted(sorted);\n\n // if all of the input values are identical, there's one cluster with all of the input in it.\n if (uniqueCount === 1) {\n return [sorted];\n }\n\n const backtrackMatrix = makeMatrix(nClusters, sorted.length),\n matrix = makeMatrix(nClusters, sorted.length);\n\n // This is a dynamic programming way to solve the problem of minimizing within-cluster sum of squares. It's similar to linear regression in this way, and this calculation incrementally computes the sum of squares that are later read.\n fillMatrices(sorted, matrix, backtrackMatrix);\n\n // The real work of Ckmeans clustering happens in the matrix generation: the generated matrices encode all possible clustering combinations, and once they're generated we can solve for the best clustering groups very quickly.\n let clusterRight = backtrackMatrix[0] ? backtrackMatrix[0].length - 1 : 0;\n const clusters = [];\n\n // Backtrack the clusters from the dynamic programming matrix. This starts at the bottom-right corner of the matrix (if the top-left is 0, 0), and moves the cluster target with the loop.\n for (let cluster = backtrackMatrix.length - 1; cluster >= 0; cluster--) {\n\n const clusterLeft = backtrackMatrix[cluster][clusterRight];\n\n // fill the cluster from the sorted input by taking a slice of the array. the backtrack matrix makes this easy - it stores the indexes where the cluster should start and end.\n clusters[cluster] = sorted.slice(clusterLeft, clusterRight + 1);\n\n if (cluster > 0) clusterRight = clusterLeft - 1;\n\n }\n\n return clusters;\n\n}\n","/**\n @function closest\n @desc Finds the closest numeric value in an array.\n @param {Number} n The number value to use when searching the array.\n @param {Array} arr The array of values to test against.\n*/\nexport default function(n, arr = []) {\n if (!arr || !(arr instanceof Array) || !arr.length) return undefined;\n return arr.reduce((prev, curr) => Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev);\n}\n","export default function extent(values, valueof) {\n let min;\n let max;\n if (valueof === undefined) {\n for (const value of values) {\n if (value != null) {\n if (min === undefined) {\n if (value >= value) min = max = value;\n } else {\n if (min > value) min = value;\n if (max < value) max = value;\n }\n }\n }\n } else {\n let index = -1;\n for (let value of values) {\n if ((value = valueof(value, ++index, values)) != null) {\n if (min === undefined) {\n if (value >= value) min = max = value;\n } else {\n if (min > value) min = value;\n if (max < value) max = value;\n }\n }\n }\n }\n return [min, max];\n}\n","function* flatten(arrays) {\n for (const array of arrays) {\n yield* array;\n }\n}\n\nexport default function merge(arrays) {\n return Array.from(flatten(arrays));\n}\n","export default function range(start, stop, step) {\n start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;\n\n var i = -1,\n n = Math.max(0, Math.ceil((stop - start) / step)) | 0,\n range = new Array(n);\n\n while (++i < n) {\n range[i] = start + i * step;\n }\n\n return range;\n}\n","export default function(polygon) {\n var i = -1,\n n = polygon.length,\n a,\n b = polygon[n - 1],\n area = 0;\n\n while (++i < n) {\n a = b;\n b = polygon[i];\n area += a[1] * b[0] - a[0] * b[1];\n }\n\n return area / 2;\n}\n","export default function(polygon) {\n var i = -1,\n n = polygon.length,\n x = 0,\n y = 0,\n a,\n b = polygon[n - 1],\n c,\n k = 0;\n\n while (++i < n) {\n a = b;\n b = polygon[i];\n k += c = a[0] * b[1] - b[0] * a[1];\n x += (a[0] + b[0]) * c;\n y += (a[1] + b[1]) * c;\n }\n\n return k *= 3, [x / k, y / k];\n}\n","export default function(polygon, point) {\n var n = polygon.length,\n p = polygon[n - 1],\n x = point[0], y = point[1],\n x0 = p[0], y0 = p[1],\n x1, y1,\n inside = false;\n\n for (var i = 0; i < n; ++i) {\n p = polygon[i], x1 = p[0], y1 = p[1];\n if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;\n x0 = x1, y0 = y1;\n }\n\n return inside;\n}\n","/**\n @function lineIntersection\n @desc Finds the intersection point (if there is one) of the lines p1q1 and p2q2.\n @param {Array} p1 The first point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q1 The second point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The first point of the second line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q2 The second point of the second line segment, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p1, q1, p2, q2) {\n\n // allow for some margins due to numerical errors\n const eps = 1e-9;\n\n // find the intersection point between the two infinite lines\n const dx1 = p1[0] - q1[0],\n dx2 = p2[0] - q2[0],\n dy1 = p1[1] - q1[1],\n dy2 = p2[1] - q2[1];\n\n const denom = dx1 * dy2 - dy1 * dx2;\n\n if (Math.abs(denom) < eps) return null;\n\n const cross1 = p1[0] * q1[1] - p1[1] * q1[0],\n cross2 = p2[0] * q2[1] - p2[1] * q2[0];\n\n const px = (cross1 * dx2 - cross2 * dx1) / denom,\n py = (cross1 * dy2 - cross2 * dy1) / denom;\n\n return [px, py];\n\n}\n","/**\n @function segmentBoxContains\n @desc Checks whether a point is inside the bounding box of a line segment.\n @param {Array} s1 The first point of the line segment to be used for the bounding box, which should always be an `[x, y]` formatted Array.\n @param {Array} s2 The second point of the line segment to be used for the bounding box, which should always be an `[x, y]` formatted Array.\n @param {Array} p The point to be checked, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(s1, s2, p) {\n\n const eps = 1e-9, [px, py] = p;\n\n return !(px < Math.min(s1[0], s2[0]) - eps || px > Math.max(s1[0], s2[0]) + eps ||\n py < Math.min(s1[1], s2[1]) - eps || py > Math.max(s1[1], s2[1]) + eps);\n\n}\n","import lineIntersection from \"./lineIntersection.js\";\nimport segmentBoxContains from \"./segmentBoxContains.js\";\n\n/**\n @function segmentsIntersect\n @desc Checks whether the line segments p1q1 && p2q2 intersect.\n @param {Array} p1 The first point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q1 The second point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The first point of the second line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q2 The second point of the second line segment, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p1, q1, p2, q2) {\n\n const p = lineIntersection(p1, q1, p2, q2);\n if (!p) return false;\n return segmentBoxContains(p1, q1, p) && segmentBoxContains(p2, q2, p);\n\n}\n","import {polygonContains} from \"d3-polygon\";\n\nimport segmentsIntersect from \"./segmentsIntersect.js\";\n\n/**\n @function polygonInside\n @desc Checks if one polygon is inside another polygon.\n @param {Array} polyA An Array of `[x, y]` points to be used as the inner polygon, checking if it is inside polyA.\n @param {Array} polyB An Array of `[x, y]` points to be used as the containing polygon.\n @returns {Boolean}\n*/\nexport default function(polyA, polyB) {\n\n let iA = -1;\n const nA = polyA.length;\n const nB = polyB.length;\n let bA = polyA[nA - 1];\n\n while (++iA < nA) {\n\n const aA = bA;\n bA = polyA[iA];\n\n let iB = -1;\n let bB = polyB[nB - 1];\n while (++iB < nB) {\n const aB = bB;\n bB = polyB[iB];\n if (segmentsIntersect(aA, bA, aB, bB)) return false;\n }\n }\n\n return polygonContains(polyB, polyA[0]);\n\n}\n","/**\n @function pointDistanceSquared\n @desc Returns the squared euclidean distance between two points.\n @param {Array} p1 The first point, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The second point, which should always be an `[x, y]` formatted Array.\n @returns {Number}\n*/\nexport default (p1, p2) => {\n\n const dx = p2[0] - p1[0],\n dy = p2[1] - p1[1];\n\n return dx * dx + dy * dy;\n\n};\n","import lineIntersection from \"./lineIntersection.js\";\nimport segmentBoxContains from \"./segmentBoxContains.js\";\nimport pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @function polygonRayCast\n @desc Gives the two closest intersection points between a ray cast from a point inside a polygon. The two points should lie on opposite sides of the origin.\n @param {Array} poly The polygon to test against, which should be an `[x, y]` formatted Array.\n @param {Array} origin The origin point of the ray to be cast, which should be an `[x, y]` formatted Array.\n @param {Number} [alpha = 0] The angle in radians of the ray.\n @returns {Array} An array containing two values, the closest point on the left and the closest point on the right. If either point cannot be found, that value will be `null`.\n*/\nexport default function(poly, origin, alpha = 0) {\n\n const eps = 1e-9;\n origin = [origin[0] + eps * Math.cos(alpha), origin[1] + eps * Math.sin(alpha)];\n const [x0, y0] = origin;\n const shiftedOrigin = [x0 + Math.cos(alpha), y0 + Math.sin(alpha)];\n\n let idx = 0;\n if (Math.abs(shiftedOrigin[0] - x0) < eps) idx = 1;\n let i = -1;\n const n = poly.length;\n let b = poly[n - 1];\n let minSqDistLeft = Number.MAX_VALUE;\n let minSqDistRight = Number.MAX_VALUE;\n let closestPointLeft = null;\n let closestPointRight = null;\n while (++i < n) {\n const a = b;\n b = poly[i];\n const p = lineIntersection(origin, shiftedOrigin, a, b);\n if (p && segmentBoxContains(a, b, p)) {\n const sqDist = pointDistanceSquared(origin, p);\n if (p[idx] < origin[idx]) {\n if (sqDist < minSqDistLeft) {\n minSqDistLeft = sqDist;\n closestPointLeft = p;\n }\n }\n else if (p[idx] > origin[idx]) {\n if (sqDist < minSqDistRight) {\n minSqDistRight = sqDist;\n closestPointRight = p;\n }\n }\n }\n }\n\n return [closestPointLeft, closestPointRight];\n\n}\n","/**\n @function pointRotate\n @desc Rotates a point around a given origin.\n @param {Array} p The point to be rotated, which should always be an `[x, y]` formatted Array.\n @param {Number} alpha The angle in radians to rotate.\n @param {Array} [origin = [0, 0]] The origin point of the rotation, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p, alpha, origin = [0, 0]) {\n\n const cosAlpha = Math.cos(alpha),\n sinAlpha = Math.sin(alpha),\n xshifted = p[0] - origin[0],\n yshifted = p[1] - origin[1];\n\n return [\n cosAlpha * xshifted - sinAlpha * yshifted + origin[0],\n sinAlpha * xshifted + cosAlpha * yshifted + origin[1]\n ];\n\n}\n","import pointRotate from \"./pointRotate.js\";\n\n/**\n @function polygonRotate\n @desc Rotates a point around a given origin.\n @param {Array} poly The polygon to be rotated, which should be an Array of `[x, y]` values.\n @param {Number} alpha The angle in radians to rotate.\n @param {Array} [origin = [0, 0]] The origin point of the rotation, which should be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default (poly, alpha, origin = [0, 0]) => poly.map(p => pointRotate(p, alpha, origin));\n","import pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @desc square distance from a point to a segment\n @param {Array} point\n @param {Array} segmentAnchor1\n @param {Array} segmentAnchor2\n @private\n*/\nfunction getSqSegDist(p, p1, p2) {\n\n let x = p1[0],\n y = p1[1];\n\n let dx = p2[0] - x,\n dy = p2[1] - y;\n\n if (dx !== 0 || dy !== 0) {\n\n const t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);\n\n if (t > 1) {\n x = p2[0];\n y = p2[1];\n\n }\n else if (t > 0) {\n x += dx * t;\n y += dy * t;\n }\n\n }\n\n dx = p[0] - x;\n dy = p[1] - y;\n\n return dx * dx + dy * dy;\n\n}\n\n/**\n @desc basic distance-based simplification\n @param {Array} polygon\n @param {Number} sqTolerance\n @private\n*/\nfunction simplifyRadialDist(poly, sqTolerance) {\n\n let point,\n prevPoint = poly[0];\n\n const newPoints = [prevPoint];\n\n for (let i = 1, len = poly.length; i < len; i++) {\n point = poly[i];\n\n if (pointDistanceSquared(point, prevPoint) > sqTolerance) {\n newPoints.push(point);\n prevPoint = point;\n }\n }\n\n if (prevPoint !== point) newPoints.push(point);\n\n return newPoints;\n}\n\n/**\n @param {Array} polygon\n @param {Number} first\n @param {Number} last\n @param {Number} sqTolerance\n @param {Array} simplified\n @private\n*/\nfunction simplifyDPStep(poly, first, last, sqTolerance, simplified) {\n\n let index, maxSqDist = sqTolerance;\n\n for (let i = first + 1; i < last; i++) {\n const sqDist = getSqSegDist(poly[i], poly[first], poly[last]);\n\n if (sqDist > maxSqDist) {\n index = i;\n maxSqDist = sqDist;\n }\n }\n\n if (maxSqDist > sqTolerance) {\n if (index - first > 1) simplifyDPStep(poly, first, index, sqTolerance, simplified);\n simplified.push(poly[index]);\n if (last - index > 1) simplifyDPStep(poly, index, last, sqTolerance, simplified);\n }\n}\n\n/**\n @desc simplification using Ramer-Douglas-Peucker algorithm\n @param {Array} polygon\n @param {Number} sqTolerance\n @private\n*/\nfunction simplifyDouglasPeucker(poly, sqTolerance) {\n const last = poly.length - 1;\n\n const simplified = [poly[0]];\n simplifyDPStep(poly, 0, last, sqTolerance, simplified);\n simplified.push(poly[last]);\n\n return simplified;\n}\n\n/**\n @function largestRect\n @desc Simplifies the points of a polygon using both the Ramer-Douglas-Peucker algorithm and basic distance-based simplification. Adapted to an ES6 module from the excellent [Simplify.js](http://mourner.github.io/simplify-js/).\n @author Vladimir Agafonkin\n @param {Array} poly An Array of points that represent a polygon.\n @param {Number} [tolerance = 1] Affects the amount of simplification (in the same metric as the point coordinates).\n @param {Boolean} [highestQuality = false] Excludes distance-based preprocessing step which leads to highest quality simplification but runs ~10-20 times slower.\n\n*/\nexport default (poly, tolerance = 1, highestQuality = false) => {\n\n if (poly.length <= 2) return poly;\n\n const sqTolerance = tolerance * tolerance;\n\n poly = highestQuality ? poly : simplifyRadialDist(poly, sqTolerance);\n poly = simplifyDouglasPeucker(poly, sqTolerance);\n\n return poly;\n\n};\n","import {extent, merge, range} from \"d3-array\";\nimport {polygonArea, polygonCentroid, polygonContains} from \"d3-polygon\";\n\nimport polygonInside from \"./polygonInside.js\";\nimport polygonRayCast from \"./polygonRayCast.js\";\nimport polygonRotate from \"./polygonRotate.js\";\nimport simplify from \"./simplify.js\";\nimport pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n// Algorithm constants\nconst aspectRatioStep = 0.5; // step size for the aspect ratio\nconst angleStep = 5; // step size for angles (in degrees); has linear impact on running time\n\nconst polyCache = {};\n\n/**\n @typedef {Object} LargestRect\n @desc The returned Object of the largestRect function.\n @property {Number} width The width of the rectangle\n @property {Number} height The height of the rectangle\n @property {Number} cx The x coordinate of the rectangle's center\n @property {Number} cy The y coordinate of the rectangle's center\n @property {Number} angle The rotation angle of the rectangle in degrees. The anchor of rotation is the center point.\n @property {Number} area The area of the largest rectangle.\n @property {Array} points An array of x/y coordinates for each point in the rectangle, useful for rendering paths.\n*/\n\n/**\n @function largestRect\n @author Daniel Smilkov [dsmilkov@gmail.com]\n @desc An angle of zero means that the longer side of the polygon (the width) will be aligned with the x axis. An angle of 90 and/or -90 means that the longer side of the polygon (the width) will be aligned with the y axis. The value can be a number between -90 and 90 specifying the angle of rotation of the polygon, a string which is parsed to a number, or an array of numbers specifying the possible rotations of the polygon.\n @param {Array} poly An Array of points that represent a polygon.\n @param {Object} [options] An Object that allows for overriding various parameters of the algorithm.\n @param {Number|String|Array} [options.angle = d3.range(-90, 95, 5)] The allowed rotations of the final rectangle.\n @param {Number|String|Array} [options.aspectRatio] The ratio between the width and height of the rectangle. The value can be a number, a string which is parsed to a number, or an array of numbers specifying the possible aspect ratios of the final rectangle.\n @param {Number} [options.maxAspectRatio = 15] The maximum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided.\n @param {Number} [options.minAspectRatio = 1] The minimum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided.\n @param {Number} [options.nTries = 20] The number of randomly drawn points inside the polygon which the algorithm explores as possible center points of the maximal rectangle.\n @param {Number} [options.minHeight = 0] The minimum height of the rectangle.\n @param {Number} [options.minWidth = 0] The minimum width of the rectangle.\n @param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.\n @param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.\n @param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.\n @return {LargestRect}\n*/\nexport default function(poly, options = {}) {\n\n if (poly.length < 3) {\n if (options.verbose) console.error(\"polygon has to have at least 3 points\", poly);\n return null;\n }\n\n // For visualization debugging purposes\n const events = [];\n\n // User's input normalization\n options = Object.assign({\n angle: range(-90, 90 + angleStep, angleStep),\n cache: true,\n maxAspectRatio: 15,\n minAspectRatio: 1,\n minHeight: 0,\n minWidth: 0,\n nTries: 20,\n tolerance: 0.02,\n verbose: false\n }, options);\n\n const angles = options.angle instanceof Array ? options.angle\n : typeof options.angle === \"number\" ? [options.angle]\n : typeof options.angle === \"string\" && !isNaN(options.angle) ? [Number(options.angle)]\n : [];\n\n const aspectRatios = options.aspectRatio instanceof Array ? options.aspectRatio\n : typeof options.aspectRatio === \"number\" ? [options.aspectRatio]\n : typeof options.aspectRatio === \"string\" && !isNaN(options.aspectRatio) ? [Number(options.aspectRatio)]\n : [];\n\n const origins = options.origin && options.origin instanceof Array\n ? options.origin[0] instanceof Array ? options.origin\n : [options.origin] : [];\n\n let cacheString;\n if (options.cache) {\n cacheString = merge(poly).join(\",\");\n cacheString += `-${options.minAspectRatio}`;\n cacheString += `-${options.maxAspectRatio}`;\n cacheString += `-${options.minHeight}`;\n cacheString += `-${options.minWidth}`;\n cacheString += `-${angles.join(\",\")}`;\n cacheString += `-${origins.join(\",\")}`;\n if (polyCache[cacheString]) return polyCache[cacheString];\n }\n\n const area = Math.abs(polygonArea(poly)); // take absolute value of the signed area\n if (area === 0) {\n if (options.verbose) console.error(\"polygon has 0 area\", poly);\n return null;\n }\n // get the width of the bounding box of the original polygon to determine tolerance\n let [minx, maxx] = extent(poly, d => d[0]);\n let [miny, maxy] = extent(poly, d => d[1]);\n\n // simplify polygon\n const tolerance = Math.min(maxx - minx, maxy - miny) * options.tolerance;\n\n if (tolerance > 0) poly = simplify(poly, tolerance);\n if (options.events) events.push({type: \"simplify\", poly});\n\n // get the width of the bounding box of the simplified polygon\n [minx, maxx] = extent(poly, d => d[0]);\n [miny, maxy] = extent(poly, d => d[1]);\n const [boxWidth, boxHeight] = [maxx - minx, maxy - miny];\n\n // discretize the binary search for optimal width to a resolution of this times the polygon width\n const widthStep = Math.min(boxWidth, boxHeight) / 50;\n\n // populate possible center points with random points inside the polygon\n if (!origins.length) {\n // get the centroid of the polygon\n const centroid = polygonCentroid(poly);\n if (!isFinite(centroid[0])) {\n if (options.verbose) console.error(\"cannot find centroid\", poly);\n return null;\n }\n if (polygonContains(poly, centroid)) origins.push(centroid);\n\n let nTries = options.nTries;\n // get few more points inside the polygon\n while (nTries) {\n const rndX = Math.random() * boxWidth + minx;\n const rndY = Math.random() * boxHeight + miny;\n const rndPoint = [rndX, rndY];\n if (polygonContains(poly, rndPoint)) {\n origins.push(rndPoint);\n }\n nTries--;\n }\n }\n if (options.events) events.push({type: \"origins\", points: origins});\n let maxArea = 0;\n let maxRect = null;\n\n for (let ai = 0; ai < angles.length; ai++) {\n const angle = angles[ai];\n const angleRad = -angle * Math.PI / 180;\n if (options.events) events.push({type: \"angle\", angle});\n for (let i = 0; i < origins.length; i++) {\n const origOrigin = origins[i];\n // generate improved origins\n const [p1W, p2W] = polygonRayCast(poly, origOrigin, angleRad);\n const [p1H, p2H] = polygonRayCast(poly, origOrigin, angleRad + Math.PI / 2);\n const modifOrigins = [];\n if (p1W && p2W) modifOrigins.push([(p1W[0] + p2W[0]) / 2, (p1W[1] + p2W[1]) / 2]); // average along with width axis\n if (p1H && p2H) modifOrigins.push([(p1H[0] + p2H[0]) / 2, (p1H[1] + p2H[1]) / 2]); // average along with height axis\n\n if (options.events) events.push({type: \"modifOrigin\", idx: i, p1W, p2W, p1H, p2H, modifOrigins});\n\n for (let i = 0; i < modifOrigins.length; i++) {\n\n const origin = modifOrigins[i];\n\n if (options.events) events.push({type: \"origin\", cx: origin[0], cy: origin[1]});\n\n const [p1W, p2W] = polygonRayCast(poly, origin, angleRad);\n if (p1W === null || p2W === null) continue;\n const minSqDistW = Math.min(pointDistanceSquared(origin, p1W), pointDistanceSquared(origin, p2W));\n const maxWidth = 2 * Math.sqrt(minSqDistW);\n\n const [p1H, p2H] = polygonRayCast(poly, origin, angleRad + Math.PI / 2);\n if (p1H === null || p2H === null) continue;\n const minSqDistH = Math.min(pointDistanceSquared(origin, p1H), pointDistanceSquared(origin, p2H));\n const maxHeight = 2 * Math.sqrt(minSqDistH);\n\n if (maxWidth * maxHeight < maxArea) continue;\n\n let aRatios = aspectRatios;\n if (!aRatios.length) {\n const minAspectRatio = Math.max(options.minAspectRatio, options.minWidth / maxHeight, maxArea / (maxHeight * maxHeight));\n const maxAspectRatio = Math.min(options.maxAspectRatio, maxWidth / options.minHeight, maxWidth * maxWidth / maxArea);\n aRatios = range(minAspectRatio, maxAspectRatio + aspectRatioStep, aspectRatioStep);\n }\n\n for (let a = 0; a < aRatios.length; a++) {\n\n const aRatio = aRatios[a];\n\n // do a binary search to find the max width that works\n let left = Math.max(options.minWidth, Math.sqrt(maxArea * aRatio));\n let right = Math.min(maxWidth, maxHeight * aRatio);\n if (right * maxHeight < maxArea) continue;\n\n if (options.events && right - left >= widthStep) events.push({type: \"aRatio\", aRatio});\n\n while (right - left >= widthStep) {\n const width = (left + right) / 2;\n const height = width / aRatio;\n const [cx, cy] = origin;\n let rectPoly = [\n [cx - width / 2, cy - height / 2],\n [cx + width / 2, cy - height / 2],\n [cx + width / 2, cy + height / 2],\n [cx - width / 2, cy + height / 2]\n ];\n rectPoly = polygonRotate(rectPoly, angleRad, origin);\n const insidePoly = polygonInside(rectPoly, poly);\n if (insidePoly) {\n // we know that the area is already greater than the maxArea found so far\n maxArea = width * height;\n rectPoly.push(rectPoly[0]);\n maxRect = {area: maxArea, cx, cy, width, height, angle: -angle, points: rectPoly};\n left = width; // increase the width in the binary search\n }\n else {\n right = width; // decrease the width in the binary search\n }\n if (options.events) events.push({type: \"rectangle\", areaFraction: width * height / area, cx, cy, width, height, angle, insidePoly});\n\n }\n\n }\n\n }\n\n }\n\n }\n\n if (options.cache) {\n polyCache[cacheString] = maxRect;\n }\n\n return options.events ? Object.assign(maxRect || {}, {events}) : maxRect;\n\n}\n","/**\n @function path2polygon\n @desc Transforms a path string into an Array of points.\n @param {String} path An SVG string path, commonly the \"d\" property of a <path> element.\n @param {Number} [segmentLength = 50] The length of line segments when converting curves line segments. Higher values lower computation time, but will result in curves that are more rigid.\n @returns {Array}\n*/\nexport default (path, segmentLength = 50) => {\n\n if (typeof document === \"undefined\") return [];\n\n const svgPath = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n svgPath.setAttribute(\"d\", path);\n\n const len = svgPath.getTotalLength();\n const NUM_POINTS = len / segmentLength < 10 ? len / 10 : len / segmentLength;\n\n const points = [];\n for (let i = 0; i < NUM_POINTS; i++) {\n const pt = svgPath.getPointAtLength(i * len / (NUM_POINTS-1));\n points.push([pt.x, pt.y]);\n }\n \n return points;\n\n};\n","import pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @function pointDistance\n @desc Calculates the pixel distance between two points.\n @param {Array} p1 The first point, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The second point, which should always be an `[x, y]` formatted Array.\n @returns {Number}\n*/\nexport default (p1, p2) => Math.sqrt(pointDistanceSquared(p1, p2));\n","const pi = Math.PI;\n\n/**\n @function shapeEdgePoint\n @desc Calculates the x/y position of a point at the edge of a shape, from the center of the shape, given a specified pixel distance and radian angle.\n @param {Number} angle The angle, in radians, of the offset point.\n @param {Number} distance The pixel distance away from the origin.\n @returns {String} [shape = \"circle\"] The type of shape, which can be either \"circle\" or \"square\".\n*/\nexport default (angle, distance, shape = \"circle\") => {\n\n if (angle < 0) angle = pi * 2 + angle;\n\n if (shape === \"square\") {\n\n const diagonal = 45 * (pi / 180);\n let x = 0, y = 0;\n\n if (angle < pi / 2) {\n const tan = Math.tan(angle);\n x += angle < diagonal ? distance : distance / tan;\n y += angle < diagonal ? tan * distance : distance;\n }\n else if (angle <= pi) {\n const tan = Math.tan(pi - angle);\n x -= angle < pi - diagonal ? distance / tan : distance;\n y += angle < pi - diagonal ? distance : tan * distance;\n }\n else if (angle < diagonal + pi) {\n x -= distance;\n y -= Math.tan(angle - pi) * distance;\n }\n else if (angle < 3 * pi / 2) {\n x -= distance / Math.tan(angle - pi);\n y -= distance;\n }\n else if (angle < 2 * pi - diagonal) {\n x += distance / Math.tan(2 * pi - angle);\n y -= distance;\n }\n else {\n x += distance;\n y -= Math.tan(2 * pi - angle) * distance;\n }\n\n return [x, y];\n\n }\n else if (shape === \"circle\") {\n return [distance * Math.cos(angle), distance * Math.sin(angle)];\n }\n else return null;\n\n};\n"],"names":["numericSort","array","slice","sort","a","b","uniqueCountSorted","input","lastSeenValue","uniqueValueCount","i","length","makeMatrix","columns","rows","matrix","column","j","push","ssq","sums","sumsOfSquares","sji","muji","fillMatrixColumn","iMin","iMax","cluster","backtrackMatrix","Math","floor","jlow","max","jhigh","min","sjlowi","ssqjlow","ssqj","fillMatrices","data","nValues","shift","shiftedValue","nClusters","Error","sorted","uniqueCount","clusterRight","clusters","clusterLeft","n","arr","Array","undefined","reduce","prev","curr","abs","extent","values","valueof","value","index","flatten","arrays","merge","from","range","start","stop","step","arguments","ceil","polygon","area","x","y","c","k","point","p","x0","y0","x1","y1","inside","p1","q1","p2","q2","eps","dx1","dx2","dy1","dy2","denom","cross1","cross2","px","py","s1","s2","lineIntersection","segmentBoxContains","polyA","polyB","iA","nA","nB","bA","aA","iB","bB","aB","segmentsIntersect","polygonContains","dx","dy","poly","origin","alpha","cos","sin","shiftedOrigin","idx","minSqDistLeft","Number","MAX_VALUE","minSqDistRight","closestPointLeft","closestPointRight","sqDist","pointDistanceSquared","cosAlpha","sinAlpha","xshifted","yshifted","map","pointRotate","getSqSegDist","t","simplifyRadialDist","sqTolerance","prevPoint","newPoints","len","simplifyDPStep","first","last","simplified","maxSqDist","simplifyDouglasPeucker","tolerance","highestQuality","aspectRatioStep","angleStep","polyCache","options","verbose","console","error","events","Object","assign","angle","cache","maxAspectRatio","minAspectRatio","minHeight","minWidth","nTries","angles","isNaN","aspectRatios","aspectRatio","origins","cacheString","join","polygonArea","minx","maxx","d","miny","maxy","simplify","type","boxWidth","boxHeight","widthStep","centroid","polygonCentroid","isFinite","rndX","random","rndY","rndPoint","points","maxArea","maxRect","ai","angleRad","PI","origOrigin","p1W","p2W","polygonRayCast","p1H","p2H","modifOrigins","cx","cy","minSqDistW","maxWidth","sqrt","minSqDistH","maxHeight","aRatios","aRatio","left","right","width","height","rectPoly","polygonRotate","insidePoly","polygonInside","areaFraction","path","segmentLength","document","svgPath","createElementNS","setAttribute","getTotalLength","NUM_POINTS","pt","getPointAtLength","pi","distance","shape","diagonal","tan"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;EAcA,GACA,SAASA,YAAYC,KAAK,EAAA;MACxB,OAAOA,KAAAA,CAAMC,KAAK,EAAGC,CAAAA,IAAI,CAAC,CAACC,CAAAA,EAAGC,IAAMD,CAAIC,GAAAA,CAAAA,CAAAA;EAC1C;EAEA;;;;;;;;;;EAUA,GACA,SAASC,kBAAkBC,KAAK,EAAA;EAC9B,IAAA,IAAIC,eAAeC,gBAAmB,GAAA,CAAA;EACtC,IAAA,IAAK,IAAIC,CAAI,GAAA,CAAA,EAAGA,IAAIH,KAAMI,CAAAA,MAAM,EAAED,CAAK,EAAA,CAAA;EACrC,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AIJ,EAAKzE,GAAAA,KAAAA,CAAAA;cAClCxF,CAAKkK,IAAAA,QAAAA;WAEF,MAAA;cACHnK,CAAKmK,IAAAA,QAAAA;EACLlK,YAAAA,CAAAA,IAAK/C,IAAKoN,CAAAA,GAAG,CAAC,CAAA,GAAIJ,KAAKzE,KAAS0E,CAAAA,GAAAA,QAAAA;EAClC;UAEA,OAAO;EAACnK,YAAAA,CAAAA;EAAGC,YAAAA;EAAE,SAAA;OAGV,MAAA,IAAImK,UAAU,QAAU,EAAA;UAC3B,OAAO;cAACD,QAAWjN,GAAAA,IAAAA,CAAK4F,GAAG,CAAC2C,KAAAA,CAAAA;cAAQ0E,QAAWjN,GAAAA,IAAAA,CAAK6F,GAAG,CAAC0C,KAAAA;EAAO,SAAA;EACjE,KAAA,MACK,OAAO,IAAA;EAEd,CAAA;;;;;;;;;;;;;;;;;;;;;;","x_google_ignoreList":[2,3,4,5,6,7]}
|
|
1
|
+
{"version":3,"file":"d3plus-math.full.js","sources":["../src/ckmeans.js","../src/closest.js","../../../node_modules/d3-array/src/extent.js","../../../node_modules/d3-array/src/merge.js","../../../node_modules/d3-array/src/range.js","../../../node_modules/d3-polygon/src/area.js","../../../node_modules/d3-polygon/src/centroid.js","../../../node_modules/d3-polygon/src/contains.js","../src/lineIntersection.js","../src/segmentBoxContains.js","../src/segmentsIntersect.js","../src/polygonInside.js","../src/pointDistanceSquared.js","../src/polygonRayCast.js","../src/pointRotate.js","../src/polygonRotate.js","../src/simplify.js","../src/largestRect.js","../src/path2polygon.js","../src/pointDistance.js","../src/shapeEdgePoint.js"],"sourcesContent":["/**\n @desc Sort an array of numbers by their numeric value, ensuring that the array is not changed in place.\n\nThis is necessary because the default behavior of .sort in JavaScript is to sort arrays as string values\n\n[1, 10, 12, 102, 20].sort()\n// output\n[1, 10, 102, 12, 20]\n\n @param {Array<number>} array input array\n @return {Array<number>} sorted array\n @private\n @example\nnumericSort([3, 2, 1]) // => [1, 2, 3]\n*/\nfunction numericSort(array) {\n return array.slice().sort((a, b) => a - b);\n}\n\n/**\n For a sorted input, counting the number of unique values is possible in constant time and constant memory. This is a simple implementation of the algorithm.\n\n Values are compared with `===`, so objects and non-primitive objects are not handled in any special way.\n @private\n @param {Array} input an array of primitive values.\n @returns {number} count of unique values\n @example\nuniqueCountSorted([1, 2, 3]); // => 3\nuniqueCountSorted([1, 1, 1]); // => 1\n*/\nfunction uniqueCountSorted(input) {\n let lastSeenValue, uniqueValueCount = 0;\n for (let i = 0; i < input.length; i++) {\n if (i === 0 || input[i] !== lastSeenValue) {\n lastSeenValue = input[i];\n uniqueValueCount++;\n }\n }\n return uniqueValueCount;\n}\n\n/**\n Create a new column x row matrix.\n @private\n @param {number} columns\n @param {number} rows\n @return {Array<Array<number>>} matrix\n @example\nmakeMatrix(10, 10);\n*/\nfunction makeMatrix(columns, rows) {\n const matrix = [];\n for (let i = 0; i < columns; i++) {\n const column = [];\n for (let j = 0; j < rows; j++) column.push(0);\n matrix.push(column);\n }\n return matrix;\n}\n\n/**\n Generates incrementally computed values based on the sums and sums of squares for the data array\n @private\n @param {number} j\n @param {number} i\n @param {Array<number>} sums\n @param {Array<number>} sumsOfSquares\n @return {number}\n @example\nssq(0, 1, [-1, 0, 2], [1, 1, 5]);\n*/\nfunction ssq(j, i, sums, sumsOfSquares) {\n let sji; // s(j, i)\n\n if (j > 0) {\n const muji = (sums[i] - sums[j - 1]) / (i - j + 1); // mu(j, i)\n sji = sumsOfSquares[i] - sumsOfSquares[j - 1] - (i - j + 1) * muji * muji;\n }\n else sji = sumsOfSquares[i] - sums[i] * sums[i] / (i + 1);\n\n if (sji < 0) return 0;\n return sji;\n}\n\n/**\n Function that recursively divides and conquers computations for cluster j\n @private\n @param {number} iMin Minimum index in cluster to be computed\n @param {number} iMax Maximum index in cluster to be computed\n @param {number} cluster Index of the cluster currently being computed\n @param {Array<Array<number>>} matrix\n @param {Array<Array<number>>} backtrackMatrix\n @param {Array<number>} sums\n @param {Array<number>} sumsOfSquares\n*/\nfunction fillMatrixColumn(iMin, iMax, cluster, matrix, backtrackMatrix, sums, sumsOfSquares) {\n if (iMin > iMax) return;\n\n // Start at midpoint between iMin and iMax\n const i = Math.floor((iMin + iMax) / 2);\n\n matrix[cluster][i] = matrix[cluster - 1][i - 1];\n backtrackMatrix[cluster][i] = i;\n\n let jlow = cluster; // the lower end for j\n if (iMin > cluster) jlow = Math.max(jlow, backtrackMatrix[cluster][iMin - 1] || 0);\n jlow = Math.max(jlow, backtrackMatrix[cluster - 1][i] || 0);\n\n let jhigh = i - 1; // the upper end for j\n if (iMax < matrix.length - 1) jhigh = Math.min(jhigh, backtrackMatrix[cluster][iMax + 1] || 0);\n\n for (let j = jhigh; j >= jlow; --j) {\n const sji = ssq(j, i, sums, sumsOfSquares);\n\n if (sji + matrix[cluster - 1][jlow - 1] >= matrix[cluster][i]) break;\n\n // Examine the lower bound of the cluster border\n const sjlowi = ssq(jlow, i, sums, sumsOfSquares);\n\n const ssqjlow = sjlowi + matrix[cluster - 1][jlow - 1];\n\n if (ssqjlow < matrix[cluster][i]) {\n // Shrink the lower bound\n matrix[cluster][i] = ssqjlow;\n backtrackMatrix[cluster][i] = jlow;\n }\n jlow++;\n\n const ssqj = sji + matrix[cluster - 1][j - 1];\n if (ssqj < matrix[cluster][i]) {\n matrix[cluster][i] = ssqj;\n backtrackMatrix[cluster][i] = j;\n }\n }\n\n fillMatrixColumn(iMin, i - 1, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n fillMatrixColumn(i + 1, iMax, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n\n}\n\n/**\n Initializes the main matrices used in Ckmeans and kicks off the divide and conquer cluster computation strategy\n @private\n @param {Array<number>} data sorted array of values\n @param {Array<Array<number>>} matrix\n @param {Array<Array<number>>} backtrackMatrix\n*/\nfunction fillMatrices(data, matrix, backtrackMatrix) {\n const nValues = matrix[0] ? matrix[0].length : 0;\n\n // Shift values by the median to improve numeric stability\n const shift = data[Math.floor(nValues / 2)];\n\n // Cumulative sum and cumulative sum of squares for all values in data array\n const sums = [];\n const sumsOfSquares = [];\n\n // Initialize first column in matrix & backtrackMatrix\n for (let i = 0, shiftedValue = void 0; i < nValues; ++i) {\n shiftedValue = data[i] - shift;\n if (i === 0) {\n sums.push(shiftedValue);\n sumsOfSquares.push(shiftedValue * shiftedValue);\n }\n else {\n sums.push(sums[i - 1] + shiftedValue);\n sumsOfSquares.push(sumsOfSquares[i - 1] + shiftedValue * shiftedValue);\n }\n\n // Initialize for cluster = 0\n matrix[0][i] = ssq(0, i, sums, sumsOfSquares);\n backtrackMatrix[0][i] = 0;\n }\n\n // Initialize the rest of the columns\n for (let cluster = 1; cluster < matrix.length; ++cluster) {\n let iMin = nValues - 1;\n if (cluster < matrix.length - 1) iMin = cluster;\n fillMatrixColumn(iMin, nValues - 1, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n }\n}\n\n/**\n @module ckmeans\n @desc Ported to ES6 from the excellent [simple-statistics](https://github.com/simple-statistics/simple-statistics) packages.\n\nCkmeans clustering is an improvement on heuristic-based clustering approaches like Jenks. The algorithm was developed in [Haizhou Wang and Mingzhou Song](http://journal.r-project.org/archive/2011-2/RJournal_2011-2_Wang+Song.pdf) as a [dynamic programming](https://en.wikipedia.org/wiki/Dynamic_programming) approach to the problem of clustering numeric data into groups with the least within-group sum-of-squared-deviations.\n\nMinimizing the difference within groups - what Wang & Song refer to as `withinss`, or within sum-of-squares, means that groups are optimally homogenous within and the data is split into representative groups. This is very useful for visualization, where you may want to represent a continuous variable in discrete color or style groups. This function can provide groups that emphasize differences between data.\n\nBeing a dynamic approach, this algorithm is based on two matrices that store incrementally-computed values for squared deviations and backtracking indexes.\n\nThis implementation is based on Ckmeans 3.4.6, which introduced a new divide and conquer approach that improved runtime from O(kn^2) to O(kn log(n)).\n\nUnlike the [original implementation](https://cran.r-project.org/web/packages/Ckmeans.1d.dp/index.html), this implementation does not include any code to automatically determine the optimal number of clusters: this information needs to be explicitly provided.\n\n### References\n_Ckmeans.1d.dp: Optimal k-means Clustering in One Dimension by Dynamic\nProgramming_ Haizhou Wang and Mingzhou Song ISSN 2073-4859 from The R Journal Vol. 3/2, December 2011\n @param {Array<number>} data input data, as an array of number values\n @param {number} nClusters number of desired classes. This cannot be greater than the number of values in the data array.\n @returns {Array<Array<number>>} clustered input\n @private\n @example\nckmeans([-1, 2, -1, 2, 4, 5, 6, -1, 2, -1], 3);\n// The input, clustered into groups of similar numbers.\n//= [[-1, -1, -1, -1], [2, 2, 2], [4, 5, 6]]);\n*/\nexport default function(data, nClusters) {\n\n if (nClusters > data.length) {\n throw new Error(\"Cannot generate more classes than there are data values\");\n }\n\n const sorted = numericSort(data);\n\n // we'll use this as the maximum number of clusters\n const uniqueCount = uniqueCountSorted(sorted);\n\n // if all of the input values are identical, there's one cluster with all of the input in it.\n if (uniqueCount === 1) {\n return [sorted];\n }\n\n const backtrackMatrix = makeMatrix(nClusters, sorted.length),\n matrix = makeMatrix(nClusters, sorted.length);\n\n // This is a dynamic programming way to solve the problem of minimizing within-cluster sum of squares. It's similar to linear regression in this way, and this calculation incrementally computes the sum of squares that are later read.\n fillMatrices(sorted, matrix, backtrackMatrix);\n\n // The real work of Ckmeans clustering happens in the matrix generation: the generated matrices encode all possible clustering combinations, and once they're generated we can solve for the best clustering groups very quickly.\n let clusterRight = backtrackMatrix[0] ? backtrackMatrix[0].length - 1 : 0;\n const clusters = [];\n\n // Backtrack the clusters from the dynamic programming matrix. This starts at the bottom-right corner of the matrix (if the top-left is 0, 0), and moves the cluster target with the loop.\n for (let cluster = backtrackMatrix.length - 1; cluster >= 0; cluster--) {\n\n const clusterLeft = backtrackMatrix[cluster][clusterRight];\n\n // fill the cluster from the sorted input by taking a slice of the array. the backtrack matrix makes this easy - it stores the indexes where the cluster should start and end.\n clusters[cluster] = sorted.slice(clusterLeft, clusterRight + 1);\n\n if (cluster > 0) clusterRight = clusterLeft - 1;\n\n }\n\n return clusters;\n\n}\n","/**\n @function closest\n @desc Finds the closest numeric value in an array.\n @param {Number} n The number value to use when searching the array.\n @param {Array} arr The array of values to test against.\n*/\nexport default function(n, arr = []) {\n if (!arr || !(arr instanceof Array) || !arr.length) return undefined;\n return arr.reduce((prev, curr) => Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev);\n}\n","export default function extent(values, valueof) {\n let min;\n let max;\n if (valueof === undefined) {\n for (const value of values) {\n if (value != null) {\n if (min === undefined) {\n if (value >= value) min = max = value;\n } else {\n if (min > value) min = value;\n if (max < value) max = value;\n }\n }\n }\n } else {\n let index = -1;\n for (let value of values) {\n if ((value = valueof(value, ++index, values)) != null) {\n if (min === undefined) {\n if (value >= value) min = max = value;\n } else {\n if (min > value) min = value;\n if (max < value) max = value;\n }\n }\n }\n }\n return [min, max];\n}\n","function* flatten(arrays) {\n for (const array of arrays) {\n yield* array;\n }\n}\n\nexport default function merge(arrays) {\n return Array.from(flatten(arrays));\n}\n","export default function range(start, stop, step) {\n start = +start, stop = +stop, step = (n = arguments.length) < 2 ? (stop = start, start = 0, 1) : n < 3 ? 1 : +step;\n\n var i = -1,\n n = Math.max(0, Math.ceil((stop - start) / step)) | 0,\n range = new Array(n);\n\n while (++i < n) {\n range[i] = start + i * step;\n }\n\n return range;\n}\n","export default function(polygon) {\n var i = -1,\n n = polygon.length,\n a,\n b = polygon[n - 1],\n area = 0;\n\n while (++i < n) {\n a = b;\n b = polygon[i];\n area += a[1] * b[0] - a[0] * b[1];\n }\n\n return area / 2;\n}\n","export default function(polygon) {\n var i = -1,\n n = polygon.length,\n x = 0,\n y = 0,\n a,\n b = polygon[n - 1],\n c,\n k = 0;\n\n while (++i < n) {\n a = b;\n b = polygon[i];\n k += c = a[0] * b[1] - b[0] * a[1];\n x += (a[0] + b[0]) * c;\n y += (a[1] + b[1]) * c;\n }\n\n return k *= 3, [x / k, y / k];\n}\n","export default function(polygon, point) {\n var n = polygon.length,\n p = polygon[n - 1],\n x = point[0], y = point[1],\n x0 = p[0], y0 = p[1],\n x1, y1,\n inside = false;\n\n for (var i = 0; i < n; ++i) {\n p = polygon[i], x1 = p[0], y1 = p[1];\n if (((y1 > y) !== (y0 > y)) && (x < (x0 - x1) * (y - y1) / (y0 - y1) + x1)) inside = !inside;\n x0 = x1, y0 = y1;\n }\n\n return inside;\n}\n","/**\n @function lineIntersection\n @desc Finds the intersection point (if there is one) of the lines p1q1 and p2q2.\n @param {Array} p1 The first point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q1 The second point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The first point of the second line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q2 The second point of the second line segment, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p1, q1, p2, q2) {\n\n // allow for some margins due to numerical errors\n const eps = 1e-9;\n\n // find the intersection point between the two infinite lines\n const dx1 = p1[0] - q1[0],\n dx2 = p2[0] - q2[0],\n dy1 = p1[1] - q1[1],\n dy2 = p2[1] - q2[1];\n\n const denom = dx1 * dy2 - dy1 * dx2;\n\n if (Math.abs(denom) < eps) return null;\n\n const cross1 = p1[0] * q1[1] - p1[1] * q1[0],\n cross2 = p2[0] * q2[1] - p2[1] * q2[0];\n\n const px = (cross1 * dx2 - cross2 * dx1) / denom,\n py = (cross1 * dy2 - cross2 * dy1) / denom;\n\n return [px, py];\n\n}\n","/**\n @function segmentBoxContains\n @desc Checks whether a point is inside the bounding box of a line segment.\n @param {Array} s1 The first point of the line segment to be used for the bounding box, which should always be an `[x, y]` formatted Array.\n @param {Array} s2 The second point of the line segment to be used for the bounding box, which should always be an `[x, y]` formatted Array.\n @param {Array} p The point to be checked, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(s1, s2, p) {\n\n const eps = 1e-9, [px, py] = p;\n\n return !(px < Math.min(s1[0], s2[0]) - eps || px > Math.max(s1[0], s2[0]) + eps ||\n py < Math.min(s1[1], s2[1]) - eps || py > Math.max(s1[1], s2[1]) + eps);\n\n}\n","import lineIntersection from \"./lineIntersection.js\";\nimport segmentBoxContains from \"./segmentBoxContains.js\";\n\n/**\n @function segmentsIntersect\n @desc Checks whether the line segments p1q1 && p2q2 intersect.\n @param {Array} p1 The first point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q1 The second point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The first point of the second line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q2 The second point of the second line segment, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p1, q1, p2, q2) {\n\n const p = lineIntersection(p1, q1, p2, q2);\n if (!p) return false;\n return segmentBoxContains(p1, q1, p) && segmentBoxContains(p2, q2, p);\n\n}\n","import {polygonContains} from \"d3-polygon\";\n\nimport segmentsIntersect from \"./segmentsIntersect.js\";\n\n/**\n @function polygonInside\n @desc Checks if one polygon is inside another polygon.\n @param {Array} polyA An Array of `[x, y]` points to be used as the inner polygon, checking if it is inside polyA.\n @param {Array} polyB An Array of `[x, y]` points to be used as the containing polygon.\n @returns {Boolean}\n*/\nexport default function(polyA, polyB) {\n\n let iA = -1;\n const nA = polyA.length;\n const nB = polyB.length;\n let bA = polyA[nA - 1];\n\n while (++iA < nA) {\n\n const aA = bA;\n bA = polyA[iA];\n\n let iB = -1;\n let bB = polyB[nB - 1];\n while (++iB < nB) {\n const aB = bB;\n bB = polyB[iB];\n if (segmentsIntersect(aA, bA, aB, bB)) return false;\n }\n }\n\n return polygonContains(polyB, polyA[0]);\n\n}\n","/**\n @function pointDistanceSquared\n @desc Returns the squared euclidean distance between two points.\n @param {Array} p1 The first point, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The second point, which should always be an `[x, y]` formatted Array.\n @returns {Number}\n*/\nexport default (p1, p2) => {\n\n const dx = p2[0] - p1[0],\n dy = p2[1] - p1[1];\n\n return dx * dx + dy * dy;\n\n};\n","import lineIntersection from \"./lineIntersection.js\";\nimport segmentBoxContains from \"./segmentBoxContains.js\";\nimport pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @function polygonRayCast\n @desc Gives the two closest intersection points between a ray cast from a point inside a polygon. The two points should lie on opposite sides of the origin.\n @param {Array} poly The polygon to test against, which should be an `[x, y]` formatted Array.\n @param {Array} origin The origin point of the ray to be cast, which should be an `[x, y]` formatted Array.\n @param {Number} [alpha = 0] The angle in radians of the ray.\n @returns {Array} An array containing two values, the closest point on the left and the closest point on the right. If either point cannot be found, that value will be `null`.\n*/\nexport default function(poly, origin, alpha = 0) {\n\n const eps = 1e-9;\n origin = [origin[0] + eps * Math.cos(alpha), origin[1] + eps * Math.sin(alpha)];\n const [x0, y0] = origin;\n const shiftedOrigin = [x0 + Math.cos(alpha), y0 + Math.sin(alpha)];\n\n let idx = 0;\n if (Math.abs(shiftedOrigin[0] - x0) < eps) idx = 1;\n let i = -1;\n const n = poly.length;\n let b = poly[n - 1];\n let minSqDistLeft = Number.MAX_VALUE;\n let minSqDistRight = Number.MAX_VALUE;\n let closestPointLeft = null;\n let closestPointRight = null;\n while (++i < n) {\n const a = b;\n b = poly[i];\n const p = lineIntersection(origin, shiftedOrigin, a, b);\n if (p && segmentBoxContains(a, b, p)) {\n const sqDist = pointDistanceSquared(origin, p);\n if (p[idx] < origin[idx]) {\n if (sqDist < minSqDistLeft) {\n minSqDistLeft = sqDist;\n closestPointLeft = p;\n }\n }\n else if (p[idx] > origin[idx]) {\n if (sqDist < minSqDistRight) {\n minSqDistRight = sqDist;\n closestPointRight = p;\n }\n }\n }\n }\n\n return [closestPointLeft, closestPointRight];\n\n}\n","/**\n @function pointRotate\n @desc Rotates a point around a given origin.\n @param {Array} p The point to be rotated, which should always be an `[x, y]` formatted Array.\n @param {Number} alpha The angle in radians to rotate.\n @param {Array} [origin = [0, 0]] The origin point of the rotation, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p, alpha, origin = [0, 0]) {\n\n const cosAlpha = Math.cos(alpha),\n sinAlpha = Math.sin(alpha),\n xshifted = p[0] - origin[0],\n yshifted = p[1] - origin[1];\n\n return [\n cosAlpha * xshifted - sinAlpha * yshifted + origin[0],\n sinAlpha * xshifted + cosAlpha * yshifted + origin[1]\n ];\n\n}\n","import pointRotate from \"./pointRotate.js\";\n\n/**\n @function polygonRotate\n @desc Rotates a point around a given origin.\n @param {Array} poly The polygon to be rotated, which should be an Array of `[x, y]` values.\n @param {Number} alpha The angle in radians to rotate.\n @param {Array} [origin = [0, 0]] The origin point of the rotation, which should be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default (poly, alpha, origin = [0, 0]) => poly.map(p => pointRotate(p, alpha, origin));\n","import pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @desc square distance from a point to a segment\n @param {Array} point\n @param {Array} segmentAnchor1\n @param {Array} segmentAnchor2\n @private\n*/\nfunction getSqSegDist(p, p1, p2) {\n\n let x = p1[0],\n y = p1[1];\n\n let dx = p2[0] - x,\n dy = p2[1] - y;\n\n if (dx !== 0 || dy !== 0) {\n\n const t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);\n\n if (t > 1) {\n x = p2[0];\n y = p2[1];\n\n }\n else if (t > 0) {\n x += dx * t;\n y += dy * t;\n }\n\n }\n\n dx = p[0] - x;\n dy = p[1] - y;\n\n return dx * dx + dy * dy;\n\n}\n\n/**\n @desc basic distance-based simplification\n @param {Array} polygon\n @param {Number} sqTolerance\n @private\n*/\nfunction simplifyRadialDist(poly, sqTolerance) {\n\n let point,\n prevPoint = poly[0];\n\n const newPoints = [prevPoint];\n\n for (let i = 1, len = poly.length; i < len; i++) {\n point = poly[i];\n\n if (pointDistanceSquared(point, prevPoint) > sqTolerance) {\n newPoints.push(point);\n prevPoint = point;\n }\n }\n\n if (prevPoint !== point) newPoints.push(point);\n\n return newPoints;\n}\n\n/**\n @param {Array} polygon\n @param {Number} first\n @param {Number} last\n @param {Number} sqTolerance\n @param {Array} simplified\n @private\n*/\nfunction simplifyDPStep(poly, first, last, sqTolerance, simplified) {\n\n let index, maxSqDist = sqTolerance;\n\n for (let i = first + 1; i < last; i++) {\n const sqDist = getSqSegDist(poly[i], poly[first], poly[last]);\n\n if (sqDist > maxSqDist) {\n index = i;\n maxSqDist = sqDist;\n }\n }\n\n if (maxSqDist > sqTolerance) {\n if (index - first > 1) simplifyDPStep(poly, first, index, sqTolerance, simplified);\n simplified.push(poly[index]);\n if (last - index > 1) simplifyDPStep(poly, index, last, sqTolerance, simplified);\n }\n}\n\n/**\n @desc simplification using Ramer-Douglas-Peucker algorithm\n @param {Array} polygon\n @param {Number} sqTolerance\n @private\n*/\nfunction simplifyDouglasPeucker(poly, sqTolerance) {\n const last = poly.length - 1;\n\n const simplified = [poly[0]];\n simplifyDPStep(poly, 0, last, sqTolerance, simplified);\n simplified.push(poly[last]);\n\n return simplified;\n}\n\n/**\n @function largestRect\n @desc Simplifies the points of a polygon using both the Ramer-Douglas-Peucker algorithm and basic distance-based simplification. Adapted to an ES6 module from the excellent [Simplify.js](http://mourner.github.io/simplify-js/).\n @author Vladimir Agafonkin\n @param {Array} poly An Array of points that represent a polygon.\n @param {Number} [tolerance = 1] Affects the amount of simplification (in the same metric as the point coordinates).\n @param {Boolean} [highestQuality = false] Excludes distance-based preprocessing step which leads to highest quality simplification but runs ~10-20 times slower.\n\n*/\nexport default (poly, tolerance = 1, highestQuality = false) => {\n\n if (poly.length <= 2) return poly;\n\n const sqTolerance = tolerance * tolerance;\n\n poly = highestQuality ? poly : simplifyRadialDist(poly, sqTolerance);\n poly = simplifyDouglasPeucker(poly, sqTolerance);\n\n return poly;\n\n};\n","import {extent, merge, range} from \"d3-array\";\nimport {polygonArea, polygonCentroid, polygonContains} from \"d3-polygon\";\n\nimport polygonInside from \"./polygonInside.js\";\nimport polygonRayCast from \"./polygonRayCast.js\";\nimport polygonRotate from \"./polygonRotate.js\";\nimport simplify from \"./simplify.js\";\nimport pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n// Algorithm constants\nconst aspectRatioStep = 0.5; // step size for the aspect ratio\nconst angleStep = 5; // step size for angles (in degrees); has linear impact on running time\n\nconst polyCache = {};\n\n/**\n @typedef {Object} largestRect\n @desc The returned Object of the largestRect function.\n @property {Number} width The width of the rectangle\n @property {Number} height The height of the rectangle\n @property {Number} cx The x coordinate of the rectangle's center\n @property {Number} cy The y coordinate of the rectangle's center\n @property {Number} angle The rotation angle of the rectangle in degrees. The anchor of rotation is the center point.\n @property {Number} area The area of the largest rectangle.\n @property {Array} points An array of x/y coordinates for each point in the rectangle, useful for rendering paths.\n*/\n\n/**\n @function largestRect\n @author Daniel Smilkov [dsmilkov@gmail.com]\n @desc An angle of zero means that the longer side of the polygon (the width) will be aligned with the x axis. An angle of 90 and/or -90 means that the longer side of the polygon (the width) will be aligned with the y axis. The value can be a number between -90 and 90 specifying the angle of rotation of the polygon, a string which is parsed to a number, or an array of numbers specifying the possible rotations of the polygon.\n @param {Array} poly An Array of points that represent a polygon.\n @param {Object} [options] An Object that allows for overriding various parameters of the algorithm.\n @param {Number|String|Array} [options.angle = d3.range(-90, 95, 5)] The allowed rotations of the final rectangle.\n @param {Number|String|Array} [options.aspectRatio] The ratio between the width and height of the rectangle. The value can be a number, a string which is parsed to a number, or an array of numbers specifying the possible aspect ratios of the final rectangle.\n @param {Number} [options.maxAspectRatio = 15] The maximum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided.\n @param {Number} [options.minAspectRatio = 1] The minimum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided.\n @param {Number} [options.nTries = 20] The number of randomly drawn points inside the polygon which the algorithm explores as possible center points of the maximal rectangle.\n @param {Number} [options.minHeight = 0] The minimum height of the rectangle.\n @param {Number} [options.minWidth = 0] The minimum width of the rectangle.\n @param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.\n @param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.\n @param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.\n @return {largestRect}\n*/\nexport default function(poly, options = {}) {\n\n if (poly.length < 3) {\n if (options.verbose) console.error(\"polygon has to have at least 3 points\", poly);\n return null;\n }\n\n // For visualization debugging purposes\n const events = [];\n\n // User's input normalization\n options = Object.assign({\n angle: range(-90, 90 + angleStep, angleStep),\n cache: true,\n maxAspectRatio: 15,\n minAspectRatio: 1,\n minHeight: 0,\n minWidth: 0,\n nTries: 20,\n tolerance: 0.02,\n verbose: false\n }, options);\n\n const angles = options.angle instanceof Array ? options.angle\n : typeof options.angle === \"number\" ? [options.angle]\n : typeof options.angle === \"string\" && !isNaN(options.angle) ? [Number(options.angle)]\n : [];\n\n const aspectRatios = options.aspectRatio instanceof Array ? options.aspectRatio\n : typeof options.aspectRatio === \"number\" ? [options.aspectRatio]\n : typeof options.aspectRatio === \"string\" && !isNaN(options.aspectRatio) ? [Number(options.aspectRatio)]\n : [];\n\n const origins = options.origin && options.origin instanceof Array\n ? options.origin[0] instanceof Array ? options.origin\n : [options.origin] : [];\n\n let cacheString;\n if (options.cache) {\n cacheString = merge(poly).join(\",\");\n cacheString += `-${options.minAspectRatio}`;\n cacheString += `-${options.maxAspectRatio}`;\n cacheString += `-${options.minHeight}`;\n cacheString += `-${options.minWidth}`;\n cacheString += `-${angles.join(\",\")}`;\n cacheString += `-${origins.join(\",\")}`;\n if (polyCache[cacheString]) return polyCache[cacheString];\n }\n\n const area = Math.abs(polygonArea(poly)); // take absolute value of the signed area\n if (area === 0) {\n if (options.verbose) console.error(\"polygon has 0 area\", poly);\n return null;\n }\n // get the width of the bounding box of the original polygon to determine tolerance\n let [minx, maxx] = extent(poly, d => d[0]);\n let [miny, maxy] = extent(poly, d => d[1]);\n\n // simplify polygon\n const tolerance = Math.min(maxx - minx, maxy - miny) * options.tolerance;\n\n if (tolerance > 0) poly = simplify(poly, tolerance);\n if (options.events) events.push({type: \"simplify\", poly});\n\n // get the width of the bounding box of the simplified polygon\n [minx, maxx] = extent(poly, d => d[0]);\n [miny, maxy] = extent(poly, d => d[1]);\n const [boxWidth, boxHeight] = [maxx - minx, maxy - miny];\n\n // discretize the binary search for optimal width to a resolution of this times the polygon width\n const widthStep = Math.min(boxWidth, boxHeight) / 50;\n\n // populate possible center points with random points inside the polygon\n if (!origins.length) {\n // get the centroid of the polygon\n const centroid = polygonCentroid(poly);\n if (!isFinite(centroid[0])) {\n if (options.verbose) console.error(\"cannot find centroid\", poly);\n return null;\n }\n if (polygonContains(poly, centroid)) origins.push(centroid);\n\n let nTries = options.nTries;\n // get few more points inside the polygon\n while (nTries) {\n const rndX = Math.random() * boxWidth + minx;\n const rndY = Math.random() * boxHeight + miny;\n const rndPoint = [rndX, rndY];\n if (polygonContains(poly, rndPoint)) {\n origins.push(rndPoint);\n }\n nTries--;\n }\n }\n if (options.events) events.push({type: \"origins\", points: origins});\n let maxArea = 0;\n let maxRect = null;\n\n for (let ai = 0; ai < angles.length; ai++) {\n const angle = angles[ai];\n const angleRad = -angle * Math.PI / 180;\n if (options.events) events.push({type: \"angle\", angle});\n for (let i = 0; i < origins.length; i++) {\n const origOrigin = origins[i];\n // generate improved origins\n const [p1W, p2W] = polygonRayCast(poly, origOrigin, angleRad);\n const [p1H, p2H] = polygonRayCast(poly, origOrigin, angleRad + Math.PI / 2);\n const modifOrigins = [];\n if (p1W && p2W) modifOrigins.push([(p1W[0] + p2W[0]) / 2, (p1W[1] + p2W[1]) / 2]); // average along with width axis\n if (p1H && p2H) modifOrigins.push([(p1H[0] + p2H[0]) / 2, (p1H[1] + p2H[1]) / 2]); // average along with height axis\n\n if (options.events) events.push({type: \"modifOrigin\", idx: i, p1W, p2W, p1H, p2H, modifOrigins});\n\n for (let i = 0; i < modifOrigins.length; i++) {\n\n const origin = modifOrigins[i];\n\n if (options.events) events.push({type: \"origin\", cx: origin[0], cy: origin[1]});\n\n const [p1W, p2W] = polygonRayCast(poly, origin, angleRad);\n if (p1W === null || p2W === null) continue;\n const minSqDistW = Math.min(pointDistanceSquared(origin, p1W), pointDistanceSquared(origin, p2W));\n const maxWidth = 2 * Math.sqrt(minSqDistW);\n\n const [p1H, p2H] = polygonRayCast(poly, origin, angleRad + Math.PI / 2);\n if (p1H === null || p2H === null) continue;\n const minSqDistH = Math.min(pointDistanceSquared(origin, p1H), pointDistanceSquared(origin, p2H));\n const maxHeight = 2 * Math.sqrt(minSqDistH);\n\n if (maxWidth * maxHeight < maxArea) continue;\n\n let aRatios = aspectRatios;\n if (!aRatios.length) {\n const minAspectRatio = Math.max(options.minAspectRatio, options.minWidth / maxHeight, maxArea / (maxHeight * maxHeight));\n const maxAspectRatio = Math.min(options.maxAspectRatio, maxWidth / options.minHeight, maxWidth * maxWidth / maxArea);\n aRatios = range(minAspectRatio, maxAspectRatio + aspectRatioStep, aspectRatioStep);\n }\n\n for (let a = 0; a < aRatios.length; a++) {\n\n const aRatio = aRatios[a];\n\n // do a binary search to find the max width that works\n let left = Math.max(options.minWidth, Math.sqrt(maxArea * aRatio));\n let right = Math.min(maxWidth, maxHeight * aRatio);\n if (right * maxHeight < maxArea) continue;\n\n if (options.events && right - left >= widthStep) events.push({type: \"aRatio\", aRatio});\n\n while (right - left >= widthStep) {\n const width = (left + right) / 2;\n const height = width / aRatio;\n const [cx, cy] = origin;\n let rectPoly = [\n [cx - width / 2, cy - height / 2],\n [cx + width / 2, cy - height / 2],\n [cx + width / 2, cy + height / 2],\n [cx - width / 2, cy + height / 2]\n ];\n rectPoly = polygonRotate(rectPoly, angleRad, origin);\n const insidePoly = polygonInside(rectPoly, poly);\n if (insidePoly) {\n // we know that the area is already greater than the maxArea found so far\n maxArea = width * height;\n rectPoly.push(rectPoly[0]);\n maxRect = {area: maxArea, cx, cy, width, height, angle: -angle, points: rectPoly};\n left = width; // increase the width in the binary search\n }\n else {\n right = width; // decrease the width in the binary search\n }\n if (options.events) events.push({type: \"rectangle\", areaFraction: width * height / area, cx, cy, width, height, angle, insidePoly});\n\n }\n\n }\n\n }\n\n }\n\n }\n\n if (options.cache) {\n polyCache[cacheString] = maxRect;\n }\n\n return options.events ? Object.assign(maxRect || {}, {events}) : maxRect;\n\n}\n","/**\n @function path2polygon\n @desc Transforms a path string into an Array of points.\n @param {String} path An SVG string path, commonly the \"d\" property of a <path> element.\n @param {Number} [segmentLength = 50] The length of line segments when converting curves line segments. Higher values lower computation time, but will result in curves that are more rigid.\n @returns {Array}\n*/\nexport default (path, segmentLength = 50) => {\n\n if (typeof document === \"undefined\") return [];\n\n const svgPath = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n svgPath.setAttribute(\"d\", path);\n\n const len = svgPath.getTotalLength();\n const NUM_POINTS = len / segmentLength < 10 ? len / 10 : len / segmentLength;\n\n const points = [];\n for (let i = 0; i < NUM_POINTS; i++) {\n const pt = svgPath.getPointAtLength(i * len / (NUM_POINTS-1));\n points.push([pt.x, pt.y]);\n }\n \n return points;\n\n};\n","import pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @function pointDistance\n @desc Calculates the pixel distance between two points.\n @param {Array} p1 The first point, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The second point, which should always be an `[x, y]` formatted Array.\n @returns {Number}\n*/\nexport default (p1, p2) => Math.sqrt(pointDistanceSquared(p1, p2));\n","const pi = Math.PI;\n\n/**\n @function shapeEdgePoint\n @desc Calculates the x/y position of a point at the edge of a shape, from the center of the shape, given a specified pixel distance and radian angle.\n @param {Number} angle The angle, in radians, of the offset point.\n @param {Number} distance The pixel distance away from the origin.\n @returns {String} [shape = \"circle\"] The type of shape, which can be either \"circle\" or \"square\".\n*/\nexport default (angle, distance, shape = \"circle\") => {\n\n if (angle < 0) angle = pi * 2 + angle;\n\n if (shape === \"square\") {\n\n const diagonal = 45 * (pi / 180);\n let x = 0, y = 0;\n\n if (angle < pi / 2) {\n const tan = Math.tan(angle);\n x += angle < diagonal ? distance : distance / tan;\n y += angle < diagonal ? tan * distance : distance;\n }\n else if (angle <= pi) {\n const tan = Math.tan(pi - angle);\n x -= angle < pi - diagonal ? distance / tan : distance;\n y += angle < pi - diagonal ? distance : tan * distance;\n }\n else if (angle < diagonal + pi) {\n x -= distance;\n y -= Math.tan(angle - pi) * distance;\n }\n else if (angle < 3 * pi / 2) {\n x -= distance / Math.tan(angle - pi);\n y -= distance;\n }\n else if (angle < 2 * pi - diagonal) {\n x += distance / Math.tan(2 * pi - angle);\n y -= distance;\n }\n else {\n x += distance;\n y -= Math.tan(2 * pi - angle) * distance;\n }\n\n return [x, y];\n\n }\n else if (shape === \"circle\") {\n return [distance * Math.cos(angle), distance * Math.sin(angle)];\n }\n else return null;\n\n};\n"],"names":["numericSort","array","slice","sort","a","b","uniqueCountSorted","input","lastSeenValue","uniqueValueCount","i","length","makeMatrix","columns","rows","matrix","column","j","push","ssq","sums","sumsOfSquares","sji","muji","fillMatrixColumn","iMin","iMax","cluster","backtrackMatrix","Math","floor","jlow","max","jhigh","min","sjlowi","ssqjlow","ssqj","fillMatrices","data","nValues","shift","shiftedValue","nClusters","Error","sorted","uniqueCount","clusterRight","clusters","clusterLeft","n","arr","Array","undefined","reduce","prev","curr","abs","extent","values","valueof","value","index","flatten","arrays","merge","from","range","start","stop","step","arguments","ceil","polygon","area","x","y","c","k","point","p","x0","y0","x1","y1","inside","p1","q1","p2","q2","eps","dx1","dx2","dy1","dy2","denom","cross1","cross2","px","py","s1","s2","lineIntersection","segmentBoxContains","polyA","polyB","iA","nA","nB","bA","aA","iB","bB","aB","segmentsIntersect","polygonContains","dx","dy","poly","origin","alpha","cos","sin","shiftedOrigin","idx","minSqDistLeft","Number","MAX_VALUE","minSqDistRight","closestPointLeft","closestPointRight","sqDist","pointDistanceSquared","cosAlpha","sinAlpha","xshifted","yshifted","map","pointRotate","getSqSegDist","t","simplifyRadialDist","sqTolerance","prevPoint","newPoints","len","simplifyDPStep","first","last","simplified","maxSqDist","simplifyDouglasPeucker","tolerance","highestQuality","aspectRatioStep","angleStep","polyCache","options","verbose","console","error","events","Object","assign","angle","cache","maxAspectRatio","minAspectRatio","minHeight","minWidth","nTries","angles","isNaN","aspectRatios","aspectRatio","origins","cacheString","join","polygonArea","minx","maxx","d","miny","maxy","simplify","type","boxWidth","boxHeight","widthStep","centroid","polygonCentroid","isFinite","rndX","random","rndY","rndPoint","points","maxArea","maxRect","ai","angleRad","PI","origOrigin","p1W","p2W","polygonRayCast","p1H","p2H","modifOrigins","cx","cy","minSqDistW","maxWidth","sqrt","minSqDistH","maxHeight","aRatios","aRatio","left","right","width","height","rectPoly","polygonRotate","insidePoly","polygonInside","areaFraction","path","segmentLength","document","svgPath","createElementNS","setAttribute","getTotalLength","NUM_POINTS","pt","getPointAtLength","pi","distance","shape","diagonal","tan"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;EAcA,GACA,SAASA,YAAYC,KAAK,EAAA;MACxB,OAAOA,KAAAA,CAAMC,KAAK,EAAGC,CAAAA,IAAI,CAAC,CAACC,CAAAA,EAAGC,IAAMD,CAAIC,GAAAA,CAAAA,CAAAA;EAC1C;EAEA;;;;;;;;;;EAUA,GACA,SAASC,kBAAkBC,KAAK,EAAA;EAC9B,IAAA,IAAIC,eAAeC,gBAAmB,GAAA,CAAA;EACtC,IAAA,IAAK,IAAIC,CAAI,GAAA,CAAA,EAAGA,IAAIH,KAAMI,CAAAA,MAAM,EAAED,CAAK,EAAA,CAAA;EACrC,QAAA,IAAIA,MAAM,CAAKH,IAAAA,KAAK,CAACG,CAAAA,CAAE,KAAKF,aAAe,EAAA;cACzCA,aAAgBD,GAAAA,KAAK,CAACG,CAAE,CAAA;EACxBD,YAAAA,gBAAAA,EAAAA;EACF;EACF;MACA,OAAOA,gBA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,KAAKzE,KAAS0E,CAAAA,GAAAA,QAAAA;EAClC;UAEA,OAAO;EAACnK,YAAAA,CAAAA;EAAGC,YAAAA;EAAE,SAAA;OAGV,MAAA,IAAImK,UAAU,QAAU,EAAA;UAC3B,OAAO;cAACD,QAAWjN,GAAAA,IAAAA,CAAK4F,GAAG,CAAC2C,KAAAA,CAAAA;cAAQ0E,QAAWjN,GAAAA,IAAAA,CAAK6F,GAAG,CAAC0C,KAAAA;EAAO,SAAA;EACjE,KAAA,MACK,OAAO,IAAA;EAEd,CAAA;;;;;;;;;;;;;;;;;;;;;;","x_google_ignoreList":[2,3,4,5,6,7]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/math v3.0.0-alpha.
|
|
2
|
+
@d3plus/math v3.0.0-alpha.4
|
|
3
3
|
Mathematical functions to aid in calculating visualizations.
|
|
4
4
|
Copyright (c) 2025 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
@@ -235,7 +235,7 @@ i[t]=n.slice(o,a+1),0<t&&(a=o-1)}return i}
|
|
|
235
235
|
@param {Array} arr The array of values to test against.
|
|
236
236
|
*/,t.closest=function(n,t=[]){if(t&&t instanceof Array&&t.length)return t.reduce((t,e)=>Math.abs(e-n)<Math.abs(t-n)?e:t)},t.largestRect=
|
|
237
237
|
/**
|
|
238
|
-
@typedef {Object}
|
|
238
|
+
@typedef {Object} largestRect
|
|
239
239
|
@desc The returned Object of the largestRect function.
|
|
240
240
|
@property {Number} width The width of the rectangle
|
|
241
241
|
@property {Number} height The height of the rectangle
|
|
@@ -261,7 +261,7 @@ i[t]=n.slice(o,a+1),0<t&&(a=o-1)}return i}
|
|
|
261
261
|
@param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.
|
|
262
262
|
@param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.
|
|
263
263
|
@param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.
|
|
264
|
-
@return {
|
|
264
|
+
@return {largestRect}
|
|
265
265
|
*/function(a,i={}){if(a.length<3)return i.verbose&&console.error("polygon has to have at least 3 points",a),null;
|
|
266
266
|
// For visualization debugging purposes
|
|
267
267
|
var o=[],e=(
|
package/umd/d3plus-math.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/math v3.0.0-alpha.
|
|
2
|
+
@d3plus/math v3.0.0-alpha.4
|
|
3
3
|
Mathematical functions to aid in calculating visualizations.
|
|
4
4
|
Copyright (c) 2025 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
@@ -594,7 +594,7 @@
|
|
|
594
594
|
const angleStep = 5; // step size for angles (in degrees); has linear impact on running time
|
|
595
595
|
const polyCache = {};
|
|
596
596
|
/**
|
|
597
|
-
@typedef {Object}
|
|
597
|
+
@typedef {Object} largestRect
|
|
598
598
|
@desc The returned Object of the largestRect function.
|
|
599
599
|
@property {Number} width The width of the rectangle
|
|
600
600
|
@property {Number} height The height of the rectangle
|
|
@@ -619,7 +619,7 @@
|
|
|
619
619
|
@param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.
|
|
620
620
|
@param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.
|
|
621
621
|
@param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.
|
|
622
|
-
@return {
|
|
622
|
+
@return {largestRect}
|
|
623
623
|
*/ function largestRect(poly, options = {}) {
|
|
624
624
|
if (poly.length < 3) {
|
|
625
625
|
if (options.verbose) console.error("polygon has to have at least 3 points", poly);
|
package/umd/d3plus-math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"d3plus-math.js","sources":["../src/ckmeans.js","../src/closest.js","../src/lineIntersection.js","../src/segmentBoxContains.js","../src/segmentsIntersect.js","../src/polygonInside.js","../src/pointDistanceSquared.js","../src/polygonRayCast.js","../src/pointRotate.js","../src/polygonRotate.js","../src/simplify.js","../src/largestRect.js","../src/path2polygon.js","../src/pointDistance.js","../src/shapeEdgePoint.js"],"sourcesContent":["/**\n @desc Sort an array of numbers by their numeric value, ensuring that the array is not changed in place.\n\nThis is necessary because the default behavior of .sort in JavaScript is to sort arrays as string values\n\n[1, 10, 12, 102, 20].sort()\n// output\n[1, 10, 102, 12, 20]\n\n @param {Array<number>} array input array\n @return {Array<number>} sorted array\n @private\n @example\nnumericSort([3, 2, 1]) // => [1, 2, 3]\n*/\nfunction numericSort(array) {\n return array.slice().sort((a, b) => a - b);\n}\n\n/**\n For a sorted input, counting the number of unique values is possible in constant time and constant memory. This is a simple implementation of the algorithm.\n\n Values are compared with `===`, so objects and non-primitive objects are not handled in any special way.\n @private\n @param {Array} input an array of primitive values.\n @returns {number} count of unique values\n @example\nuniqueCountSorted([1, 2, 3]); // => 3\nuniqueCountSorted([1, 1, 1]); // => 1\n*/\nfunction uniqueCountSorted(input) {\n let lastSeenValue, uniqueValueCount = 0;\n for (let i = 0; i < input.length; i++) {\n if (i === 0 || input[i] !== lastSeenValue) {\n lastSeenValue = input[i];\n uniqueValueCount++;\n }\n }\n return uniqueValueCount;\n}\n\n/**\n Create a new column x row matrix.\n @private\n @param {number} columns\n @param {number} rows\n @return {Array<Array<number>>} matrix\n @example\nmakeMatrix(10, 10);\n*/\nfunction makeMatrix(columns, rows) {\n const matrix = [];\n for (let i = 0; i < columns; i++) {\n const column = [];\n for (let j = 0; j < rows; j++) column.push(0);\n matrix.push(column);\n }\n return matrix;\n}\n\n/**\n Generates incrementally computed values based on the sums and sums of squares for the data array\n @private\n @param {number} j\n @param {number} i\n @param {Array<number>} sums\n @param {Array<number>} sumsOfSquares\n @return {number}\n @example\nssq(0, 1, [-1, 0, 2], [1, 1, 5]);\n*/\nfunction ssq(j, i, sums, sumsOfSquares) {\n let sji; // s(j, i)\n\n if (j > 0) {\n const muji = (sums[i] - sums[j - 1]) / (i - j + 1); // mu(j, i)\n sji = sumsOfSquares[i] - sumsOfSquares[j - 1] - (i - j + 1) * muji * muji;\n }\n else sji = sumsOfSquares[i] - sums[i] * sums[i] / (i + 1);\n\n if (sji < 0) return 0;\n return sji;\n}\n\n/**\n Function that recursively divides and conquers computations for cluster j\n @private\n @param {number} iMin Minimum index in cluster to be computed\n @param {number} iMax Maximum index in cluster to be computed\n @param {number} cluster Index of the cluster currently being computed\n @param {Array<Array<number>>} matrix\n @param {Array<Array<number>>} backtrackMatrix\n @param {Array<number>} sums\n @param {Array<number>} sumsOfSquares\n*/\nfunction fillMatrixColumn(iMin, iMax, cluster, matrix, backtrackMatrix, sums, sumsOfSquares) {\n if (iMin > iMax) return;\n\n // Start at midpoint between iMin and iMax\n const i = Math.floor((iMin + iMax) / 2);\n\n matrix[cluster][i] = matrix[cluster - 1][i - 1];\n backtrackMatrix[cluster][i] = i;\n\n let jlow = cluster; // the lower end for j\n if (iMin > cluster) jlow = Math.max(jlow, backtrackMatrix[cluster][iMin - 1] || 0);\n jlow = Math.max(jlow, backtrackMatrix[cluster - 1][i] || 0);\n\n let jhigh = i - 1; // the upper end for j\n if (iMax < matrix.length - 1) jhigh = Math.min(jhigh, backtrackMatrix[cluster][iMax + 1] || 0);\n\n for (let j = jhigh; j >= jlow; --j) {\n const sji = ssq(j, i, sums, sumsOfSquares);\n\n if (sji + matrix[cluster - 1][jlow - 1] >= matrix[cluster][i]) break;\n\n // Examine the lower bound of the cluster border\n const sjlowi = ssq(jlow, i, sums, sumsOfSquares);\n\n const ssqjlow = sjlowi + matrix[cluster - 1][jlow - 1];\n\n if (ssqjlow < matrix[cluster][i]) {\n // Shrink the lower bound\n matrix[cluster][i] = ssqjlow;\n backtrackMatrix[cluster][i] = jlow;\n }\n jlow++;\n\n const ssqj = sji + matrix[cluster - 1][j - 1];\n if (ssqj < matrix[cluster][i]) {\n matrix[cluster][i] = ssqj;\n backtrackMatrix[cluster][i] = j;\n }\n }\n\n fillMatrixColumn(iMin, i - 1, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n fillMatrixColumn(i + 1, iMax, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n\n}\n\n/**\n Initializes the main matrices used in Ckmeans and kicks off the divide and conquer cluster computation strategy\n @private\n @param {Array<number>} data sorted array of values\n @param {Array<Array<number>>} matrix\n @param {Array<Array<number>>} backtrackMatrix\n*/\nfunction fillMatrices(data, matrix, backtrackMatrix) {\n const nValues = matrix[0] ? matrix[0].length : 0;\n\n // Shift values by the median to improve numeric stability\n const shift = data[Math.floor(nValues / 2)];\n\n // Cumulative sum and cumulative sum of squares for all values in data array\n const sums = [];\n const sumsOfSquares = [];\n\n // Initialize first column in matrix & backtrackMatrix\n for (let i = 0, shiftedValue = void 0; i < nValues; ++i) {\n shiftedValue = data[i] - shift;\n if (i === 0) {\n sums.push(shiftedValue);\n sumsOfSquares.push(shiftedValue * shiftedValue);\n }\n else {\n sums.push(sums[i - 1] + shiftedValue);\n sumsOfSquares.push(sumsOfSquares[i - 1] + shiftedValue * shiftedValue);\n }\n\n // Initialize for cluster = 0\n matrix[0][i] = ssq(0, i, sums, sumsOfSquares);\n backtrackMatrix[0][i] = 0;\n }\n\n // Initialize the rest of the columns\n for (let cluster = 1; cluster < matrix.length; ++cluster) {\n let iMin = nValues - 1;\n if (cluster < matrix.length - 1) iMin = cluster;\n fillMatrixColumn(iMin, nValues - 1, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n }\n}\n\n/**\n @module ckmeans\n @desc Ported to ES6 from the excellent [simple-statistics](https://github.com/simple-statistics/simple-statistics) packages.\n\nCkmeans clustering is an improvement on heuristic-based clustering approaches like Jenks. The algorithm was developed in [Haizhou Wang and Mingzhou Song](http://journal.r-project.org/archive/2011-2/RJournal_2011-2_Wang+Song.pdf) as a [dynamic programming](https://en.wikipedia.org/wiki/Dynamic_programming) approach to the problem of clustering numeric data into groups with the least within-group sum-of-squared-deviations.\n\nMinimizing the difference within groups - what Wang & Song refer to as `withinss`, or within sum-of-squares, means that groups are optimally homogenous within and the data is split into representative groups. This is very useful for visualization, where you may want to represent a continuous variable in discrete color or style groups. This function can provide groups that emphasize differences between data.\n\nBeing a dynamic approach, this algorithm is based on two matrices that store incrementally-computed values for squared deviations and backtracking indexes.\n\nThis implementation is based on Ckmeans 3.4.6, which introduced a new divide and conquer approach that improved runtime from O(kn^2) to O(kn log(n)).\n\nUnlike the [original implementation](https://cran.r-project.org/web/packages/Ckmeans.1d.dp/index.html), this implementation does not include any code to automatically determine the optimal number of clusters: this information needs to be explicitly provided.\n\n### References\n_Ckmeans.1d.dp: Optimal k-means Clustering in One Dimension by Dynamic\nProgramming_ Haizhou Wang and Mingzhou Song ISSN 2073-4859 from The R Journal Vol. 3/2, December 2011\n @param {Array<number>} data input data, as an array of number values\n @param {number} nClusters number of desired classes. This cannot be greater than the number of values in the data array.\n @returns {Array<Array<number>>} clustered input\n @private\n @example\nckmeans([-1, 2, -1, 2, 4, 5, 6, -1, 2, -1], 3);\n// The input, clustered into groups of similar numbers.\n//= [[-1, -1, -1, -1], [2, 2, 2], [4, 5, 6]]);\n*/\nexport default function(data, nClusters) {\n\n if (nClusters > data.length) {\n throw new Error(\"Cannot generate more classes than there are data values\");\n }\n\n const sorted = numericSort(data);\n\n // we'll use this as the maximum number of clusters\n const uniqueCount = uniqueCountSorted(sorted);\n\n // if all of the input values are identical, there's one cluster with all of the input in it.\n if (uniqueCount === 1) {\n return [sorted];\n }\n\n const backtrackMatrix = makeMatrix(nClusters, sorted.length),\n matrix = makeMatrix(nClusters, sorted.length);\n\n // This is a dynamic programming way to solve the problem of minimizing within-cluster sum of squares. It's similar to linear regression in this way, and this calculation incrementally computes the sum of squares that are later read.\n fillMatrices(sorted, matrix, backtrackMatrix);\n\n // The real work of Ckmeans clustering happens in the matrix generation: the generated matrices encode all possible clustering combinations, and once they're generated we can solve for the best clustering groups very quickly.\n let clusterRight = backtrackMatrix[0] ? backtrackMatrix[0].length - 1 : 0;\n const clusters = [];\n\n // Backtrack the clusters from the dynamic programming matrix. This starts at the bottom-right corner of the matrix (if the top-left is 0, 0), and moves the cluster target with the loop.\n for (let cluster = backtrackMatrix.length - 1; cluster >= 0; cluster--) {\n\n const clusterLeft = backtrackMatrix[cluster][clusterRight];\n\n // fill the cluster from the sorted input by taking a slice of the array. the backtrack matrix makes this easy - it stores the indexes where the cluster should start and end.\n clusters[cluster] = sorted.slice(clusterLeft, clusterRight + 1);\n\n if (cluster > 0) clusterRight = clusterLeft - 1;\n\n }\n\n return clusters;\n\n}\n","/**\n @function closest\n @desc Finds the closest numeric value in an array.\n @param {Number} n The number value to use when searching the array.\n @param {Array} arr The array of values to test against.\n*/\nexport default function(n, arr = []) {\n if (!arr || !(arr instanceof Array) || !arr.length) return undefined;\n return arr.reduce((prev, curr) => Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev);\n}\n","/**\n @function lineIntersection\n @desc Finds the intersection point (if there is one) of the lines p1q1 and p2q2.\n @param {Array} p1 The first point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q1 The second point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The first point of the second line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q2 The second point of the second line segment, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p1, q1, p2, q2) {\n\n // allow for some margins due to numerical errors\n const eps = 1e-9;\n\n // find the intersection point between the two infinite lines\n const dx1 = p1[0] - q1[0],\n dx2 = p2[0] - q2[0],\n dy1 = p1[1] - q1[1],\n dy2 = p2[1] - q2[1];\n\n const denom = dx1 * dy2 - dy1 * dx2;\n\n if (Math.abs(denom) < eps) return null;\n\n const cross1 = p1[0] * q1[1] - p1[1] * q1[0],\n cross2 = p2[0] * q2[1] - p2[1] * q2[0];\n\n const px = (cross1 * dx2 - cross2 * dx1) / denom,\n py = (cross1 * dy2 - cross2 * dy1) / denom;\n\n return [px, py];\n\n}\n","/**\n @function segmentBoxContains\n @desc Checks whether a point is inside the bounding box of a line segment.\n @param {Array} s1 The first point of the line segment to be used for the bounding box, which should always be an `[x, y]` formatted Array.\n @param {Array} s2 The second point of the line segment to be used for the bounding box, which should always be an `[x, y]` formatted Array.\n @param {Array} p The point to be checked, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(s1, s2, p) {\n\n const eps = 1e-9, [px, py] = p;\n\n return !(px < Math.min(s1[0], s2[0]) - eps || px > Math.max(s1[0], s2[0]) + eps ||\n py < Math.min(s1[1], s2[1]) - eps || py > Math.max(s1[1], s2[1]) + eps);\n\n}\n","import lineIntersection from \"./lineIntersection.js\";\nimport segmentBoxContains from \"./segmentBoxContains.js\";\n\n/**\n @function segmentsIntersect\n @desc Checks whether the line segments p1q1 && p2q2 intersect.\n @param {Array} p1 The first point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q1 The second point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The first point of the second line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q2 The second point of the second line segment, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p1, q1, p2, q2) {\n\n const p = lineIntersection(p1, q1, p2, q2);\n if (!p) return false;\n return segmentBoxContains(p1, q1, p) && segmentBoxContains(p2, q2, p);\n\n}\n","import {polygonContains} from \"d3-polygon\";\n\nimport segmentsIntersect from \"./segmentsIntersect.js\";\n\n/**\n @function polygonInside\n @desc Checks if one polygon is inside another polygon.\n @param {Array} polyA An Array of `[x, y]` points to be used as the inner polygon, checking if it is inside polyA.\n @param {Array} polyB An Array of `[x, y]` points to be used as the containing polygon.\n @returns {Boolean}\n*/\nexport default function(polyA, polyB) {\n\n let iA = -1;\n const nA = polyA.length;\n const nB = polyB.length;\n let bA = polyA[nA - 1];\n\n while (++iA < nA) {\n\n const aA = bA;\n bA = polyA[iA];\n\n let iB = -1;\n let bB = polyB[nB - 1];\n while (++iB < nB) {\n const aB = bB;\n bB = polyB[iB];\n if (segmentsIntersect(aA, bA, aB, bB)) return false;\n }\n }\n\n return polygonContains(polyB, polyA[0]);\n\n}\n","/**\n @function pointDistanceSquared\n @desc Returns the squared euclidean distance between two points.\n @param {Array} p1 The first point, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The second point, which should always be an `[x, y]` formatted Array.\n @returns {Number}\n*/\nexport default (p1, p2) => {\n\n const dx = p2[0] - p1[0],\n dy = p2[1] - p1[1];\n\n return dx * dx + dy * dy;\n\n};\n","import lineIntersection from \"./lineIntersection.js\";\nimport segmentBoxContains from \"./segmentBoxContains.js\";\nimport pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @function polygonRayCast\n @desc Gives the two closest intersection points between a ray cast from a point inside a polygon. The two points should lie on opposite sides of the origin.\n @param {Array} poly The polygon to test against, which should be an `[x, y]` formatted Array.\n @param {Array} origin The origin point of the ray to be cast, which should be an `[x, y]` formatted Array.\n @param {Number} [alpha = 0] The angle in radians of the ray.\n @returns {Array} An array containing two values, the closest point on the left and the closest point on the right. If either point cannot be found, that value will be `null`.\n*/\nexport default function(poly, origin, alpha = 0) {\n\n const eps = 1e-9;\n origin = [origin[0] + eps * Math.cos(alpha), origin[1] + eps * Math.sin(alpha)];\n const [x0, y0] = origin;\n const shiftedOrigin = [x0 + Math.cos(alpha), y0 + Math.sin(alpha)];\n\n let idx = 0;\n if (Math.abs(shiftedOrigin[0] - x0) < eps) idx = 1;\n let i = -1;\n const n = poly.length;\n let b = poly[n - 1];\n let minSqDistLeft = Number.MAX_VALUE;\n let minSqDistRight = Number.MAX_VALUE;\n let closestPointLeft = null;\n let closestPointRight = null;\n while (++i < n) {\n const a = b;\n b = poly[i];\n const p = lineIntersection(origin, shiftedOrigin, a, b);\n if (p && segmentBoxContains(a, b, p)) {\n const sqDist = pointDistanceSquared(origin, p);\n if (p[idx] < origin[idx]) {\n if (sqDist < minSqDistLeft) {\n minSqDistLeft = sqDist;\n closestPointLeft = p;\n }\n }\n else if (p[idx] > origin[idx]) {\n if (sqDist < minSqDistRight) {\n minSqDistRight = sqDist;\n closestPointRight = p;\n }\n }\n }\n }\n\n return [closestPointLeft, closestPointRight];\n\n}\n","/**\n @function pointRotate\n @desc Rotates a point around a given origin.\n @param {Array} p The point to be rotated, which should always be an `[x, y]` formatted Array.\n @param {Number} alpha The angle in radians to rotate.\n @param {Array} [origin = [0, 0]] The origin point of the rotation, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p, alpha, origin = [0, 0]) {\n\n const cosAlpha = Math.cos(alpha),\n sinAlpha = Math.sin(alpha),\n xshifted = p[0] - origin[0],\n yshifted = p[1] - origin[1];\n\n return [\n cosAlpha * xshifted - sinAlpha * yshifted + origin[0],\n sinAlpha * xshifted + cosAlpha * yshifted + origin[1]\n ];\n\n}\n","import pointRotate from \"./pointRotate.js\";\n\n/**\n @function polygonRotate\n @desc Rotates a point around a given origin.\n @param {Array} poly The polygon to be rotated, which should be an Array of `[x, y]` values.\n @param {Number} alpha The angle in radians to rotate.\n @param {Array} [origin = [0, 0]] The origin point of the rotation, which should be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default (poly, alpha, origin = [0, 0]) => poly.map(p => pointRotate(p, alpha, origin));\n","import pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @desc square distance from a point to a segment\n @param {Array} point\n @param {Array} segmentAnchor1\n @param {Array} segmentAnchor2\n @private\n*/\nfunction getSqSegDist(p, p1, p2) {\n\n let x = p1[0],\n y = p1[1];\n\n let dx = p2[0] - x,\n dy = p2[1] - y;\n\n if (dx !== 0 || dy !== 0) {\n\n const t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);\n\n if (t > 1) {\n x = p2[0];\n y = p2[1];\n\n }\n else if (t > 0) {\n x += dx * t;\n y += dy * t;\n }\n\n }\n\n dx = p[0] - x;\n dy = p[1] - y;\n\n return dx * dx + dy * dy;\n\n}\n\n/**\n @desc basic distance-based simplification\n @param {Array} polygon\n @param {Number} sqTolerance\n @private\n*/\nfunction simplifyRadialDist(poly, sqTolerance) {\n\n let point,\n prevPoint = poly[0];\n\n const newPoints = [prevPoint];\n\n for (let i = 1, len = poly.length; i < len; i++) {\n point = poly[i];\n\n if (pointDistanceSquared(point, prevPoint) > sqTolerance) {\n newPoints.push(point);\n prevPoint = point;\n }\n }\n\n if (prevPoint !== point) newPoints.push(point);\n\n return newPoints;\n}\n\n/**\n @param {Array} polygon\n @param {Number} first\n @param {Number} last\n @param {Number} sqTolerance\n @param {Array} simplified\n @private\n*/\nfunction simplifyDPStep(poly, first, last, sqTolerance, simplified) {\n\n let index, maxSqDist = sqTolerance;\n\n for (let i = first + 1; i < last; i++) {\n const sqDist = getSqSegDist(poly[i], poly[first], poly[last]);\n\n if (sqDist > maxSqDist) {\n index = i;\n maxSqDist = sqDist;\n }\n }\n\n if (maxSqDist > sqTolerance) {\n if (index - first > 1) simplifyDPStep(poly, first, index, sqTolerance, simplified);\n simplified.push(poly[index]);\n if (last - index > 1) simplifyDPStep(poly, index, last, sqTolerance, simplified);\n }\n}\n\n/**\n @desc simplification using Ramer-Douglas-Peucker algorithm\n @param {Array} polygon\n @param {Number} sqTolerance\n @private\n*/\nfunction simplifyDouglasPeucker(poly, sqTolerance) {\n const last = poly.length - 1;\n\n const simplified = [poly[0]];\n simplifyDPStep(poly, 0, last, sqTolerance, simplified);\n simplified.push(poly[last]);\n\n return simplified;\n}\n\n/**\n @function largestRect\n @desc Simplifies the points of a polygon using both the Ramer-Douglas-Peucker algorithm and basic distance-based simplification. Adapted to an ES6 module from the excellent [Simplify.js](http://mourner.github.io/simplify-js/).\n @author Vladimir Agafonkin\n @param {Array} poly An Array of points that represent a polygon.\n @param {Number} [tolerance = 1] Affects the amount of simplification (in the same metric as the point coordinates).\n @param {Boolean} [highestQuality = false] Excludes distance-based preprocessing step which leads to highest quality simplification but runs ~10-20 times slower.\n\n*/\nexport default (poly, tolerance = 1, highestQuality = false) => {\n\n if (poly.length <= 2) return poly;\n\n const sqTolerance = tolerance * tolerance;\n\n poly = highestQuality ? poly : simplifyRadialDist(poly, sqTolerance);\n poly = simplifyDouglasPeucker(poly, sqTolerance);\n\n return poly;\n\n};\n","import {extent, merge, range} from \"d3-array\";\nimport {polygonArea, polygonCentroid, polygonContains} from \"d3-polygon\";\n\nimport polygonInside from \"./polygonInside.js\";\nimport polygonRayCast from \"./polygonRayCast.js\";\nimport polygonRotate from \"./polygonRotate.js\";\nimport simplify from \"./simplify.js\";\nimport pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n// Algorithm constants\nconst aspectRatioStep = 0.5; // step size for the aspect ratio\nconst angleStep = 5; // step size for angles (in degrees); has linear impact on running time\n\nconst polyCache = {};\n\n/**\n @typedef {Object} LargestRect\n @desc The returned Object of the largestRect function.\n @property {Number} width The width of the rectangle\n @property {Number} height The height of the rectangle\n @property {Number} cx The x coordinate of the rectangle's center\n @property {Number} cy The y coordinate of the rectangle's center\n @property {Number} angle The rotation angle of the rectangle in degrees. The anchor of rotation is the center point.\n @property {Number} area The area of the largest rectangle.\n @property {Array} points An array of x/y coordinates for each point in the rectangle, useful for rendering paths.\n*/\n\n/**\n @function largestRect\n @author Daniel Smilkov [dsmilkov@gmail.com]\n @desc An angle of zero means that the longer side of the polygon (the width) will be aligned with the x axis. An angle of 90 and/or -90 means that the longer side of the polygon (the width) will be aligned with the y axis. The value can be a number between -90 and 90 specifying the angle of rotation of the polygon, a string which is parsed to a number, or an array of numbers specifying the possible rotations of the polygon.\n @param {Array} poly An Array of points that represent a polygon.\n @param {Object} [options] An Object that allows for overriding various parameters of the algorithm.\n @param {Number|String|Array} [options.angle = d3.range(-90, 95, 5)] The allowed rotations of the final rectangle.\n @param {Number|String|Array} [options.aspectRatio] The ratio between the width and height of the rectangle. The value can be a number, a string which is parsed to a number, or an array of numbers specifying the possible aspect ratios of the final rectangle.\n @param {Number} [options.maxAspectRatio = 15] The maximum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided.\n @param {Number} [options.minAspectRatio = 1] The minimum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided.\n @param {Number} [options.nTries = 20] The number of randomly drawn points inside the polygon which the algorithm explores as possible center points of the maximal rectangle.\n @param {Number} [options.minHeight = 0] The minimum height of the rectangle.\n @param {Number} [options.minWidth = 0] The minimum width of the rectangle.\n @param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.\n @param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.\n @param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.\n @return {LargestRect}\n*/\nexport default function(poly, options = {}) {\n\n if (poly.length < 3) {\n if (options.verbose) console.error(\"polygon has to have at least 3 points\", poly);\n return null;\n }\n\n // For visualization debugging purposes\n const events = [];\n\n // User's input normalization\n options = Object.assign({\n angle: range(-90, 90 + angleStep, angleStep),\n cache: true,\n maxAspectRatio: 15,\n minAspectRatio: 1,\n minHeight: 0,\n minWidth: 0,\n nTries: 20,\n tolerance: 0.02,\n verbose: false\n }, options);\n\n const angles = options.angle instanceof Array ? options.angle\n : typeof options.angle === \"number\" ? [options.angle]\n : typeof options.angle === \"string\" && !isNaN(options.angle) ? [Number(options.angle)]\n : [];\n\n const aspectRatios = options.aspectRatio instanceof Array ? options.aspectRatio\n : typeof options.aspectRatio === \"number\" ? [options.aspectRatio]\n : typeof options.aspectRatio === \"string\" && !isNaN(options.aspectRatio) ? [Number(options.aspectRatio)]\n : [];\n\n const origins = options.origin && options.origin instanceof Array\n ? options.origin[0] instanceof Array ? options.origin\n : [options.origin] : [];\n\n let cacheString;\n if (options.cache) {\n cacheString = merge(poly).join(\",\");\n cacheString += `-${options.minAspectRatio}`;\n cacheString += `-${options.maxAspectRatio}`;\n cacheString += `-${options.minHeight}`;\n cacheString += `-${options.minWidth}`;\n cacheString += `-${angles.join(\",\")}`;\n cacheString += `-${origins.join(\",\")}`;\n if (polyCache[cacheString]) return polyCache[cacheString];\n }\n\n const area = Math.abs(polygonArea(poly)); // take absolute value of the signed area\n if (area === 0) {\n if (options.verbose) console.error(\"polygon has 0 area\", poly);\n return null;\n }\n // get the width of the bounding box of the original polygon to determine tolerance\n let [minx, maxx] = extent(poly, d => d[0]);\n let [miny, maxy] = extent(poly, d => d[1]);\n\n // simplify polygon\n const tolerance = Math.min(maxx - minx, maxy - miny) * options.tolerance;\n\n if (tolerance > 0) poly = simplify(poly, tolerance);\n if (options.events) events.push({type: \"simplify\", poly});\n\n // get the width of the bounding box of the simplified polygon\n [minx, maxx] = extent(poly, d => d[0]);\n [miny, maxy] = extent(poly, d => d[1]);\n const [boxWidth, boxHeight] = [maxx - minx, maxy - miny];\n\n // discretize the binary search for optimal width to a resolution of this times the polygon width\n const widthStep = Math.min(boxWidth, boxHeight) / 50;\n\n // populate possible center points with random points inside the polygon\n if (!origins.length) {\n // get the centroid of the polygon\n const centroid = polygonCentroid(poly);\n if (!isFinite(centroid[0])) {\n if (options.verbose) console.error(\"cannot find centroid\", poly);\n return null;\n }\n if (polygonContains(poly, centroid)) origins.push(centroid);\n\n let nTries = options.nTries;\n // get few more points inside the polygon\n while (nTries) {\n const rndX = Math.random() * boxWidth + minx;\n const rndY = Math.random() * boxHeight + miny;\n const rndPoint = [rndX, rndY];\n if (polygonContains(poly, rndPoint)) {\n origins.push(rndPoint);\n }\n nTries--;\n }\n }\n if (options.events) events.push({type: \"origins\", points: origins});\n let maxArea = 0;\n let maxRect = null;\n\n for (let ai = 0; ai < angles.length; ai++) {\n const angle = angles[ai];\n const angleRad = -angle * Math.PI / 180;\n if (options.events) events.push({type: \"angle\", angle});\n for (let i = 0; i < origins.length; i++) {\n const origOrigin = origins[i];\n // generate improved origins\n const [p1W, p2W] = polygonRayCast(poly, origOrigin, angleRad);\n const [p1H, p2H] = polygonRayCast(poly, origOrigin, angleRad + Math.PI / 2);\n const modifOrigins = [];\n if (p1W && p2W) modifOrigins.push([(p1W[0] + p2W[0]) / 2, (p1W[1] + p2W[1]) / 2]); // average along with width axis\n if (p1H && p2H) modifOrigins.push([(p1H[0] + p2H[0]) / 2, (p1H[1] + p2H[1]) / 2]); // average along with height axis\n\n if (options.events) events.push({type: \"modifOrigin\", idx: i, p1W, p2W, p1H, p2H, modifOrigins});\n\n for (let i = 0; i < modifOrigins.length; i++) {\n\n const origin = modifOrigins[i];\n\n if (options.events) events.push({type: \"origin\", cx: origin[0], cy: origin[1]});\n\n const [p1W, p2W] = polygonRayCast(poly, origin, angleRad);\n if (p1W === null || p2W === null) continue;\n const minSqDistW = Math.min(pointDistanceSquared(origin, p1W), pointDistanceSquared(origin, p2W));\n const maxWidth = 2 * Math.sqrt(minSqDistW);\n\n const [p1H, p2H] = polygonRayCast(poly, origin, angleRad + Math.PI / 2);\n if (p1H === null || p2H === null) continue;\n const minSqDistH = Math.min(pointDistanceSquared(origin, p1H), pointDistanceSquared(origin, p2H));\n const maxHeight = 2 * Math.sqrt(minSqDistH);\n\n if (maxWidth * maxHeight < maxArea) continue;\n\n let aRatios = aspectRatios;\n if (!aRatios.length) {\n const minAspectRatio = Math.max(options.minAspectRatio, options.minWidth / maxHeight, maxArea / (maxHeight * maxHeight));\n const maxAspectRatio = Math.min(options.maxAspectRatio, maxWidth / options.minHeight, maxWidth * maxWidth / maxArea);\n aRatios = range(minAspectRatio, maxAspectRatio + aspectRatioStep, aspectRatioStep);\n }\n\n for (let a = 0; a < aRatios.length; a++) {\n\n const aRatio = aRatios[a];\n\n // do a binary search to find the max width that works\n let left = Math.max(options.minWidth, Math.sqrt(maxArea * aRatio));\n let right = Math.min(maxWidth, maxHeight * aRatio);\n if (right * maxHeight < maxArea) continue;\n\n if (options.events && right - left >= widthStep) events.push({type: \"aRatio\", aRatio});\n\n while (right - left >= widthStep) {\n const width = (left + right) / 2;\n const height = width / aRatio;\n const [cx, cy] = origin;\n let rectPoly = [\n [cx - width / 2, cy - height / 2],\n [cx + width / 2, cy - height / 2],\n [cx + width / 2, cy + height / 2],\n [cx - width / 2, cy + height / 2]\n ];\n rectPoly = polygonRotate(rectPoly, angleRad, origin);\n const insidePoly = polygonInside(rectPoly, poly);\n if (insidePoly) {\n // we know that the area is already greater than the maxArea found so far\n maxArea = width * height;\n rectPoly.push(rectPoly[0]);\n maxRect = {area: maxArea, cx, cy, width, height, angle: -angle, points: rectPoly};\n left = width; // increase the width in the binary search\n }\n else {\n right = width; // decrease the width in the binary search\n }\n if (options.events) events.push({type: \"rectangle\", areaFraction: width * height / area, cx, cy, width, height, angle, insidePoly});\n\n }\n\n }\n\n }\n\n }\n\n }\n\n if (options.cache) {\n polyCache[cacheString] = maxRect;\n }\n\n return options.events ? Object.assign(maxRect || {}, {events}) : maxRect;\n\n}\n","/**\n @function path2polygon\n @desc Transforms a path string into an Array of points.\n @param {String} path An SVG string path, commonly the \"d\" property of a <path> element.\n @param {Number} [segmentLength = 50] The length of line segments when converting curves line segments. Higher values lower computation time, but will result in curves that are more rigid.\n @returns {Array}\n*/\nexport default (path, segmentLength = 50) => {\n\n if (typeof document === \"undefined\") return [];\n\n const svgPath = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n svgPath.setAttribute(\"d\", path);\n\n const len = svgPath.getTotalLength();\n const NUM_POINTS = len / segmentLength < 10 ? len / 10 : len / segmentLength;\n\n const points = [];\n for (let i = 0; i < NUM_POINTS; i++) {\n const pt = svgPath.getPointAtLength(i * len / (NUM_POINTS-1));\n points.push([pt.x, pt.y]);\n }\n \n return points;\n\n};\n","import pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @function pointDistance\n @desc Calculates the pixel distance between two points.\n @param {Array} p1 The first point, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The second point, which should always be an `[x, y]` formatted Array.\n @returns {Number}\n*/\nexport default (p1, p2) => Math.sqrt(pointDistanceSquared(p1, p2));\n","const pi = Math.PI;\n\n/**\n @function shapeEdgePoint\n @desc Calculates the x/y position of a point at the edge of a shape, from the center of the shape, given a specified pixel distance and radian angle.\n @param {Number} angle The angle, in radians, of the offset point.\n @param {Number} distance The pixel distance away from the origin.\n @returns {String} [shape = \"circle\"] The type of shape, which can be either \"circle\" or \"square\".\n*/\nexport default (angle, distance, shape = \"circle\") => {\n\n if (angle < 0) angle = pi * 2 + angle;\n\n if (shape === \"square\") {\n\n const diagonal = 45 * (pi / 180);\n let x = 0, y = 0;\n\n if (angle < pi / 2) {\n const tan = Math.tan(angle);\n x += angle < diagonal ? distance : distance / tan;\n y += angle < diagonal ? tan * distance : distance;\n }\n else if (angle <= pi) {\n const tan = Math.tan(pi - angle);\n x -= angle < pi - diagonal ? distance / tan : distance;\n y += angle < pi - diagonal ? distance : tan * distance;\n }\n else if (angle < diagonal + pi) {\n x -= distance;\n y -= Math.tan(angle - pi) * distance;\n }\n else if (angle < 3 * pi / 2) {\n x -= distance / Math.tan(angle - pi);\n y -= distance;\n }\n else if (angle < 2 * pi - diagonal) {\n x += distance / Math.tan(2 * pi - angle);\n y -= distance;\n }\n else {\n x += distance;\n y -= Math.tan(2 * pi - angle) * distance;\n }\n\n return [x, y];\n\n }\n else if (shape === \"circle\") {\n return [distance * Math.cos(angle), distance * Math.sin(angle)];\n }\n else return null;\n\n};\n"],"names":["numericSort","array","slice","sort","a","b","uniqueCountSorted","input","lastSeenValue","uniqueValueCount","i","length","makeMatrix","columns","rows","matrix","column","j","push","ssq","sums","sumsOfSquares","sji","muji","fillMatrixColumn","iMin","iMax","cluster","backtrackMatrix","Math","floor","jlow","max","jhigh","min","sjlowi","ssqjlow","ssqj","fillMatrices","data","nValues","shift","shiftedValue","nClusters","Error","sorted","uniqueCount","clusterRight","clusters","clusterLeft","n","arr","Array","undefined","reduce","prev","curr","abs","p1","q1","p2","q2","eps","dx1","dx2","dy1","dy2","denom","cross1","cross2","px","py","s1","s2","p","lineIntersection","segmentBoxContains","polyA","polyB","iA","nA","nB","bA","aA","iB","bB","aB","segmentsIntersect","polygonContains","dx","dy","poly","origin","alpha","cos","sin","x0","y0","shiftedOrigin","idx","minSqDistLeft","Number","MAX_VALUE","minSqDistRight","closestPointLeft","closestPointRight","sqDist","pointDistanceSquared","cosAlpha","sinAlpha","xshifted","yshifted","map","pointRotate","getSqSegDist","x","y","t","simplifyRadialDist","sqTolerance","point","prevPoint","newPoints","len","simplifyDPStep","first","last","simplified","index","maxSqDist","simplifyDouglasPeucker","tolerance","highestQuality","aspectRatioStep","angleStep","polyCache","options","verbose","console","error","events","Object","assign","angle","range","cache","maxAspectRatio","minAspectRatio","minHeight","minWidth","nTries","angles","isNaN","aspectRatios","aspectRatio","origins","cacheString","merge","join","area","polygonArea","minx","maxx","extent","d","miny","maxy","simplify","type","boxWidth","boxHeight","widthStep","centroid","polygonCentroid","isFinite","rndX","random","rndY","rndPoint","points","maxArea","maxRect","ai","angleRad","PI","origOrigin","p1W","p2W","polygonRayCast","p1H","p2H","modifOrigins","cx","cy","minSqDistW","maxWidth","sqrt","minSqDistH","maxHeight","aRatios","aRatio","left","right","width","height","rectPoly","polygonRotate","insidePoly","polygonInside","areaFraction","path","segmentLength","document","svgPath","createElementNS","setAttribute","getTotalLength","NUM_POINTS","pt","getPointAtLength","pi","distance","shape","diagonal","tan"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;EAcA,GACA,SAASA,YAAY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AAA,QAAAA;EAClC;UAEA,OAAO;EAAC1G,YAAAA,CAAAA;EAAGC,YAAAA;EAAE,SAAA;OAGV,MAAA,IAAI0G,UAAU,QAAU,EAAA;UAC3B,OAAO;cAACD,QAAWhM,GAAAA,IAAAA,CAAKiE,GAAG,CAACiD,KAAAA,CAAAA;cAAQ8E,QAAWhM,GAAAA,IAAAA,CAAKkE,GAAG,CAACgD,KAAAA;EAAO,SAAA;EACjE,KAAA,MACK,OAAO,IAAA;EAEd,CAAA;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"d3plus-math.js","sources":["../src/ckmeans.js","../src/closest.js","../src/lineIntersection.js","../src/segmentBoxContains.js","../src/segmentsIntersect.js","../src/polygonInside.js","../src/pointDistanceSquared.js","../src/polygonRayCast.js","../src/pointRotate.js","../src/polygonRotate.js","../src/simplify.js","../src/largestRect.js","../src/path2polygon.js","../src/pointDistance.js","../src/shapeEdgePoint.js"],"sourcesContent":["/**\n @desc Sort an array of numbers by their numeric value, ensuring that the array is not changed in place.\n\nThis is necessary because the default behavior of .sort in JavaScript is to sort arrays as string values\n\n[1, 10, 12, 102, 20].sort()\n// output\n[1, 10, 102, 12, 20]\n\n @param {Array<number>} array input array\n @return {Array<number>} sorted array\n @private\n @example\nnumericSort([3, 2, 1]) // => [1, 2, 3]\n*/\nfunction numericSort(array) {\n return array.slice().sort((a, b) => a - b);\n}\n\n/**\n For a sorted input, counting the number of unique values is possible in constant time and constant memory. This is a simple implementation of the algorithm.\n\n Values are compared with `===`, so objects and non-primitive objects are not handled in any special way.\n @private\n @param {Array} input an array of primitive values.\n @returns {number} count of unique values\n @example\nuniqueCountSorted([1, 2, 3]); // => 3\nuniqueCountSorted([1, 1, 1]); // => 1\n*/\nfunction uniqueCountSorted(input) {\n let lastSeenValue, uniqueValueCount = 0;\n for (let i = 0; i < input.length; i++) {\n if (i === 0 || input[i] !== lastSeenValue) {\n lastSeenValue = input[i];\n uniqueValueCount++;\n }\n }\n return uniqueValueCount;\n}\n\n/**\n Create a new column x row matrix.\n @private\n @param {number} columns\n @param {number} rows\n @return {Array<Array<number>>} matrix\n @example\nmakeMatrix(10, 10);\n*/\nfunction makeMatrix(columns, rows) {\n const matrix = [];\n for (let i = 0; i < columns; i++) {\n const column = [];\n for (let j = 0; j < rows; j++) column.push(0);\n matrix.push(column);\n }\n return matrix;\n}\n\n/**\n Generates incrementally computed values based on the sums and sums of squares for the data array\n @private\n @param {number} j\n @param {number} i\n @param {Array<number>} sums\n @param {Array<number>} sumsOfSquares\n @return {number}\n @example\nssq(0, 1, [-1, 0, 2], [1, 1, 5]);\n*/\nfunction ssq(j, i, sums, sumsOfSquares) {\n let sji; // s(j, i)\n\n if (j > 0) {\n const muji = (sums[i] - sums[j - 1]) / (i - j + 1); // mu(j, i)\n sji = sumsOfSquares[i] - sumsOfSquares[j - 1] - (i - j + 1) * muji * muji;\n }\n else sji = sumsOfSquares[i] - sums[i] * sums[i] / (i + 1);\n\n if (sji < 0) return 0;\n return sji;\n}\n\n/**\n Function that recursively divides and conquers computations for cluster j\n @private\n @param {number} iMin Minimum index in cluster to be computed\n @param {number} iMax Maximum index in cluster to be computed\n @param {number} cluster Index of the cluster currently being computed\n @param {Array<Array<number>>} matrix\n @param {Array<Array<number>>} backtrackMatrix\n @param {Array<number>} sums\n @param {Array<number>} sumsOfSquares\n*/\nfunction fillMatrixColumn(iMin, iMax, cluster, matrix, backtrackMatrix, sums, sumsOfSquares) {\n if (iMin > iMax) return;\n\n // Start at midpoint between iMin and iMax\n const i = Math.floor((iMin + iMax) / 2);\n\n matrix[cluster][i] = matrix[cluster - 1][i - 1];\n backtrackMatrix[cluster][i] = i;\n\n let jlow = cluster; // the lower end for j\n if (iMin > cluster) jlow = Math.max(jlow, backtrackMatrix[cluster][iMin - 1] || 0);\n jlow = Math.max(jlow, backtrackMatrix[cluster - 1][i] || 0);\n\n let jhigh = i - 1; // the upper end for j\n if (iMax < matrix.length - 1) jhigh = Math.min(jhigh, backtrackMatrix[cluster][iMax + 1] || 0);\n\n for (let j = jhigh; j >= jlow; --j) {\n const sji = ssq(j, i, sums, sumsOfSquares);\n\n if (sji + matrix[cluster - 1][jlow - 1] >= matrix[cluster][i]) break;\n\n // Examine the lower bound of the cluster border\n const sjlowi = ssq(jlow, i, sums, sumsOfSquares);\n\n const ssqjlow = sjlowi + matrix[cluster - 1][jlow - 1];\n\n if (ssqjlow < matrix[cluster][i]) {\n // Shrink the lower bound\n matrix[cluster][i] = ssqjlow;\n backtrackMatrix[cluster][i] = jlow;\n }\n jlow++;\n\n const ssqj = sji + matrix[cluster - 1][j - 1];\n if (ssqj < matrix[cluster][i]) {\n matrix[cluster][i] = ssqj;\n backtrackMatrix[cluster][i] = j;\n }\n }\n\n fillMatrixColumn(iMin, i - 1, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n fillMatrixColumn(i + 1, iMax, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n\n}\n\n/**\n Initializes the main matrices used in Ckmeans and kicks off the divide and conquer cluster computation strategy\n @private\n @param {Array<number>} data sorted array of values\n @param {Array<Array<number>>} matrix\n @param {Array<Array<number>>} backtrackMatrix\n*/\nfunction fillMatrices(data, matrix, backtrackMatrix) {\n const nValues = matrix[0] ? matrix[0].length : 0;\n\n // Shift values by the median to improve numeric stability\n const shift = data[Math.floor(nValues / 2)];\n\n // Cumulative sum and cumulative sum of squares for all values in data array\n const sums = [];\n const sumsOfSquares = [];\n\n // Initialize first column in matrix & backtrackMatrix\n for (let i = 0, shiftedValue = void 0; i < nValues; ++i) {\n shiftedValue = data[i] - shift;\n if (i === 0) {\n sums.push(shiftedValue);\n sumsOfSquares.push(shiftedValue * shiftedValue);\n }\n else {\n sums.push(sums[i - 1] + shiftedValue);\n sumsOfSquares.push(sumsOfSquares[i - 1] + shiftedValue * shiftedValue);\n }\n\n // Initialize for cluster = 0\n matrix[0][i] = ssq(0, i, sums, sumsOfSquares);\n backtrackMatrix[0][i] = 0;\n }\n\n // Initialize the rest of the columns\n for (let cluster = 1; cluster < matrix.length; ++cluster) {\n let iMin = nValues - 1;\n if (cluster < matrix.length - 1) iMin = cluster;\n fillMatrixColumn(iMin, nValues - 1, cluster, matrix, backtrackMatrix, sums, sumsOfSquares);\n }\n}\n\n/**\n @module ckmeans\n @desc Ported to ES6 from the excellent [simple-statistics](https://github.com/simple-statistics/simple-statistics) packages.\n\nCkmeans clustering is an improvement on heuristic-based clustering approaches like Jenks. The algorithm was developed in [Haizhou Wang and Mingzhou Song](http://journal.r-project.org/archive/2011-2/RJournal_2011-2_Wang+Song.pdf) as a [dynamic programming](https://en.wikipedia.org/wiki/Dynamic_programming) approach to the problem of clustering numeric data into groups with the least within-group sum-of-squared-deviations.\n\nMinimizing the difference within groups - what Wang & Song refer to as `withinss`, or within sum-of-squares, means that groups are optimally homogenous within and the data is split into representative groups. This is very useful for visualization, where you may want to represent a continuous variable in discrete color or style groups. This function can provide groups that emphasize differences between data.\n\nBeing a dynamic approach, this algorithm is based on two matrices that store incrementally-computed values for squared deviations and backtracking indexes.\n\nThis implementation is based on Ckmeans 3.4.6, which introduced a new divide and conquer approach that improved runtime from O(kn^2) to O(kn log(n)).\n\nUnlike the [original implementation](https://cran.r-project.org/web/packages/Ckmeans.1d.dp/index.html), this implementation does not include any code to automatically determine the optimal number of clusters: this information needs to be explicitly provided.\n\n### References\n_Ckmeans.1d.dp: Optimal k-means Clustering in One Dimension by Dynamic\nProgramming_ Haizhou Wang and Mingzhou Song ISSN 2073-4859 from The R Journal Vol. 3/2, December 2011\n @param {Array<number>} data input data, as an array of number values\n @param {number} nClusters number of desired classes. This cannot be greater than the number of values in the data array.\n @returns {Array<Array<number>>} clustered input\n @private\n @example\nckmeans([-1, 2, -1, 2, 4, 5, 6, -1, 2, -1], 3);\n// The input, clustered into groups of similar numbers.\n//= [[-1, -1, -1, -1], [2, 2, 2], [4, 5, 6]]);\n*/\nexport default function(data, nClusters) {\n\n if (nClusters > data.length) {\n throw new Error(\"Cannot generate more classes than there are data values\");\n }\n\n const sorted = numericSort(data);\n\n // we'll use this as the maximum number of clusters\n const uniqueCount = uniqueCountSorted(sorted);\n\n // if all of the input values are identical, there's one cluster with all of the input in it.\n if (uniqueCount === 1) {\n return [sorted];\n }\n\n const backtrackMatrix = makeMatrix(nClusters, sorted.length),\n matrix = makeMatrix(nClusters, sorted.length);\n\n // This is a dynamic programming way to solve the problem of minimizing within-cluster sum of squares. It's similar to linear regression in this way, and this calculation incrementally computes the sum of squares that are later read.\n fillMatrices(sorted, matrix, backtrackMatrix);\n\n // The real work of Ckmeans clustering happens in the matrix generation: the generated matrices encode all possible clustering combinations, and once they're generated we can solve for the best clustering groups very quickly.\n let clusterRight = backtrackMatrix[0] ? backtrackMatrix[0].length - 1 : 0;\n const clusters = [];\n\n // Backtrack the clusters from the dynamic programming matrix. This starts at the bottom-right corner of the matrix (if the top-left is 0, 0), and moves the cluster target with the loop.\n for (let cluster = backtrackMatrix.length - 1; cluster >= 0; cluster--) {\n\n const clusterLeft = backtrackMatrix[cluster][clusterRight];\n\n // fill the cluster from the sorted input by taking a slice of the array. the backtrack matrix makes this easy - it stores the indexes where the cluster should start and end.\n clusters[cluster] = sorted.slice(clusterLeft, clusterRight + 1);\n\n if (cluster > 0) clusterRight = clusterLeft - 1;\n\n }\n\n return clusters;\n\n}\n","/**\n @function closest\n @desc Finds the closest numeric value in an array.\n @param {Number} n The number value to use when searching the array.\n @param {Array} arr The array of values to test against.\n*/\nexport default function(n, arr = []) {\n if (!arr || !(arr instanceof Array) || !arr.length) return undefined;\n return arr.reduce((prev, curr) => Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev);\n}\n","/**\n @function lineIntersection\n @desc Finds the intersection point (if there is one) of the lines p1q1 and p2q2.\n @param {Array} p1 The first point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q1 The second point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The first point of the second line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q2 The second point of the second line segment, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p1, q1, p2, q2) {\n\n // allow for some margins due to numerical errors\n const eps = 1e-9;\n\n // find the intersection point between the two infinite lines\n const dx1 = p1[0] - q1[0],\n dx2 = p2[0] - q2[0],\n dy1 = p1[1] - q1[1],\n dy2 = p2[1] - q2[1];\n\n const denom = dx1 * dy2 - dy1 * dx2;\n\n if (Math.abs(denom) < eps) return null;\n\n const cross1 = p1[0] * q1[1] - p1[1] * q1[0],\n cross2 = p2[0] * q2[1] - p2[1] * q2[0];\n\n const px = (cross1 * dx2 - cross2 * dx1) / denom,\n py = (cross1 * dy2 - cross2 * dy1) / denom;\n\n return [px, py];\n\n}\n","/**\n @function segmentBoxContains\n @desc Checks whether a point is inside the bounding box of a line segment.\n @param {Array} s1 The first point of the line segment to be used for the bounding box, which should always be an `[x, y]` formatted Array.\n @param {Array} s2 The second point of the line segment to be used for the bounding box, which should always be an `[x, y]` formatted Array.\n @param {Array} p The point to be checked, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(s1, s2, p) {\n\n const eps = 1e-9, [px, py] = p;\n\n return !(px < Math.min(s1[0], s2[0]) - eps || px > Math.max(s1[0], s2[0]) + eps ||\n py < Math.min(s1[1], s2[1]) - eps || py > Math.max(s1[1], s2[1]) + eps);\n\n}\n","import lineIntersection from \"./lineIntersection.js\";\nimport segmentBoxContains from \"./segmentBoxContains.js\";\n\n/**\n @function segmentsIntersect\n @desc Checks whether the line segments p1q1 && p2q2 intersect.\n @param {Array} p1 The first point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q1 The second point of the first line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The first point of the second line segment, which should always be an `[x, y]` formatted Array.\n @param {Array} q2 The second point of the second line segment, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p1, q1, p2, q2) {\n\n const p = lineIntersection(p1, q1, p2, q2);\n if (!p) return false;\n return segmentBoxContains(p1, q1, p) && segmentBoxContains(p2, q2, p);\n\n}\n","import {polygonContains} from \"d3-polygon\";\n\nimport segmentsIntersect from \"./segmentsIntersect.js\";\n\n/**\n @function polygonInside\n @desc Checks if one polygon is inside another polygon.\n @param {Array} polyA An Array of `[x, y]` points to be used as the inner polygon, checking if it is inside polyA.\n @param {Array} polyB An Array of `[x, y]` points to be used as the containing polygon.\n @returns {Boolean}\n*/\nexport default function(polyA, polyB) {\n\n let iA = -1;\n const nA = polyA.length;\n const nB = polyB.length;\n let bA = polyA[nA - 1];\n\n while (++iA < nA) {\n\n const aA = bA;\n bA = polyA[iA];\n\n let iB = -1;\n let bB = polyB[nB - 1];\n while (++iB < nB) {\n const aB = bB;\n bB = polyB[iB];\n if (segmentsIntersect(aA, bA, aB, bB)) return false;\n }\n }\n\n return polygonContains(polyB, polyA[0]);\n\n}\n","/**\n @function pointDistanceSquared\n @desc Returns the squared euclidean distance between two points.\n @param {Array} p1 The first point, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The second point, which should always be an `[x, y]` formatted Array.\n @returns {Number}\n*/\nexport default (p1, p2) => {\n\n const dx = p2[0] - p1[0],\n dy = p2[1] - p1[1];\n\n return dx * dx + dy * dy;\n\n};\n","import lineIntersection from \"./lineIntersection.js\";\nimport segmentBoxContains from \"./segmentBoxContains.js\";\nimport pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @function polygonRayCast\n @desc Gives the two closest intersection points between a ray cast from a point inside a polygon. The two points should lie on opposite sides of the origin.\n @param {Array} poly The polygon to test against, which should be an `[x, y]` formatted Array.\n @param {Array} origin The origin point of the ray to be cast, which should be an `[x, y]` formatted Array.\n @param {Number} [alpha = 0] The angle in radians of the ray.\n @returns {Array} An array containing two values, the closest point on the left and the closest point on the right. If either point cannot be found, that value will be `null`.\n*/\nexport default function(poly, origin, alpha = 0) {\n\n const eps = 1e-9;\n origin = [origin[0] + eps * Math.cos(alpha), origin[1] + eps * Math.sin(alpha)];\n const [x0, y0] = origin;\n const shiftedOrigin = [x0 + Math.cos(alpha), y0 + Math.sin(alpha)];\n\n let idx = 0;\n if (Math.abs(shiftedOrigin[0] - x0) < eps) idx = 1;\n let i = -1;\n const n = poly.length;\n let b = poly[n - 1];\n let minSqDistLeft = Number.MAX_VALUE;\n let minSqDistRight = Number.MAX_VALUE;\n let closestPointLeft = null;\n let closestPointRight = null;\n while (++i < n) {\n const a = b;\n b = poly[i];\n const p = lineIntersection(origin, shiftedOrigin, a, b);\n if (p && segmentBoxContains(a, b, p)) {\n const sqDist = pointDistanceSquared(origin, p);\n if (p[idx] < origin[idx]) {\n if (sqDist < minSqDistLeft) {\n minSqDistLeft = sqDist;\n closestPointLeft = p;\n }\n }\n else if (p[idx] > origin[idx]) {\n if (sqDist < minSqDistRight) {\n minSqDistRight = sqDist;\n closestPointRight = p;\n }\n }\n }\n }\n\n return [closestPointLeft, closestPointRight];\n\n}\n","/**\n @function pointRotate\n @desc Rotates a point around a given origin.\n @param {Array} p The point to be rotated, which should always be an `[x, y]` formatted Array.\n @param {Number} alpha The angle in radians to rotate.\n @param {Array} [origin = [0, 0]] The origin point of the rotation, which should always be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default function(p, alpha, origin = [0, 0]) {\n\n const cosAlpha = Math.cos(alpha),\n sinAlpha = Math.sin(alpha),\n xshifted = p[0] - origin[0],\n yshifted = p[1] - origin[1];\n\n return [\n cosAlpha * xshifted - sinAlpha * yshifted + origin[0],\n sinAlpha * xshifted + cosAlpha * yshifted + origin[1]\n ];\n\n}\n","import pointRotate from \"./pointRotate.js\";\n\n/**\n @function polygonRotate\n @desc Rotates a point around a given origin.\n @param {Array} poly The polygon to be rotated, which should be an Array of `[x, y]` values.\n @param {Number} alpha The angle in radians to rotate.\n @param {Array} [origin = [0, 0]] The origin point of the rotation, which should be an `[x, y]` formatted Array.\n @returns {Boolean}\n*/\nexport default (poly, alpha, origin = [0, 0]) => poly.map(p => pointRotate(p, alpha, origin));\n","import pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @desc square distance from a point to a segment\n @param {Array} point\n @param {Array} segmentAnchor1\n @param {Array} segmentAnchor2\n @private\n*/\nfunction getSqSegDist(p, p1, p2) {\n\n let x = p1[0],\n y = p1[1];\n\n let dx = p2[0] - x,\n dy = p2[1] - y;\n\n if (dx !== 0 || dy !== 0) {\n\n const t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);\n\n if (t > 1) {\n x = p2[0];\n y = p2[1];\n\n }\n else if (t > 0) {\n x += dx * t;\n y += dy * t;\n }\n\n }\n\n dx = p[0] - x;\n dy = p[1] - y;\n\n return dx * dx + dy * dy;\n\n}\n\n/**\n @desc basic distance-based simplification\n @param {Array} polygon\n @param {Number} sqTolerance\n @private\n*/\nfunction simplifyRadialDist(poly, sqTolerance) {\n\n let point,\n prevPoint = poly[0];\n\n const newPoints = [prevPoint];\n\n for (let i = 1, len = poly.length; i < len; i++) {\n point = poly[i];\n\n if (pointDistanceSquared(point, prevPoint) > sqTolerance) {\n newPoints.push(point);\n prevPoint = point;\n }\n }\n\n if (prevPoint !== point) newPoints.push(point);\n\n return newPoints;\n}\n\n/**\n @param {Array} polygon\n @param {Number} first\n @param {Number} last\n @param {Number} sqTolerance\n @param {Array} simplified\n @private\n*/\nfunction simplifyDPStep(poly, first, last, sqTolerance, simplified) {\n\n let index, maxSqDist = sqTolerance;\n\n for (let i = first + 1; i < last; i++) {\n const sqDist = getSqSegDist(poly[i], poly[first], poly[last]);\n\n if (sqDist > maxSqDist) {\n index = i;\n maxSqDist = sqDist;\n }\n }\n\n if (maxSqDist > sqTolerance) {\n if (index - first > 1) simplifyDPStep(poly, first, index, sqTolerance, simplified);\n simplified.push(poly[index]);\n if (last - index > 1) simplifyDPStep(poly, index, last, sqTolerance, simplified);\n }\n}\n\n/**\n @desc simplification using Ramer-Douglas-Peucker algorithm\n @param {Array} polygon\n @param {Number} sqTolerance\n @private\n*/\nfunction simplifyDouglasPeucker(poly, sqTolerance) {\n const last = poly.length - 1;\n\n const simplified = [poly[0]];\n simplifyDPStep(poly, 0, last, sqTolerance, simplified);\n simplified.push(poly[last]);\n\n return simplified;\n}\n\n/**\n @function largestRect\n @desc Simplifies the points of a polygon using both the Ramer-Douglas-Peucker algorithm and basic distance-based simplification. Adapted to an ES6 module from the excellent [Simplify.js](http://mourner.github.io/simplify-js/).\n @author Vladimir Agafonkin\n @param {Array} poly An Array of points that represent a polygon.\n @param {Number} [tolerance = 1] Affects the amount of simplification (in the same metric as the point coordinates).\n @param {Boolean} [highestQuality = false] Excludes distance-based preprocessing step which leads to highest quality simplification but runs ~10-20 times slower.\n\n*/\nexport default (poly, tolerance = 1, highestQuality = false) => {\n\n if (poly.length <= 2) return poly;\n\n const sqTolerance = tolerance * tolerance;\n\n poly = highestQuality ? poly : simplifyRadialDist(poly, sqTolerance);\n poly = simplifyDouglasPeucker(poly, sqTolerance);\n\n return poly;\n\n};\n","import {extent, merge, range} from \"d3-array\";\nimport {polygonArea, polygonCentroid, polygonContains} from \"d3-polygon\";\n\nimport polygonInside from \"./polygonInside.js\";\nimport polygonRayCast from \"./polygonRayCast.js\";\nimport polygonRotate from \"./polygonRotate.js\";\nimport simplify from \"./simplify.js\";\nimport pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n// Algorithm constants\nconst aspectRatioStep = 0.5; // step size for the aspect ratio\nconst angleStep = 5; // step size for angles (in degrees); has linear impact on running time\n\nconst polyCache = {};\n\n/**\n @typedef {Object} largestRect\n @desc The returned Object of the largestRect function.\n @property {Number} width The width of the rectangle\n @property {Number} height The height of the rectangle\n @property {Number} cx The x coordinate of the rectangle's center\n @property {Number} cy The y coordinate of the rectangle's center\n @property {Number} angle The rotation angle of the rectangle in degrees. The anchor of rotation is the center point.\n @property {Number} area The area of the largest rectangle.\n @property {Array} points An array of x/y coordinates for each point in the rectangle, useful for rendering paths.\n*/\n\n/**\n @function largestRect\n @author Daniel Smilkov [dsmilkov@gmail.com]\n @desc An angle of zero means that the longer side of the polygon (the width) will be aligned with the x axis. An angle of 90 and/or -90 means that the longer side of the polygon (the width) will be aligned with the y axis. The value can be a number between -90 and 90 specifying the angle of rotation of the polygon, a string which is parsed to a number, or an array of numbers specifying the possible rotations of the polygon.\n @param {Array} poly An Array of points that represent a polygon.\n @param {Object} [options] An Object that allows for overriding various parameters of the algorithm.\n @param {Number|String|Array} [options.angle = d3.range(-90, 95, 5)] The allowed rotations of the final rectangle.\n @param {Number|String|Array} [options.aspectRatio] The ratio between the width and height of the rectangle. The value can be a number, a string which is parsed to a number, or an array of numbers specifying the possible aspect ratios of the final rectangle.\n @param {Number} [options.maxAspectRatio = 15] The maximum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided.\n @param {Number} [options.minAspectRatio = 1] The minimum aspect ratio (width/height) allowed for the rectangle. This property should only be used if the aspectRatio is not provided.\n @param {Number} [options.nTries = 20] The number of randomly drawn points inside the polygon which the algorithm explores as possible center points of the maximal rectangle.\n @param {Number} [options.minHeight = 0] The minimum height of the rectangle.\n @param {Number} [options.minWidth = 0] The minimum width of the rectangle.\n @param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.\n @param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.\n @param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.\n @return {largestRect}\n*/\nexport default function(poly, options = {}) {\n\n if (poly.length < 3) {\n if (options.verbose) console.error(\"polygon has to have at least 3 points\", poly);\n return null;\n }\n\n // For visualization debugging purposes\n const events = [];\n\n // User's input normalization\n options = Object.assign({\n angle: range(-90, 90 + angleStep, angleStep),\n cache: true,\n maxAspectRatio: 15,\n minAspectRatio: 1,\n minHeight: 0,\n minWidth: 0,\n nTries: 20,\n tolerance: 0.02,\n verbose: false\n }, options);\n\n const angles = options.angle instanceof Array ? options.angle\n : typeof options.angle === \"number\" ? [options.angle]\n : typeof options.angle === \"string\" && !isNaN(options.angle) ? [Number(options.angle)]\n : [];\n\n const aspectRatios = options.aspectRatio instanceof Array ? options.aspectRatio\n : typeof options.aspectRatio === \"number\" ? [options.aspectRatio]\n : typeof options.aspectRatio === \"string\" && !isNaN(options.aspectRatio) ? [Number(options.aspectRatio)]\n : [];\n\n const origins = options.origin && options.origin instanceof Array\n ? options.origin[0] instanceof Array ? options.origin\n : [options.origin] : [];\n\n let cacheString;\n if (options.cache) {\n cacheString = merge(poly).join(\",\");\n cacheString += `-${options.minAspectRatio}`;\n cacheString += `-${options.maxAspectRatio}`;\n cacheString += `-${options.minHeight}`;\n cacheString += `-${options.minWidth}`;\n cacheString += `-${angles.join(\",\")}`;\n cacheString += `-${origins.join(\",\")}`;\n if (polyCache[cacheString]) return polyCache[cacheString];\n }\n\n const area = Math.abs(polygonArea(poly)); // take absolute value of the signed area\n if (area === 0) {\n if (options.verbose) console.error(\"polygon has 0 area\", poly);\n return null;\n }\n // get the width of the bounding box of the original polygon to determine tolerance\n let [minx, maxx] = extent(poly, d => d[0]);\n let [miny, maxy] = extent(poly, d => d[1]);\n\n // simplify polygon\n const tolerance = Math.min(maxx - minx, maxy - miny) * options.tolerance;\n\n if (tolerance > 0) poly = simplify(poly, tolerance);\n if (options.events) events.push({type: \"simplify\", poly});\n\n // get the width of the bounding box of the simplified polygon\n [minx, maxx] = extent(poly, d => d[0]);\n [miny, maxy] = extent(poly, d => d[1]);\n const [boxWidth, boxHeight] = [maxx - minx, maxy - miny];\n\n // discretize the binary search for optimal width to a resolution of this times the polygon width\n const widthStep = Math.min(boxWidth, boxHeight) / 50;\n\n // populate possible center points with random points inside the polygon\n if (!origins.length) {\n // get the centroid of the polygon\n const centroid = polygonCentroid(poly);\n if (!isFinite(centroid[0])) {\n if (options.verbose) console.error(\"cannot find centroid\", poly);\n return null;\n }\n if (polygonContains(poly, centroid)) origins.push(centroid);\n\n let nTries = options.nTries;\n // get few more points inside the polygon\n while (nTries) {\n const rndX = Math.random() * boxWidth + minx;\n const rndY = Math.random() * boxHeight + miny;\n const rndPoint = [rndX, rndY];\n if (polygonContains(poly, rndPoint)) {\n origins.push(rndPoint);\n }\n nTries--;\n }\n }\n if (options.events) events.push({type: \"origins\", points: origins});\n let maxArea = 0;\n let maxRect = null;\n\n for (let ai = 0; ai < angles.length; ai++) {\n const angle = angles[ai];\n const angleRad = -angle * Math.PI / 180;\n if (options.events) events.push({type: \"angle\", angle});\n for (let i = 0; i < origins.length; i++) {\n const origOrigin = origins[i];\n // generate improved origins\n const [p1W, p2W] = polygonRayCast(poly, origOrigin, angleRad);\n const [p1H, p2H] = polygonRayCast(poly, origOrigin, angleRad + Math.PI / 2);\n const modifOrigins = [];\n if (p1W && p2W) modifOrigins.push([(p1W[0] + p2W[0]) / 2, (p1W[1] + p2W[1]) / 2]); // average along with width axis\n if (p1H && p2H) modifOrigins.push([(p1H[0] + p2H[0]) / 2, (p1H[1] + p2H[1]) / 2]); // average along with height axis\n\n if (options.events) events.push({type: \"modifOrigin\", idx: i, p1W, p2W, p1H, p2H, modifOrigins});\n\n for (let i = 0; i < modifOrigins.length; i++) {\n\n const origin = modifOrigins[i];\n\n if (options.events) events.push({type: \"origin\", cx: origin[0], cy: origin[1]});\n\n const [p1W, p2W] = polygonRayCast(poly, origin, angleRad);\n if (p1W === null || p2W === null) continue;\n const minSqDistW = Math.min(pointDistanceSquared(origin, p1W), pointDistanceSquared(origin, p2W));\n const maxWidth = 2 * Math.sqrt(minSqDistW);\n\n const [p1H, p2H] = polygonRayCast(poly, origin, angleRad + Math.PI / 2);\n if (p1H === null || p2H === null) continue;\n const minSqDistH = Math.min(pointDistanceSquared(origin, p1H), pointDistanceSquared(origin, p2H));\n const maxHeight = 2 * Math.sqrt(minSqDistH);\n\n if (maxWidth * maxHeight < maxArea) continue;\n\n let aRatios = aspectRatios;\n if (!aRatios.length) {\n const minAspectRatio = Math.max(options.minAspectRatio, options.minWidth / maxHeight, maxArea / (maxHeight * maxHeight));\n const maxAspectRatio = Math.min(options.maxAspectRatio, maxWidth / options.minHeight, maxWidth * maxWidth / maxArea);\n aRatios = range(minAspectRatio, maxAspectRatio + aspectRatioStep, aspectRatioStep);\n }\n\n for (let a = 0; a < aRatios.length; a++) {\n\n const aRatio = aRatios[a];\n\n // do a binary search to find the max width that works\n let left = Math.max(options.minWidth, Math.sqrt(maxArea * aRatio));\n let right = Math.min(maxWidth, maxHeight * aRatio);\n if (right * maxHeight < maxArea) continue;\n\n if (options.events && right - left >= widthStep) events.push({type: \"aRatio\", aRatio});\n\n while (right - left >= widthStep) {\n const width = (left + right) / 2;\n const height = width / aRatio;\n const [cx, cy] = origin;\n let rectPoly = [\n [cx - width / 2, cy - height / 2],\n [cx + width / 2, cy - height / 2],\n [cx + width / 2, cy + height / 2],\n [cx - width / 2, cy + height / 2]\n ];\n rectPoly = polygonRotate(rectPoly, angleRad, origin);\n const insidePoly = polygonInside(rectPoly, poly);\n if (insidePoly) {\n // we know that the area is already greater than the maxArea found so far\n maxArea = width * height;\n rectPoly.push(rectPoly[0]);\n maxRect = {area: maxArea, cx, cy, width, height, angle: -angle, points: rectPoly};\n left = width; // increase the width in the binary search\n }\n else {\n right = width; // decrease the width in the binary search\n }\n if (options.events) events.push({type: \"rectangle\", areaFraction: width * height / area, cx, cy, width, height, angle, insidePoly});\n\n }\n\n }\n\n }\n\n }\n\n }\n\n if (options.cache) {\n polyCache[cacheString] = maxRect;\n }\n\n return options.events ? Object.assign(maxRect || {}, {events}) : maxRect;\n\n}\n","/**\n @function path2polygon\n @desc Transforms a path string into an Array of points.\n @param {String} path An SVG string path, commonly the \"d\" property of a <path> element.\n @param {Number} [segmentLength = 50] The length of line segments when converting curves line segments. Higher values lower computation time, but will result in curves that are more rigid.\n @returns {Array}\n*/\nexport default (path, segmentLength = 50) => {\n\n if (typeof document === \"undefined\") return [];\n\n const svgPath = document.createElementNS(\"http://www.w3.org/2000/svg\", \"path\");\n svgPath.setAttribute(\"d\", path);\n\n const len = svgPath.getTotalLength();\n const NUM_POINTS = len / segmentLength < 10 ? len / 10 : len / segmentLength;\n\n const points = [];\n for (let i = 0; i < NUM_POINTS; i++) {\n const pt = svgPath.getPointAtLength(i * len / (NUM_POINTS-1));\n points.push([pt.x, pt.y]);\n }\n \n return points;\n\n};\n","import pointDistanceSquared from \"./pointDistanceSquared.js\";\n\n/**\n @function pointDistance\n @desc Calculates the pixel distance between two points.\n @param {Array} p1 The first point, which should always be an `[x, y]` formatted Array.\n @param {Array} p2 The second point, which should always be an `[x, y]` formatted Array.\n @returns {Number}\n*/\nexport default (p1, p2) => Math.sqrt(pointDistanceSquared(p1, p2));\n","const pi = Math.PI;\n\n/**\n @function shapeEdgePoint\n @desc Calculates the x/y position of a point at the edge of a shape, from the center of the shape, given a specified pixel distance and radian angle.\n @param {Number} angle The angle, in radians, of the offset point.\n @param {Number} distance The pixel distance away from the origin.\n @returns {String} [shape = \"circle\"] The type of shape, which can be either \"circle\" or \"square\".\n*/\nexport default (angle, distance, shape = \"circle\") => {\n\n if (angle < 0) angle = pi * 2 + angle;\n\n if (shape === \"square\") {\n\n const diagonal = 45 * (pi / 180);\n let x = 0, y = 0;\n\n if (angle < pi / 2) {\n const tan = Math.tan(angle);\n x += angle < diagonal ? distance : distance / tan;\n y += angle < diagonal ? tan * distance : distance;\n }\n else if (angle <= pi) {\n const tan = Math.tan(pi - angle);\n x -= angle < pi - diagonal ? distance / tan : distance;\n y += angle < pi - diagonal ? distance : tan * distance;\n }\n else if (angle < diagonal + pi) {\n x -= distance;\n y -= Math.tan(angle - pi) * distance;\n }\n else if (angle < 3 * pi / 2) {\n x -= distance / Math.tan(angle - pi);\n y -= distance;\n }\n else if (angle < 2 * pi - diagonal) {\n x += distance / Math.tan(2 * pi - angle);\n y -= distance;\n }\n else {\n x += distance;\n y -= Math.tan(2 * pi - angle) * distance;\n }\n\n return [x, y];\n\n }\n else if (shape === \"circle\") {\n return [distance * Math.cos(angle), distance * Math.sin(angle)];\n }\n else return null;\n\n};\n"],"names":["numericSort","array","slice","sort","a","b","uniqueCountSorted","input","lastSeenValue","uniqueValueCount","i","length","makeMatrix","columns","rows","matrix","column","j","push","ssq","sums","sumsOfSquares","sji","muji","fillMatrixColumn","iMin","iMax","cluster","backtrackMatrix","Math","floor","jlow","max","jhigh","min","sjlowi","ssqjlow","ssqj","fillMatrices","data","nValues","shift","shiftedValue","nClusters","Error","sorted","uniqueCount","clusterRight","clusters","clusterLeft","n","arr","Array","undefined","reduce","prev","curr","abs","p1","q1","p2","q2","eps","dx1","dx2","dy1","dy2","denom","cross1","cross2","px","py","s1","s2","p","lineIntersection","segmentBoxContains","polyA","polyB","iA","nA","nB","bA","aA","iB","bB","aB","segmentsIntersect","polygonContains","dx","dy","poly","origin","alpha","cos","sin","x0","y0","shiftedOrigin","idx","minSqDistLeft","Number","MAX_VALUE","minSqDistRight","closestPointLeft","closestPointRight","sqDist","pointDistanceSquared","cosAlpha","sinAlpha","xshifted","yshifted","map","pointRotate","getSqSegDist","x","y","t","simplifyRadialDist","sqTolerance","point","prevPoint","newPoints","len","simplifyDPStep","first","last","simplified","index","maxSqDist","simplifyDouglasPeucker","tolerance","highestQuality","aspectRatioStep","angleStep","polyCache","options","verbose","console","error","events","Object","assign","angle","range","cache","maxAspectRatio","minAspectRatio","minHeight","minWidth","nTries","angles","isNaN","aspectRatios","aspectRatio","origins","cacheString","merge","join","area","polygonArea","minx","maxx","extent","d","miny","maxy","simplify","type","boxWidth","boxHeight","widthStep","centroid","polygonCentroid","isFinite","rndX","random","rndY","rndPoint","points","maxArea","maxRect","ai","angleRad","PI","origOrigin","p1W","p2W","polygonRayCast","p1H","p2H","modifOrigins","cx","cy","minSqDistW","maxWidth","sqrt","minSqDistH","maxHeight","aRatios","aRatio","left","right","width","height","rectPoly","polygonRotate","insidePoly","polygonInside","areaFraction","path","segmentLength","document","svgPath","createElementNS","setAttribute","getTotalLength","NUM_POINTS","pt","getPointAtLength","pi","distance","shape","diagonal","tan"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;EAcA,GACA,SAASA,YAAYC,KAAK,EAAA;MACxB,OAAOA,KAAAA,CAAMC,KAAK,EAAGC,CAAAA,IAAI,CAAC,CAACC,CAAAA,EAAGC,IAAMD,CAAIC,GAAAA,CAAAA,CAAAA;EAC1C;EAEA;;;;;;;;;;EAUA,GACA,SAASC,kBAAkBC,KAAK,EAAA;EAC9B,IAAA,IAAIC,eAAeC,gBAAmB,GAAA,CAAA;EACtC,IAAA,IAAK,IAAIC,CAAI,GAAA,CAAA,EAAGA,IAAIH,KAAMI,CAAAA,MAAM,EAAED,CAAK,EAAA,CAAA;EACrC,QAAA,IAAIA,MAAM,CAAKH,IAAAA,KAAK,CAACG,CAAAA,CAAE,KAAKF,aAAe,EAAA;cACzCA,aAAgBD,GAAAA,KAAK,CAACG,CAAE,CAAA;EACxBD,YAAAA,gBAAAA,EAAAA;EACF;EACF;MACA,OAAOA,gBAAAA;EACT;EAEA;;;;;;;;EAQA,GACA,SAASG,UAAAA,CAAWC,OAAO,EAAEC,IAAI,EAAA;EAC/B,IAAA,MAAMC,SAAS,EAAE;EACjB,IAAA,IAAK,IAAIL,CAAAA,GAAI,CAAGA,EAAAA,CAAAA,GAAIG,SAASH,CAAK,EAAA,CAAA;EAChC,QAAA,MAAMM,SAAS,EAAE;UACjB,IAAK,IAAIC,IAAI,CAAGA,EAAAA,CAAAA,GAAIH,MAAMG,CAAKD,EAAAA,CAAAA,MAAAA,CAAOE,IAAI,CAAC,CAAA,CAAA;EAC3CH,QAAAA,MAAAA,CAAOG,IAAI,CAACF,MAAAA,CAAAA;EACd;MACA,OAAOD,MAAAA;E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IAAK0G,QAAWhM,GAAAA,IAAAA,CAAKmM,GAAG,CAAC,IAAIJ,EAAK7E,GAAAA,KAAAA,CAAAA;cAClC3B,CAAKyG,IAAAA,QAAAA;WAEF,MAAA;cACH1G,CAAK0G,IAAAA,QAAAA;EACLzG,YAAAA,CAAAA,IAAKvF,IAAKmM,CAAAA,GAAG,CAAC,CAAA,GAAIJ,KAAK7E,KAAS8E,CAAAA,GAAAA,QAAAA;EAClC;UAEA,OAAO;EAAC1G,YAAAA,CAAAA;EAAGC,YAAAA;EAAE,SAAA;OAGV,MAAA,IAAI0G,UAAU,QAAU,EAAA;UAC3B,OAAO;cAACD,QAAWhM,GAAAA,IAAAA,CAAKiE,GAAG,CAACiD,KAAAA,CAAAA;cAAQ8E,QAAWhM,GAAAA,IAAAA,CAAKkE,GAAG,CAACgD,KAAAA;EAAO,SAAA;EACjE,KAAA,MACK,OAAO,IAAA;EAEd,CAAA;;;;;;;;;;;;;;;;;;;;;;"}
|
package/umd/d3plus-math.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/math v3.0.0-alpha.
|
|
2
|
+
@d3plus/math v3.0.0-alpha.4
|
|
3
3
|
Mathematical functions to aid in calculating visualizations.
|
|
4
4
|
Copyright (c) 2025 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
@@ -235,7 +235,7 @@ i[t]=n.slice(o,a+1),0<t&&(a=o-1)}return i}
|
|
|
235
235
|
@param {Array} arr The array of values to test against.
|
|
236
236
|
*/,t.closest=function(n,t=[]){if(t&&t instanceof Array&&t.length)return t.reduce((t,e)=>Math.abs(e-n)<Math.abs(t-n)?e:t)},t.largestRect=
|
|
237
237
|
/**
|
|
238
|
-
@typedef {Object}
|
|
238
|
+
@typedef {Object} largestRect
|
|
239
239
|
@desc The returned Object of the largestRect function.
|
|
240
240
|
@property {Number} width The width of the rectangle
|
|
241
241
|
@property {Number} height The height of the rectangle
|
|
@@ -261,7 +261,7 @@ i[t]=n.slice(o,a+1),0<t&&(a=o-1)}return i}
|
|
|
261
261
|
@param {Number} [options.tolerance = 0.02] The simplification tolerance factor, between 0 and 1. A larger tolerance corresponds to more extensive simplification.
|
|
262
262
|
@param {Array} [options.origin] The center point of the rectangle. If specified, the rectangle will be fixed at that point, otherwise the algorithm optimizes across all possible points. The given value can be either a two dimensional array specifying the x and y coordinate of the origin or an array of two dimensional points specifying multiple possible center points of the rectangle.
|
|
263
263
|
@param {Boolean} [options.cache] Whether or not to cache the result, which would be used in subsequent calculations to preserve consistency and speed up calculation time.
|
|
264
|
-
@return {
|
|
264
|
+
@return {largestRect}
|
|
265
265
|
*/function(a,i={}){if(a.length<3)return i.verbose&&console.error("polygon has to have at least 3 points",a),null;
|
|
266
266
|
// For visualization debugging purposes
|
|
267
267
|
var o=[],e=(
|