You've already forked wakapi-readme-stats
Bar graph added.
This commit is contained in:
13
node_modules/d3-delaunay/LICENSE
generated
vendored
Normal file
13
node_modules/d3-delaunay/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
Copyright 2018 Observable, Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||
with or without fee is hereby granted, provided that the above copyright notice
|
||||
and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
201
node_modules/d3-delaunay/README.md
generated
vendored
Normal file
201
node_modules/d3-delaunay/README.md
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
# d3-delaunay
|
||||
|
||||
<p align="center"><img src="https://raw.githubusercontent.com/d3/d3-delaunay/master/img/voronator.jpg" width="300">
|
||||
<p align="center">Georgy “The Voronator” Voronoy
|
||||
|
||||
This is a fast, no-dependency library for computing the [Voronoi diagram](https://en.wikipedia.org/wiki/Voronoi_diagram) of a set of two-dimensional points. It is based on [Delaunator](https://github.com/mapbox/delaunator), a fast library for computing the [Delaunay triangulation](https://en.wikipedia.org/wiki/Delaunay_triangulation) using [sweep algorithms](https://github.com/mapbox/delaunator/blob/master/README.md#papers). The Voronoi diagram is constructed by connecting the circumcenters of adjacent triangles in the Delaunay triangulation.
|
||||
|
||||
For an interactive explanation of how this library works, see [The Delaunay’s Dual](https://observablehq.com/@mbostock/the-delaunays-dual).
|
||||
|
||||
## Installing
|
||||
|
||||
To install, `npm install d3-delaunay` or `yarn add d3-delaunay`. You can also download the [latest release](https://github.com/d3/d3-delaunay/releases/latest) or load directly from [unpkg](https://unpkg.com/d3-delaunay/). AMD, CommonJS and ES6+ environments are supported. In vanilla, a `d3` global is exported.
|
||||
|
||||
```js
|
||||
import {Delaunay} from "d3-delaunay";
|
||||
|
||||
const points = [[0, 0], [0, 1], [1, 0], [1, 1]];
|
||||
const delaunay = Delaunay.from(points);
|
||||
const voronoi = delaunay.voronoi([0, 0, 960, 500]);
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### Delaunay
|
||||
|
||||
<a href="#new_Delaunay" name="new_Delaunay">#</a> new <b>Delaunay</b>(<i>points</i>) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Returns the Delaunay triangulation for the given flat array [*x0*, *y0*, *x1*, *y1*, …] of *points*.
|
||||
|
||||
```js
|
||||
const delaunay = new Delaunay(Float64Array.of(0, 0, 0, 1, 1, 0, 1, 1));
|
||||
```
|
||||
|
||||
<a href="#delaunay_from" name="delaunay_from">#</a> Delaunay.<b>from</b>(<i>points</i>[, <i>fx</i>[, <i>fy</i>[, <i>that</i>]]]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Returns the Delaunay triangulation for the given array or iterable of *points*. If *fx* and *fy* are not specified, then *points* is assumed to be an array of two-element arrays of numbers: [[*x0*, *y0*], [*x1*, *y1*], …]. Otherwise, *fx* and *fy* are functions that are invoked for each element in the *points* array in order, and must return the respective *x*- and *y*-coordinate for each point. If *that* is specified, the functions *fx* and *fy* are invoked with *that* as *this*. (See [Array.from](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/from) for reference.)
|
||||
|
||||
```js
|
||||
const delaunay = Delaunay.from([[0, 0], [0, 1], [1, 0], [1, 1]]);
|
||||
```
|
||||
|
||||
<a href="#delaunay_points" name="delaunay_points">#</a> <i>delaunay</i>.<b>points</b>
|
||||
|
||||
The coordinates of the points as an array [*x0*, *y0*, *x1*, *y1*, …]. Typically, this is a Float64Array, however you can use any array-like type in the [constructor](#new_Delaunay).
|
||||
|
||||
<a href="#delaunay_halfedges" name="delaunay_halfedges">#</a> <i>delaunay</i>.<b>halfedges</b>
|
||||
|
||||
The halfedge indexes as an Int32Array [*j0*, *j1*, …]. For each index 0 ≤ *i* < *halfedges*.length, there is a halfedge from triangle vertex *j* = *halfedges*[*i*] to triangle vertex *i*. Equivalently, this means that triangle ⌊*i* / 3⌋ is adjacent to triangle ⌊*j* / 3⌋. If *j* is negative, then triangle ⌊*i* / 3⌋ is an exterior triangle on the [convex hull](#delaunay_hull). For example, to render the internal edges of the Delaunay triangulation:
|
||||
|
||||
```js
|
||||
const {points, halfedges, triangles} = delaunay;
|
||||
for (let i = 0, n = halfedges.length; i < n; ++i) {
|
||||
const j = halfedges[i];
|
||||
if (j < i) continue;
|
||||
const ti = triangles[i];
|
||||
const tj = triangles[j];
|
||||
context.moveTo(points[ti * 2], points[ti * 2 + 1]);
|
||||
context.lineTo(points[tj * 2], points[tj * 2 + 1]);
|
||||
}
|
||||
```
|
||||
|
||||
See also [*delaunay*.render](#delaunay_render).
|
||||
|
||||
<a href="#delaunay_hull" name="delaunay_hull">#</a> <i>delaunay</i>.<b>hull</b>
|
||||
|
||||
An Int32Array of point indexes that form the convex hull in counterclockwise order. If the points are collinear, returns them ordered.
|
||||
|
||||
See also [*delaunay*.renderHull](#delaunay_renderHull).
|
||||
|
||||
<a href="#delaunay_triangles" name="delaunay_triangles">#</a> <i>delaunay</i>.<b>triangles</b>
|
||||
|
||||
The triangle vertex indexes as an Uint32Array [*i0*, *j0*, *k0*, *i1*, *j1*, *k1*, …]. Each contiguous triplet of indexes *i*, *j*, *k* forms a counterclockwise triangle. The coordinates of the triangle’s points can be found by going through [*delaunay*.points](#delaunay_points). For example, to render triangle *i*:
|
||||
|
||||
```js
|
||||
const {points, triangles} = delaunay;
|
||||
const t0 = triangles[i * 3 + 0];
|
||||
const t1 = triangles[i * 3 + 1];
|
||||
const t2 = triangles[i * 3 + 2];
|
||||
context.moveTo(points[t0 * 2], points[t0 * 2 + 1]);
|
||||
context.lineTo(points[t1 * 2], points[t1 * 2 + 1]);
|
||||
context.lineTo(points[t2 * 2], points[t2 * 2 + 1]);
|
||||
context.closePath();
|
||||
```
|
||||
|
||||
See also [*delaunay*.renderTriangle](#delaunay_renderTriangle).
|
||||
|
||||
<a href="#delaunay_inedges" name="delaunay_inedges">#</a> <i>delaunay</i>.<b>inedges</b>
|
||||
|
||||
The incoming halfedge indexes as a Int32Array [*e0*, *e1*, *e2*, …]. For each point *i*, *inedges*[*i*] is the halfedge index *e* of an incoming halfedge. For coincident points, the halfedge index is -1; for points on the convex hull, the incoming halfedge is on the convex hull; for other points, the choice of incoming halfedge is arbitrary. The *inedges* table can be used to traverse the Delaunay triangulation; see also [*delaunay*.neighbors](#delaunay_neighbors).
|
||||
|
||||
<a href="#delaunay_find" name="delaunay_find">#</a> <i>delaunay</i>.<b>find</b>(<i>x</i>, <i>y</i>[, <i>i</i>]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Returns the index of the input point that is closest to the specified point ⟨*x*, *y*⟩. The search is started at the specified point *i*. If *i* is not specified, it defaults to zero.
|
||||
|
||||
<a href="#delaunay_neighbors" name="delaunay_neighbors">#</a> <i>delaunay</i>.<b>neighbors</b>(<i>i</i>) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Returns an iterable over the indexes of the neighboring points to the specified point *i*. The iterable is empty if *i* is a coincident point.
|
||||
|
||||
<a href="#delaunay_render" name="delaunay_render">#</a> <i>delaunay</i>.<b>render</b>([<i>context</i>]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
<img alt="delaunay.render" src="https://raw.githubusercontent.com/d3/d3-delaunay/master/img/delaunay-mesh.png">
|
||||
|
||||
Renders the edges of the Delaunay triangulation to the specified *context*. The specified *context* must implement the *context*.moveTo and *context*.lineTo methods from the [CanvasPathMethods API](https://www.w3.org/TR/2dcontext/#canvaspathmethods). If a *context* is not specified, an SVG path string is returned instead.
|
||||
|
||||
<a href="#delaunay_renderHull" name="delaunay_renderHull">#</a> <i>delaunay</i>.<b>renderHull</b>([<i>context</i>]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
<img alt="delaunay.renderHull" src="https://raw.githubusercontent.com/d3/d3-delaunay/master/img/delaunay-hull.png">
|
||||
|
||||
Renders the convex hull of the Delaunay triangulation to the specified *context*. The specified *context* must implement the *context*.moveTo and *context*.lineTo methods from the [CanvasPathMethods API](https://www.w3.org/TR/2dcontext/#canvaspathmethods). If a *context* is not specified, an SVG path string is returned instead.
|
||||
|
||||
<a href="#delaunay_renderTriangle" name="delaunay_renderTriangle">#</a> <i>delaunay</i>.<b>renderTriangle</b>(<i>i</i>[, <i>context</i>]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
<img alt="delaunay.renderTriangle" src="https://raw.githubusercontent.com/d3/d3-delaunay/master/img/delaunay-triangle.png">
|
||||
|
||||
Renders triangle *i* of the Delaunay triangulation to the specified *context*. The specified *context* must implement the *context*.moveTo, *context*.lineTo and *context*.closePath methods from the [CanvasPathMethods API](https://www.w3.org/TR/2dcontext/#canvaspathmethods). If a *context* is not specified, an SVG path string is returned instead.
|
||||
|
||||
<a href="#delaunay_renderPoints" name="delaunay_renderPoints">#</a> <i>delaunay</i>.<b>renderPoints</b>(\[<i>context</i>\]\[, <i>radius</i>\]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Renders the input points of the Delaunay triangulation to the specified *context* as circles with the specified *radius*. If *radius* is not specified, it defaults to 2. The specified *context* must implement the *context*.moveTo and *context*.arc methods from the [CanvasPathMethods API](https://www.w3.org/TR/2dcontext/#canvaspathmethods). If a *context* is not specified, an SVG path string is returned instead.
|
||||
|
||||
<a href="#delaunay_hullPolygon" name="delaunay_hullPolygon">#</a> <i>delaunay</i>.<b>hullPolygon()</b> [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Returns the closed polygon [[*x0*, *y0*], [*x1*, *y1*], …, [*x0*, *y0*]] representing the convex hull.
|
||||
|
||||
<a href="#delaunay_trianglePolygons" name="delaunay_trianglePolygons">#</a> <i>delaunay</i>.<b>trianglePolygons()</b> [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Returns an iterable over the [polygons for each triangle](#delaunay_trianglePolygon), in order.
|
||||
|
||||
<a href="#delaunay_trianglePolygon" name="delaunay_trianglePolygon">#</a> <i>delaunay</i>.<b>trianglePolygon(<i>i</i>)</b> [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Returns the closed polygon [[*x0*, *y0*], [*x1*, *y1*], [*x2*, *y2*], [*x0*, *y0*]] representing the triangle *i*.
|
||||
|
||||
<a href="#delaunay_update" name="delaunay_update">#</a> <i>delaunay</i>.<b>update</b>() [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Updates the triangulation after the points have been modified in-place.
|
||||
|
||||
<a href="#delaunay_voronoi" name="delaunay_voronoi">#</a> <i>delaunay</i>.<b>voronoi</b>([<i>bounds</i>]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js "Source")
|
||||
|
||||
Returns the [Voronoi diagram](#voronoi) for the associated [points](#delaunay_points). When rendering, the diagram will be clipped to the specified *bounds* = [*xmin*, *ymin*, *xmax*, *ymax*]. If *bounds* is not specified, it defaults to [0, 0, 960, 500]. See [To Infinity and Back Again](https://observablehq.com/@mbostock/to-infinity-and-back-again) for an interactive explanation of Voronoi cell clipping.
|
||||
|
||||
The Voronoi diagram is returned even in degenerate cases where no triangulation exists — namely 0, 1 or 2 points, and collinear points.
|
||||
|
||||
### Voronoi
|
||||
|
||||
<a href="#voronoi_delaunay" name="voronoi_delaunay">#</a> <i>voronoi</i>.<b>delaunay</b>
|
||||
|
||||
The Voronoi diagram’s associated [Delaunay triangulation](#delaunay).
|
||||
|
||||
<a href="#voronoi_circumcenters" name="voronoi_circumcenters">#</a> <i>voronoi</i>.<b>circumcenters</b>
|
||||
|
||||
The [circumcenters](http://mathworld.wolfram.com/Circumcenter.html) of the Delaunay triangles as a Float64Array [*cx0*, *cy0*, *cx1*, *cy1*, …]. Each contiguous pair of coordinates *cx*, *cy* is the circumcenter for the corresponding triangle. These circumcenters form the coordinates of the Voronoi cell polygons.
|
||||
|
||||
<a href="#voronoi_vectors" name="voronoi_vectors">#</a> <i>voronoi</i>.<b>vectors</b>
|
||||
|
||||
A Float64Array [*vx0*, *vy0*, *wx0*, *wy0*, …] where each non-zero quadruple describes an open (infinite) cell on the outer hull, giving the directions of two open half-lines.
|
||||
|
||||
<a href="#voronoi_xmin" name="voronoi_xmin">#</a> <i>voronoi</i>.<b>xmin</b><br>
|
||||
<a href="#voronoi_ymin" name="voronoi_ymin">#</a> <i>voronoi</i>.<b>ymin</b><br>
|
||||
<a href="#voronoi_xmax" name="voronoi_xmax">#</a> <i>voronoi</i>.<b>xmax</b><br>
|
||||
<a href="#voronoi_ymax" name="voronoi_ymax">#</a> <i>voronoi</i>.<b>ymax</b><br>
|
||||
|
||||
The bounds of the viewport [*xmin*, *ymin*, *xmax*, *ymax*] for rendering the Voronoi diagram. These values only affect the rendering methods ([*voronoi*.render](#voronoi_render), [*voronoi*.renderBounds](#voronoi_renderBounds), [*cell*.render](#cell_render)).
|
||||
|
||||
<a href="#voronoi_contains" name="voronoi_contains">#</a> <i>voronoi</i>.<b>contains</b>(<i>i</i>, <i>x</i>, <i>y</i>) [<>](https://github.com/d3/d3-delaunay/blob/master/src/cell.js "Source")
|
||||
|
||||
Returns true if the cell with the specified index *i* contains the specified point ⟨*x*, *y*⟩. (This method is not affected by the associated Voronoi diagram’s viewport [bounds](#voronoi_xmin).)
|
||||
|
||||
<a href="#voronoi_neighbors" name="voronoi_neighbors">#</a> <i>voronoi</i>.<b>neighbors</b>(<i>i</i>) [<>](https://github.com/d3/d3-delaunay/blob/master/src/voronoi.js "Source")
|
||||
|
||||
Returns an iterable over the indexes of the cells that share a common edge with the specified cell *i*. Voronoi neighbors are always neighbors on the Delaunay graph, but the converse is false when the common edge has been clipped out by the Voronoi diagram’s viewport.
|
||||
|
||||
<a href="#voronoi_render" name="voronoi_render">#</a> <i>voronoi</i>.<b>render</b>([<i>context</i>]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/voronoi.js "Source")
|
||||
|
||||
<img alt="voronoi.render" src="https://raw.githubusercontent.com/d3/d3-delaunay/master/img/voronoi-mesh.png">
|
||||
|
||||
Renders the mesh of Voronoi cells to the specified *context*. The specified *context* must implement the *context*.moveTo and *context*.lineTo methods from the [CanvasPathMethods API](https://www.w3.org/TR/2dcontext/#canvaspathmethods). If a *context* is not specified, an SVG path string is returned instead.
|
||||
|
||||
<a href="#voronoi_renderBounds" name="voronoi_renderBounds">#</a> <i>voronoi</i>.<b>renderBounds</b>([<i>context</i>]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/voronoi.js "Source")
|
||||
|
||||
<img alt="voronoi.renderBounds" src="https://raw.githubusercontent.com/d3/d3-delaunay/master/img/voronoi-bounds.png">
|
||||
|
||||
Renders the viewport extent to the specified *context*. The specified *context* must implement the *context*.rect method from the [CanvasPathMethods API](https://www.w3.org/TR/2dcontext/#canvaspathmethods). Equivalent to *context*.rect(*voronoi*.xmin, *voronoi*.ymin, *voronoi*.xmax - *voronoi*.xmin, *voronoi*.ymax - *voronoi*.ymin). If a *context* is not specified, an SVG path string is returned instead.
|
||||
|
||||
<a href="#voronoi_renderCell" name="voronoi_renderCell">#</a> <i>voronoi</i>.<b>renderCell</b>(<i>i</i>[, <i>context</i>]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/voronoi.js "Source")
|
||||
|
||||
<img alt="cell.render" src="https://raw.githubusercontent.com/d3/d3-delaunay/master/img/spectral.png">
|
||||
|
||||
Renders the cell with the specified index *i* to the specified *context*. The specified *context* must implement the *context*.moveTo , *context*.lineTo and *context*.closePath methods from the [CanvasPathMethods API](https://www.w3.org/TR/2dcontext/#canvaspathmethods). If a *context* is not specified, an SVG path string is returned instead.
|
||||
|
||||
<a href="#voronoi_cellPolygons" name="voronoi_cellPolygons">#</a> <i>voronoi</i>.<b>cellPolygons</b>() [<>](https://github.com/d3/d3-delaunay/blob/master/src/voronoi.js "Source")
|
||||
|
||||
Returns an iterable over the non-empty [polygons for each cell](#voronoi_cellPolygon), with the cell index as property.
|
||||
|
||||
<a href="#voronoi_cellPolygon" name="voronoi_cellPolygon">#</a> <i>voronoi</i>.<b>cellPolygon</b>(<i>i</i>) [<>](https://github.com/d3/d3-delaunay/blob/master/src/voronoi.js "Source")
|
||||
|
||||
Returns the convex, closed polygon [[*x0*, *y0*], [*x1*, *y1*], …, [*x0*, *y0*]] representing the cell for the specified point *i*.
|
||||
|
||||
<a href="#voronoi_update" name="voronoi_update">#</a> <i>voronoi</i>.<b>update</b>() [<>](https://github.com/d3/d3-delaunay/blob/master/src/voronoi.js "Source")
|
||||
|
||||
Updates the Voronoi diagram and underlying triangulation after the points have been modified in-place — useful for Lloyd’s relaxation.
|
||||
|
||||
1123
node_modules/d3-delaunay/dist/d3-delaunay.js
generated
vendored
Normal file
1123
node_modules/d3-delaunay/dist/d3-delaunay.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
node_modules/d3-delaunay/dist/d3-delaunay.min.js
generated
vendored
Normal file
3
node_modules/d3-delaunay/dist/d3-delaunay.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
82
node_modules/d3-delaunay/package.json
generated
vendored
Normal file
82
node_modules/d3-delaunay/package.json
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"_from": "d3-delaunay@^5.2.1",
|
||||
"_id": "d3-delaunay@5.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-amALSrOllWVLaHTnDLHwMIiz0d1bBu9gZXd1FiLfXf8sHcX9jrcj81TVZOqD4UX7MgBZZ07c8GxzEgBpJqc74w==",
|
||||
"_location": "/d3-delaunay",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "d3-delaunay@^5.2.1",
|
||||
"name": "d3-delaunay",
|
||||
"escapedName": "d3-delaunay",
|
||||
"rawSpec": "^5.2.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^5.2.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vega-voronoi"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/d3-delaunay/-/d3-delaunay-5.3.0.tgz",
|
||||
"_shasum": "b47f05c38f854a4e7b3cea80e0bb12e57398772d",
|
||||
"_spec": "d3-delaunay@^5.2.1",
|
||||
"_where": "/home/prabhatdev/Documents/opensource/gitHubStats/waka-readme-stats/node_modules/vega-voronoi",
|
||||
"author": {
|
||||
"name": "Mike Bostock",
|
||||
"url": "https://bost.ocks.org/mike"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/d3/d3-delaunay/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Vladimir Agafonkin",
|
||||
"url": "https://agafonkin.com"
|
||||
},
|
||||
{
|
||||
"name": "Philippe Rivière",
|
||||
"url": "https://visionscarto.net"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"delaunator": "4"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Compute the Voronoi diagram of a set of two-dimensional points.",
|
||||
"devDependencies": {
|
||||
"@observablehq/tape": "~0.0.1",
|
||||
"eslint": "6",
|
||||
"esm": "3",
|
||||
"rollup": "1",
|
||||
"rollup-plugin-node-resolve": "5",
|
||||
"rollup-plugin-terser": "5"
|
||||
},
|
||||
"files": [
|
||||
"dist/**/*.js",
|
||||
"src/**/*.js"
|
||||
],
|
||||
"homepage": "https://github.com/d3/d3-delaunay",
|
||||
"keywords": [
|
||||
"voronoi",
|
||||
"delaunay",
|
||||
"geometry"
|
||||
],
|
||||
"license": "ISC",
|
||||
"main": "dist/d3-delaunay.js",
|
||||
"module": "src/index.js",
|
||||
"name": "d3-delaunay",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/d3/d3-delaunay.git"
|
||||
},
|
||||
"scripts": {
|
||||
"postpublish": "git push && git push --tags && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js",
|
||||
"prepublishOnly": "yarn test && rm -rf dist && rollup -c",
|
||||
"test": "tape -r esm 'test/**/*-test.js' && eslint src test"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"unpkg": "dist/d3-delaunay.min.js",
|
||||
"version": "5.3.0"
|
||||
}
|
||||
244
node_modules/d3-delaunay/src/delaunay.js
generated
vendored
Normal file
244
node_modules/d3-delaunay/src/delaunay.js
generated
vendored
Normal file
@@ -0,0 +1,244 @@
|
||||
import Delaunator from "delaunator";
|
||||
import Path from "./path.js";
|
||||
import Polygon from "./polygon.js";
|
||||
import Voronoi from "./voronoi.js";
|
||||
|
||||
const tau = 2 * Math.PI, pow = Math.pow;
|
||||
|
||||
function pointX(p) {
|
||||
return p[0];
|
||||
}
|
||||
|
||||
function pointY(p) {
|
||||
return p[1];
|
||||
}
|
||||
|
||||
// A triangulation is collinear if all its triangles have a non-null area
|
||||
function collinear(d) {
|
||||
const {triangles, coords} = d;
|
||||
for (let i = 0; i < triangles.length; i += 3) {
|
||||
const a = 2 * triangles[i],
|
||||
b = 2 * triangles[i + 1],
|
||||
c = 2 * triangles[i + 2],
|
||||
cross = (coords[c] - coords[a]) * (coords[b + 1] - coords[a + 1])
|
||||
- (coords[b] - coords[a]) * (coords[c + 1] - coords[a + 1]);
|
||||
if (cross > 1e-10) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function jitter(x, y, r) {
|
||||
return [x + Math.sin(x + y) * r, y + Math.cos(x - y) * r];
|
||||
}
|
||||
|
||||
export default class Delaunay {
|
||||
static from(points, fx = pointX, fy = pointY, that) {
|
||||
return new Delaunay("length" in points
|
||||
? flatArray(points, fx, fy, that)
|
||||
: Float64Array.from(flatIterable(points, fx, fy, that)));
|
||||
}
|
||||
constructor(points) {
|
||||
this._delaunator = new Delaunator(points);
|
||||
this.inedges = new Int32Array(points.length / 2);
|
||||
this._hullIndex = new Int32Array(points.length / 2);
|
||||
this.points = this._delaunator.coords;
|
||||
this._init();
|
||||
}
|
||||
update() {
|
||||
this._delaunator.update();
|
||||
this._init();
|
||||
return this;
|
||||
}
|
||||
_init() {
|
||||
const d = this._delaunator, points = this.points;
|
||||
|
||||
// check for collinear
|
||||
if (d.hull && d.hull.length > 2 && collinear(d)) {
|
||||
this.collinear = Int32Array.from({length: points.length/2}, (_,i) => i)
|
||||
.sort((i, j) => points[2 * i] - points[2 * j] || points[2 * i + 1] - points[2 * j + 1]); // for exact neighbors
|
||||
const e = this.collinear[0], f = this.collinear[this.collinear.length - 1],
|
||||
bounds = [ points[2 * e], points[2 * e + 1], points[2 * f], points[2 * f + 1] ],
|
||||
r = 1e-8 * Math.hypot(bounds[3] - bounds[1], bounds[2] - bounds[0]);
|
||||
for (let i = 0, n = points.length / 2; i < n; ++i) {
|
||||
const p = jitter(points[2 * i], points[2 * i + 1], r);
|
||||
points[2 * i] = p[0];
|
||||
points[2 * i + 1] = p[1];
|
||||
}
|
||||
this._delaunator = new Delaunator(points);
|
||||
} else {
|
||||
delete this.collinear;
|
||||
}
|
||||
|
||||
const halfedges = this.halfedges = this._delaunator.halfedges;
|
||||
const hull = this.hull = this._delaunator.hull;
|
||||
const triangles = this.triangles = this._delaunator.triangles;
|
||||
const inedges = this.inedges.fill(-1);
|
||||
const hullIndex = this._hullIndex.fill(-1);
|
||||
|
||||
// Compute an index from each point to an (arbitrary) incoming halfedge
|
||||
// Used to give the first neighbor of each point; for this reason,
|
||||
// on the hull we give priority to exterior halfedges
|
||||
for (let e = 0, n = halfedges.length; e < n; ++e) {
|
||||
const p = triangles[e % 3 === 2 ? e - 2 : e + 1];
|
||||
if (halfedges[e] === -1 || inedges[p] === -1) inedges[p] = e;
|
||||
}
|
||||
for (let i = 0, n = hull.length; i < n; ++i) {
|
||||
hullIndex[hull[i]] = i;
|
||||
}
|
||||
|
||||
// degenerate case: 1 or 2 (distinct) points
|
||||
if (hull.length <= 2 && hull.length > 0) {
|
||||
this.triangles = new Int32Array(3).fill(-1);
|
||||
this.halfedges = new Int32Array(3).fill(-1);
|
||||
this.triangles[0] = hull[0];
|
||||
this.triangles[1] = hull[1];
|
||||
this.triangles[2] = hull[1];
|
||||
inedges[hull[0]] = 1;
|
||||
if (hull.length === 2) inedges[hull[1]] = 0;
|
||||
}
|
||||
}
|
||||
voronoi(bounds) {
|
||||
return new Voronoi(this, bounds);
|
||||
}
|
||||
*neighbors(i) {
|
||||
const {inedges, hull, _hullIndex, halfedges, triangles, collinear} = this;
|
||||
|
||||
// degenerate case with several collinear points
|
||||
if (collinear) {
|
||||
const l = collinear.indexOf(i);
|
||||
if (l > 0) yield collinear[l - 1];
|
||||
if (l < collinear.length - 1) yield collinear[l + 1];
|
||||
return;
|
||||
}
|
||||
|
||||
const e0 = inedges[i];
|
||||
if (e0 === -1) return; // coincident point
|
||||
let e = e0, p0 = -1;
|
||||
do {
|
||||
yield p0 = triangles[e];
|
||||
e = e % 3 === 2 ? e - 2 : e + 1;
|
||||
if (triangles[e] !== i) return; // bad triangulation
|
||||
e = halfedges[e];
|
||||
if (e === -1) {
|
||||
const p = hull[(_hullIndex[i] + 1) % hull.length];
|
||||
if (p !== p0) yield p;
|
||||
return;
|
||||
}
|
||||
} while (e !== e0);
|
||||
}
|
||||
find(x, y, i = 0) {
|
||||
if ((x = +x, x !== x) || (y = +y, y !== y)) return -1;
|
||||
const i0 = i;
|
||||
let c;
|
||||
while ((c = this._step(i, x, y)) >= 0 && c !== i && c !== i0) i = c;
|
||||
return c;
|
||||
}
|
||||
_step(i, x, y) {
|
||||
const {inedges, hull, _hullIndex, halfedges, triangles, points} = this;
|
||||
if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1);
|
||||
let c = i;
|
||||
let dc = pow(x - points[i * 2], 2) + pow(y - points[i * 2 + 1], 2);
|
||||
const e0 = inedges[i];
|
||||
let e = e0;
|
||||
do {
|
||||
let t = triangles[e];
|
||||
const dt = pow(x - points[t * 2], 2) + pow(y - points[t * 2 + 1], 2);
|
||||
if (dt < dc) dc = dt, c = t;
|
||||
e = e % 3 === 2 ? e - 2 : e + 1;
|
||||
if (triangles[e] !== i) break; // bad triangulation
|
||||
e = halfedges[e];
|
||||
if (e === -1) {
|
||||
e = hull[(_hullIndex[i] + 1) % hull.length];
|
||||
if (e !== t) {
|
||||
if (pow(x - points[e * 2], 2) + pow(y - points[e * 2 + 1], 2) < dc) return e;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (e !== e0);
|
||||
return c;
|
||||
}
|
||||
render(context) {
|
||||
const buffer = context == null ? context = new Path : undefined;
|
||||
const {points, halfedges, triangles} = this;
|
||||
for (let i = 0, n = halfedges.length; i < n; ++i) {
|
||||
const j = halfedges[i];
|
||||
if (j < i) continue;
|
||||
const ti = triangles[i] * 2;
|
||||
const tj = triangles[j] * 2;
|
||||
context.moveTo(points[ti], points[ti + 1]);
|
||||
context.lineTo(points[tj], points[tj + 1]);
|
||||
}
|
||||
this.renderHull(context);
|
||||
return buffer && buffer.value();
|
||||
}
|
||||
renderPoints(context, r = 2) {
|
||||
const buffer = context == null ? context = new Path : undefined;
|
||||
const {points} = this;
|
||||
for (let i = 0, n = points.length; i < n; i += 2) {
|
||||
const x = points[i], y = points[i + 1];
|
||||
context.moveTo(x + r, y);
|
||||
context.arc(x, y, r, 0, tau);
|
||||
}
|
||||
return buffer && buffer.value();
|
||||
}
|
||||
renderHull(context) {
|
||||
const buffer = context == null ? context = new Path : undefined;
|
||||
const {hull, points} = this;
|
||||
const h = hull[0] * 2, n = hull.length;
|
||||
context.moveTo(points[h], points[h + 1]);
|
||||
for (let i = 1; i < n; ++i) {
|
||||
const h = 2 * hull[i];
|
||||
context.lineTo(points[h], points[h + 1]);
|
||||
}
|
||||
context.closePath();
|
||||
return buffer && buffer.value();
|
||||
}
|
||||
hullPolygon() {
|
||||
const polygon = new Polygon;
|
||||
this.renderHull(polygon);
|
||||
return polygon.value();
|
||||
}
|
||||
renderTriangle(i, context) {
|
||||
const buffer = context == null ? context = new Path : undefined;
|
||||
const {points, triangles} = this;
|
||||
const t0 = triangles[i *= 3] * 2;
|
||||
const t1 = triangles[i + 1] * 2;
|
||||
const t2 = triangles[i + 2] * 2;
|
||||
context.moveTo(points[t0], points[t0 + 1]);
|
||||
context.lineTo(points[t1], points[t1 + 1]);
|
||||
context.lineTo(points[t2], points[t2 + 1]);
|
||||
context.closePath();
|
||||
return buffer && buffer.value();
|
||||
}
|
||||
*trianglePolygons() {
|
||||
const {triangles} = this;
|
||||
for (let i = 0, n = triangles.length / 3; i < n; ++i) {
|
||||
yield this.trianglePolygon(i);
|
||||
}
|
||||
}
|
||||
trianglePolygon(i) {
|
||||
const polygon = new Polygon;
|
||||
this.renderTriangle(i, polygon);
|
||||
return polygon.value();
|
||||
}
|
||||
}
|
||||
|
||||
function flatArray(points, fx, fy, that) {
|
||||
const n = points.length;
|
||||
const array = new Float64Array(n * 2);
|
||||
for (let i = 0; i < n; ++i) {
|
||||
const p = points[i];
|
||||
array[i * 2] = fx.call(that, p, i, points);
|
||||
array[i * 2 + 1] = fy.call(that, p, i, points);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
function* flatIterable(points, fx, fy, that) {
|
||||
let i = 0;
|
||||
for (const p of points) {
|
||||
yield fx.call(that, p, i, points);
|
||||
yield fy.call(that, p, i, points);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
2
node_modules/d3-delaunay/src/index.js
generated
vendored
Normal file
2
node_modules/d3-delaunay/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export {default as Delaunay} from "./delaunay.js";
|
||||
export {default as Voronoi} from "./voronoi.js";
|
||||
37
node_modules/d3-delaunay/src/path.js
generated
vendored
Normal file
37
node_modules/d3-delaunay/src/path.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
const epsilon = 1e-6;
|
||||
|
||||
export default class Path {
|
||||
constructor() {
|
||||
this._x0 = this._y0 = // start of current subpath
|
||||
this._x1 = this._y1 = null; // end of current subpath
|
||||
this._ = "";
|
||||
}
|
||||
moveTo(x, y) {
|
||||
this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}`;
|
||||
}
|
||||
closePath() {
|
||||
if (this._x1 !== null) {
|
||||
this._x1 = this._x0, this._y1 = this._y0;
|
||||
this._ += "Z";
|
||||
}
|
||||
}
|
||||
lineTo(x, y) {
|
||||
this._ += `L${this._x1 = +x},${this._y1 = +y}`;
|
||||
}
|
||||
arc(x, y, r) {
|
||||
x = +x, y = +y, r = +r;
|
||||
const x0 = x + r;
|
||||
const y0 = y;
|
||||
if (r < 0) throw new Error("negative radius");
|
||||
if (this._x1 === null) this._ += `M${x0},${y0}`;
|
||||
else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) this._ += "L" + x0 + "," + y0;
|
||||
if (!r) return;
|
||||
this._ += `A${r},${r},0,1,1,${x - r},${y}A${r},${r},0,1,1,${this._x1 = x0},${this._y1 = y0}`;
|
||||
}
|
||||
rect(x, y, w, h) {
|
||||
this._ += `M${this._x0 = this._x1 = +x},${this._y0 = this._y1 = +y}h${+w}v${+h}h${-w}Z`;
|
||||
}
|
||||
value() {
|
||||
return this._ || null;
|
||||
}
|
||||
}
|
||||
17
node_modules/d3-delaunay/src/polygon.js
generated
vendored
Normal file
17
node_modules/d3-delaunay/src/polygon.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
export default class Polygon {
|
||||
constructor() {
|
||||
this._ = [];
|
||||
}
|
||||
moveTo(x, y) {
|
||||
this._.push([x, y]);
|
||||
}
|
||||
closePath() {
|
||||
this._.push(this._[0].slice());
|
||||
}
|
||||
lineTo(x, y) {
|
||||
this._.push([x, y]);
|
||||
}
|
||||
value() {
|
||||
return this._.length ? this._ : null;
|
||||
}
|
||||
}
|
||||
320
node_modules/d3-delaunay/src/voronoi.js
generated
vendored
Normal file
320
node_modules/d3-delaunay/src/voronoi.js
generated
vendored
Normal file
@@ -0,0 +1,320 @@
|
||||
import Path from "./path.js";
|
||||
import Polygon from "./polygon.js";
|
||||
|
||||
export default class Voronoi {
|
||||
constructor(delaunay, [xmin, ymin, xmax, ymax] = [0, 0, 960, 500]) {
|
||||
if (!((xmax = +xmax) >= (xmin = +xmin)) || !((ymax = +ymax) >= (ymin = +ymin))) throw new Error("invalid bounds");
|
||||
this.delaunay = delaunay;
|
||||
this._circumcenters = new Float64Array(delaunay.points.length * 2);
|
||||
this.vectors = new Float64Array(delaunay.points.length * 2);
|
||||
this.xmax = xmax, this.xmin = xmin;
|
||||
this.ymax = ymax, this.ymin = ymin;
|
||||
this._init();
|
||||
}
|
||||
update() {
|
||||
this.delaunay.update();
|
||||
this._init();
|
||||
return this;
|
||||
}
|
||||
_init() {
|
||||
const {delaunay: {points, hull, triangles}, vectors} = this;
|
||||
|
||||
// Compute circumcenters.
|
||||
const circumcenters = this.circumcenters = this._circumcenters.subarray(0, triangles.length / 3 * 2);
|
||||
for (let i = 0, j = 0, n = triangles.length, x, y; i < n; i += 3, j += 2) {
|
||||
const t1 = triangles[i] * 2;
|
||||
const t2 = triangles[i + 1] * 2;
|
||||
const t3 = triangles[i + 2] * 2;
|
||||
const x1 = points[t1];
|
||||
const y1 = points[t1 + 1];
|
||||
const x2 = points[t2];
|
||||
const y2 = points[t2 + 1];
|
||||
const x3 = points[t3];
|
||||
const y3 = points[t3 + 1];
|
||||
|
||||
const dx = x2 - x1;
|
||||
const dy = y2 - y1;
|
||||
const ex = x3 - x1;
|
||||
const ey = y3 - y1;
|
||||
const bl = dx * dx + dy * dy;
|
||||
const cl = ex * ex + ey * ey;
|
||||
const ab = (dx * ey - dy * ex) * 2;
|
||||
|
||||
if (!ab) {
|
||||
// degenerate case (collinear diagram)
|
||||
x = (x1 + x3) / 2 - 1e8 * ey;
|
||||
y = (y1 + y3) / 2 + 1e8 * ex;
|
||||
}
|
||||
else if (Math.abs(ab) < 1e-8) {
|
||||
// almost equal points (degenerate triangle)
|
||||
x = (x1 + x3) / 2;
|
||||
y = (y1 + y3) / 2;
|
||||
} else {
|
||||
const d = 1 / ab;
|
||||
x = x1 + (ey * bl - dy * cl) * d;
|
||||
y = y1 + (dx * cl - ex * bl) * d;
|
||||
}
|
||||
circumcenters[j] = x;
|
||||
circumcenters[j + 1] = y;
|
||||
}
|
||||
|
||||
// Compute exterior cell rays.
|
||||
let h = hull[hull.length - 1];
|
||||
let p0, p1 = h * 4;
|
||||
let x0, x1 = points[2 * h];
|
||||
let y0, y1 = points[2 * h + 1];
|
||||
vectors.fill(0);
|
||||
for (let i = 0; i < hull.length; ++i) {
|
||||
h = hull[i];
|
||||
p0 = p1, x0 = x1, y0 = y1;
|
||||
p1 = h * 4, x1 = points[2 * h], y1 = points[2 * h + 1];
|
||||
vectors[p0 + 2] = vectors[p1] = y0 - y1;
|
||||
vectors[p0 + 3] = vectors[p1 + 1] = x1 - x0;
|
||||
}
|
||||
}
|
||||
render(context) {
|
||||
const buffer = context == null ? context = new Path : undefined;
|
||||
const {delaunay: {halfedges, inedges, hull}, circumcenters, vectors} = this;
|
||||
if (hull.length <= 1) return null;
|
||||
for (let i = 0, n = halfedges.length; i < n; ++i) {
|
||||
const j = halfedges[i];
|
||||
if (j < i) continue;
|
||||
const ti = Math.floor(i / 3) * 2;
|
||||
const tj = Math.floor(j / 3) * 2;
|
||||
const xi = circumcenters[ti];
|
||||
const yi = circumcenters[ti + 1];
|
||||
const xj = circumcenters[tj];
|
||||
const yj = circumcenters[tj + 1];
|
||||
this._renderSegment(xi, yi, xj, yj, context);
|
||||
}
|
||||
let h0, h1 = hull[hull.length - 1];
|
||||
for (let i = 0; i < hull.length; ++i) {
|
||||
h0 = h1, h1 = hull[i];
|
||||
const t = Math.floor(inedges[h1] / 3) * 2;
|
||||
const x = circumcenters[t];
|
||||
const y = circumcenters[t + 1];
|
||||
const v = h0 * 4;
|
||||
const p = this._project(x, y, vectors[v + 2], vectors[v + 3]);
|
||||
if (p) this._renderSegment(x, y, p[0], p[1], context);
|
||||
}
|
||||
return buffer && buffer.value();
|
||||
}
|
||||
renderBounds(context) {
|
||||
const buffer = context == null ? context = new Path : undefined;
|
||||
context.rect(this.xmin, this.ymin, this.xmax - this.xmin, this.ymax - this.ymin);
|
||||
return buffer && buffer.value();
|
||||
}
|
||||
renderCell(i, context) {
|
||||
const buffer = context == null ? context = new Path : undefined;
|
||||
const points = this._clip(i);
|
||||
if (points === null || !points.length) return;
|
||||
context.moveTo(points[0], points[1]);
|
||||
let n = points.length;
|
||||
while (points[0] === points[n-2] && points[1] === points[n-1] && n > 1) n -= 2;
|
||||
for (let i = 2; i < n; i += 2) {
|
||||
if (points[i] !== points[i-2] || points[i+1] !== points[i-1])
|
||||
context.lineTo(points[i], points[i + 1]);
|
||||
}
|
||||
context.closePath();
|
||||
return buffer && buffer.value();
|
||||
}
|
||||
*cellPolygons() {
|
||||
const {delaunay: {points}} = this;
|
||||
for (let i = 0, n = points.length / 2; i < n; ++i) {
|
||||
const cell = this.cellPolygon(i);
|
||||
if (cell) cell.index = i, yield cell;
|
||||
}
|
||||
}
|
||||
cellPolygon(i) {
|
||||
const polygon = new Polygon;
|
||||
this.renderCell(i, polygon);
|
||||
return polygon.value();
|
||||
}
|
||||
_renderSegment(x0, y0, x1, y1, context) {
|
||||
let S;
|
||||
const c0 = this._regioncode(x0, y0);
|
||||
const c1 = this._regioncode(x1, y1);
|
||||
if (c0 === 0 && c1 === 0) {
|
||||
context.moveTo(x0, y0);
|
||||
context.lineTo(x1, y1);
|
||||
} else if (S = this._clipSegment(x0, y0, x1, y1, c0, c1)) {
|
||||
context.moveTo(S[0], S[1]);
|
||||
context.lineTo(S[2], S[3]);
|
||||
}
|
||||
}
|
||||
contains(i, x, y) {
|
||||
if ((x = +x, x !== x) || (y = +y, y !== y)) return false;
|
||||
return this.delaunay._step(i, x, y) === i;
|
||||
}
|
||||
*neighbors(i) {
|
||||
const ci = this._clip(i);
|
||||
if (ci) for (const j of this.delaunay.neighbors(i)) {
|
||||
const cj = this._clip(j);
|
||||
// find the common edge
|
||||
if (cj) loop: for (let ai = 0, li = ci.length; ai < li; ai += 2) {
|
||||
for (let aj = 0, lj = cj.length; aj < lj; aj += 2) {
|
||||
if (ci[ai] == cj[aj]
|
||||
&& ci[ai + 1] == cj[aj + 1]
|
||||
&& ci[(ai + 2) % li] == cj[(aj + lj - 2) % lj]
|
||||
&& ci[(ai + 3) % li] == cj[(aj + lj - 1) % lj]
|
||||
) {
|
||||
yield j;
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_cell(i) {
|
||||
const {circumcenters, delaunay: {inedges, halfedges, triangles}} = this;
|
||||
const e0 = inedges[i];
|
||||
if (e0 === -1) return null; // coincident point
|
||||
const points = [];
|
||||
let e = e0;
|
||||
do {
|
||||
const t = Math.floor(e / 3);
|
||||
points.push(circumcenters[t * 2], circumcenters[t * 2 + 1]);
|
||||
e = e % 3 === 2 ? e - 2 : e + 1;
|
||||
if (triangles[e] !== i) break; // bad triangulation
|
||||
e = halfedges[e];
|
||||
} while (e !== e0 && e !== -1);
|
||||
return points;
|
||||
}
|
||||
_clip(i) {
|
||||
// degenerate case (1 valid point: return the box)
|
||||
if (i === 0 && this.delaunay.hull.length === 1) {
|
||||
return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
|
||||
}
|
||||
const points = this._cell(i);
|
||||
if (points === null) return null;
|
||||
const {vectors: V} = this;
|
||||
const v = i * 4;
|
||||
return V[v] || V[v + 1]
|
||||
? this._clipInfinite(i, points, V[v], V[v + 1], V[v + 2], V[v + 3])
|
||||
: this._clipFinite(i, points);
|
||||
}
|
||||
_clipFinite(i, points) {
|
||||
const n = points.length;
|
||||
let P = null;
|
||||
let x0, y0, x1 = points[n - 2], y1 = points[n - 1];
|
||||
let c0, c1 = this._regioncode(x1, y1);
|
||||
let e0, e1;
|
||||
for (let j = 0; j < n; j += 2) {
|
||||
x0 = x1, y0 = y1, x1 = points[j], y1 = points[j + 1];
|
||||
c0 = c1, c1 = this._regioncode(x1, y1);
|
||||
if (c0 === 0 && c1 === 0) {
|
||||
e0 = e1, e1 = 0;
|
||||
if (P) P.push(x1, y1);
|
||||
else P = [x1, y1];
|
||||
} else {
|
||||
let S, sx0, sy0, sx1, sy1;
|
||||
if (c0 === 0) {
|
||||
if ((S = this._clipSegment(x0, y0, x1, y1, c0, c1)) === null) continue;
|
||||
[sx0, sy0, sx1, sy1] = S;
|
||||
} else {
|
||||
if ((S = this._clipSegment(x1, y1, x0, y0, c1, c0)) === null) continue;
|
||||
[sx1, sy1, sx0, sy0] = S;
|
||||
e0 = e1, e1 = this._edgecode(sx0, sy0);
|
||||
if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
||||
if (P) P.push(sx0, sy0);
|
||||
else P = [sx0, sy0];
|
||||
}
|
||||
e0 = e1, e1 = this._edgecode(sx1, sy1);
|
||||
if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
||||
if (P) P.push(sx1, sy1);
|
||||
else P = [sx1, sy1];
|
||||
}
|
||||
}
|
||||
if (P) {
|
||||
e0 = e1, e1 = this._edgecode(P[0], P[1]);
|
||||
if (e0 && e1) this._edge(i, e0, e1, P, P.length);
|
||||
} else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
|
||||
return [this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax, this.xmin, this.ymin];
|
||||
}
|
||||
return P;
|
||||
}
|
||||
_clipSegment(x0, y0, x1, y1, c0, c1) {
|
||||
while (true) {
|
||||
if (c0 === 0 && c1 === 0) return [x0, y0, x1, y1];
|
||||
if (c0 & c1) return null;
|
||||
let x, y, c = c0 || c1;
|
||||
if (c & 0b1000) x = x0 + (x1 - x0) * (this.ymax - y0) / (y1 - y0), y = this.ymax;
|
||||
else if (c & 0b0100) x = x0 + (x1 - x0) * (this.ymin - y0) / (y1 - y0), y = this.ymin;
|
||||
else if (c & 0b0010) y = y0 + (y1 - y0) * (this.xmax - x0) / (x1 - x0), x = this.xmax;
|
||||
else y = y0 + (y1 - y0) * (this.xmin - x0) / (x1 - x0), x = this.xmin;
|
||||
if (c0) x0 = x, y0 = y, c0 = this._regioncode(x0, y0);
|
||||
else x1 = x, y1 = y, c1 = this._regioncode(x1, y1);
|
||||
}
|
||||
}
|
||||
_clipInfinite(i, points, vx0, vy0, vxn, vyn) {
|
||||
let P = Array.from(points), p;
|
||||
if (p = this._project(P[0], P[1], vx0, vy0)) P.unshift(p[0], p[1]);
|
||||
if (p = this._project(P[P.length - 2], P[P.length - 1], vxn, vyn)) P.push(p[0], p[1]);
|
||||
if (P = this._clipFinite(i, P)) {
|
||||
for (let j = 0, n = P.length, c0, c1 = this._edgecode(P[n - 2], P[n - 1]); j < n; j += 2) {
|
||||
c0 = c1, c1 = this._edgecode(P[j], P[j + 1]);
|
||||
if (c0 && c1) j = this._edge(i, c0, c1, P, j), n = P.length;
|
||||
}
|
||||
} else if (this.contains(i, (this.xmin + this.xmax) / 2, (this.ymin + this.ymax) / 2)) {
|
||||
P = [this.xmin, this.ymin, this.xmax, this.ymin, this.xmax, this.ymax, this.xmin, this.ymax];
|
||||
}
|
||||
return P;
|
||||
}
|
||||
_edge(i, e0, e1, P, j) {
|
||||
while (e0 !== e1) {
|
||||
let x, y;
|
||||
switch (e0) {
|
||||
case 0b0101: e0 = 0b0100; continue; // top-left
|
||||
case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break; // top
|
||||
case 0b0110: e0 = 0b0010; continue; // top-right
|
||||
case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break; // right
|
||||
case 0b1010: e0 = 0b1000; continue; // bottom-right
|
||||
case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break; // bottom
|
||||
case 0b1001: e0 = 0b0001; continue; // bottom-left
|
||||
case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break; // left
|
||||
}
|
||||
if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) {
|
||||
P.splice(j, 0, x, y), j += 2;
|
||||
}
|
||||
}
|
||||
if (P.length > 4) {
|
||||
for (let i = 0; i < P.length; i+= 2) {
|
||||
const j = (i + 2) % P.length, k = (i + 4) % P.length;
|
||||
if (P[i] === P[j] && P[j] === P[k]
|
||||
|| P[i + 1] === P[j + 1] && P[j + 1] === P[k + 1])
|
||||
P.splice(j, 2), i -= 2;
|
||||
}
|
||||
}
|
||||
return j;
|
||||
}
|
||||
_project(x0, y0, vx, vy) {
|
||||
let t = Infinity, c, x, y;
|
||||
if (vy < 0) { // top
|
||||
if (y0 <= this.ymin) return null;
|
||||
if ((c = (this.ymin - y0) / vy) < t) y = this.ymin, x = x0 + (t = c) * vx;
|
||||
} else if (vy > 0) { // bottom
|
||||
if (y0 >= this.ymax) return null;
|
||||
if ((c = (this.ymax - y0) / vy) < t) y = this.ymax, x = x0 + (t = c) * vx;
|
||||
}
|
||||
if (vx > 0) { // right
|
||||
if (x0 >= this.xmax) return null;
|
||||
if ((c = (this.xmax - x0) / vx) < t) x = this.xmax, y = y0 + (t = c) * vy;
|
||||
} else if (vx < 0) { // left
|
||||
if (x0 <= this.xmin) return null;
|
||||
if ((c = (this.xmin - x0) / vx) < t) x = this.xmin, y = y0 + (t = c) * vy;
|
||||
}
|
||||
return [x, y];
|
||||
}
|
||||
_edgecode(x, y) {
|
||||
return (x === this.xmin ? 0b0001
|
||||
: x === this.xmax ? 0b0010 : 0b0000)
|
||||
| (y === this.ymin ? 0b0100
|
||||
: y === this.ymax ? 0b1000 : 0b0000);
|
||||
}
|
||||
_regioncode(x, y) {
|
||||
return (x < this.xmin ? 0b0001
|
||||
: x > this.xmax ? 0b0010 : 0b0000)
|
||||
| (y < this.ymin ? 0b0100
|
||||
: y > this.ymax ? 0b1000 : 0b0000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user