{"bugs":{"url":"https://github.com/d3/d3-delaunay/issues"},"dist":{"shasum":"b9841343cb930b249fbe8c75d3ca52e5e2aeb6df","tarball":"https://registry.npmjs.org/d3-delaunay/-/d3-delaunay-3.0.0-alpha.1.tgz","fileCount":9,"integrity":"sha512-2VqQkD/1YGQDMMah1fblKldRzTAyYrs4UAMW3MfmHxFGKJyggGgVm/GU2okuE0zLFhzOHrepV8ys1GPW9f7emQ==","signatures":[{"sig":"MEYCIQD9nQ9PWy1av+82CIDKPzm3pBtiQsML1zOiIrF2I6ThbgIhAJhG3HsBzfbK+ScuAtYbVvgOTpUk08HXLaFrUAEUglTh","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":72983},"main":"dist/d3-delaunay.js","name":"d3-delaunay","unpkg":"dist/d3-delaunay.min.js","author":{"url":"https://bost.ocks.org/mike","name":"Mike Bostock"},"module":"src/index.js","readme":"# d3-delaunay\n\n<p align=\"center\"><img src=\"https://raw.githubusercontent.com/d3/d3-delaunay/master/img/voronator.jpg\" width=\"300\">\n<p align=\"center\">Georgy “The Voronator” Voronoy\n\nThis 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.\n\nFor an interactive explanation of how this library works, see [The Delaunay’s Dual](https://beta.observablehq.com/@mbostock/the-delaunays-dual).\n\n## Installing\n\nTo 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, ES5 and ES6+ environments are supported. In vanilla, a `d3` global is exported.\n\n```js\nimport {Delaunay} from \"d3-delaunay\";\n\nconst points = [[0, 0], [0, 1], [1, 0], [1, 1]];\nconst delaunay = Delaunay.from(points);\nconst voronoi = delaunay.voronoi([0, 0, 960, 500]);\n```\n\n## API Reference\n\n### Delaunay\n\n<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\")\n\nReturns the Delaunay triangulation for the given flat array [*x0*, *y0*, *x1*, *y1*, …] of *points*.\n\n```js\nconst delaunay = new Delaunay(Float64Array.of(0, 0, 0, 1, 1, 0, 1, 1));\n```\n\n<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\")\n\nReturns 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.)\n\n```js\nconst delaunay = Delaunay.from([[0, 0], [0, 1], [1, 0], [1, 1]]);\n```\n\n<a href=\"#delaunay_points\" name=\"delaunay_points\">#</a> <i>delaunay</i>.<b>points</b>\n\nThe 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).\n\n<a href=\"#delaunay_halfedges\" name=\"delaunay_halfedges\">#</a> <i>delaunay</i>.<b>halfedges</b>\n\nThe half-edge indexes as an Int32Array [*j0*, *j1*, …]. For each index 0 ≤ *i* < *halfedges*.length, there is a half-edge 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:\n\n```js\nconst {points, halfedges, triangles} = delaunay;\nfor (let i = 0, n = halfedges.length; i < n; ++i) {\n  const j = halfedges[i];\n  if (j < i) continue;\n  const ti = triangles[i] * 2;\n  const tj = triangles[j] * 2;\n  context.moveTo(points[ti], points[ti + 1]);\n  context.lineTo(points[tj], points[tj + 1]);\n}\n```\n\nSee also [*delaunay*.render](#delaunay_render).\n\n<a href=\"#delaunay_hull\" name=\"delaunay_hull\">#</a> <i>delaunay</i>.<b>hull</b>\n\nThe convex hull as an a Uint32Array [*i0*, *i1*, …] of triangle vertex indexes. For example, to render the exterior edges of the Delaunay triangulation:\n\n```js\nconst {hull, triangles} = delaunay;\nconst n = hull.length;\nlet i0, i1 = triangles[hull[n - 1]] * 2;\nfor (let i = 0; i < n; ++i) {\n  i0 = i1, i1 = triangles[hull[i]] * 2;\n  context.moveTo(points[i0], points[i0 + 1]);\n  context.lineTo(points[i1], points[i1 + 1]);\n}\n```\n\nSee also [*delaunay*.renderHull](#delaunay_renderHull).\n\n<a href=\"#delaunay_triangles\" name=\"delaunay_triangles\">#</a> <i>delaunay</i>.<b>triangles</b>\n\nThe triangle vertex indexes as an Int32Array [*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*:\n\n```js\nconst {points, triangles} = delaunay;\nconst t0 = triangles[i * 3 + 0] * 2;\nconst t1 = triangles[i * 3 + 1] * 2;\nconst t2 = triangles[i * 3 + 2] * 2;\ncontext.moveTo(points[t0], points[t0 + 1]);\ncontext.lineTo(points[t1], points[t1 + 1]);\ncontext.lineTo(points[t2], points[t2 + 1]);\ncontext.closePath();\n```\n\nSee also [*delaunay*.renderTriangle](#delaunay_renderTriangle).\n\n<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\")\n\n<img alt=\"delaunay.render\" src=\"https://raw.githubusercontent.com/d3/d3-delaunay/master/img/delaunay-mesh.png\">\n\nRenders 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).\n\n<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\")\n\n<img alt=\"delaunay.renderHull\" src=\"https://raw.githubusercontent.com/d3/d3-delaunay/master/img/delaunay-hull.png\">\n\nRenders 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).\n\n<a href=\"#delaunay_renderTriangle\" name=\"delaunay_renderTriangle\">#</a> <i>delaunay</i>.<b>renderTriangle</b>(<i>context</i>) [<>](https://github.com/d3/d3-delaunay/blob/master/src/delaunay.js \"Source\")\n\n<img alt=\"delaunay.renderTriangle\" src=\"https://raw.githubusercontent.com/d3/d3-delaunay/master/img/delaunay-triangle.png\">\n\nRenders 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).\n\n<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\")\n\nReturns 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://beta.observablehq.com/@mbostock/to-infinity-and-back-again) for an interactive explanation of Voronoi cell clipping.\n\n### Voronoi\n\n<a href=\"#voronoi_delaunay\" name=\"voronoi_delaunay\">#</a> <i>voronoi</i>.<b>delaunay</b>\n\nThe Voronoi diagram’s associated [Delaunay triangulation](#delaunay).\n\n<a href=\"#voronoi_circumcenters\" name=\"voronoi_circumcenters\">#</a> <i>voronoi</i>.<b>circumcenters</b>\n\nThe [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.\n\n<a href=\"#voronoi_edges\" name=\"voronoi_edges\">#</a> <i>voronoi</i>.<b>edges</b>\n\n… TODO The triangle indexes [*i0*, *i1*, …] in counterclockwise order. Together with the start and end vectors [*cell*.v0](#cell_v0) and [*cell*.vn](#cell_vn) if any, the [circumcenters](#voronoi_circumcenters) of these triangles form the exterior polygon of the cell. For coincident points, only the cell associated with the first input point is non-null.\n\n<a href=\"#voronoi_index\" name=\"voronoi_index\">#</a> <i>voronoi</i>.<b>index</b>\n\n… TODO The triangle indexes [*i0*, *i1*, …] in counterclockwise order. Together with the start and end vectors [*cell*.v0](#cell_v0) and [*cell*.vn](#cell_vn) if any, the [circumcenters](#voronoi_circumcenters) of these triangles form the exterior polygon of the cell. For coincident points, only the cell associated with the first input point is non-null.\n\n<a href=\"#voronoi_vectors\" name=\"voronoi_vectors\">#</a> <i>voronoi</i>.<b>vectors</b>\n\n… TODO The start vector [*vx0*, *vy0*], if the cell’s associated point is on the [convex hull](#delaunay_hull) of the Delaunay triangulation. Together with the cell’s [triangle circumcenters](#cell_triangles) and end vector [*cell*.vn](#cell_vn) if any, the start vector forms the exterior polygon of the cell. The end vector [*vxn*, *vyn*], if the cell’s associated point is on the [convex hull](#delaunay_hull) of the Delaunay triangulation. Together with the cell’s [triangle circumcenters](#cell_triangles) and start vector [*cell*.v0](#cell_v0) if any, the end vector forms the exterior polygon of the cell.\n\n\n<a href=\"#voronoi_xmin\" name=\"voronoi_xmin\">#</a> <i>voronoi</i>.<b>xmin</b><br>\n<a href=\"#voronoi_ymin\" name=\"voronoi_ymin\">#</a> <i>voronoi</i>.<b>ymin</b><br>\n<a href=\"#voronoi_xmax\" name=\"voronoi_xmax\">#</a> <i>voronoi</i>.<b>xmax</b><br>\n<a href=\"#voronoi_ymax\" name=\"voronoi_ymax\">#</a> <i>voronoi</i>.<b>ymax</b><br>\n\nThe 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)).\n\n<a href=\"#voronoi_find\" name=\"voronoi_find\">#</a> <i>voronoi</i>.<b>find</b>(<i>x</i>, <i>y</i>[, <i>i</i>]) [<>](https://github.com/d3/d3-delaunay/blob/master/src/voronoi.js \"Source\")\n\nReturns the index of the cell that contains the specified point ⟨*x*, *y*⟩. The search is started at the specified point *i*. If *i* is not specified, it defaults to zero. (This method is not affected by the associated Voronoi diagram’s viewport [bounds](#voronoi_xmin).)\n\n<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\")\n\nReturns 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).)\n\n<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\")\n\n<img alt=\"voronoi.render\" src=\"https://raw.githubusercontent.com/d3/d3-delaunay/master/img/voronoi-mesh.png\">\n\nRenders 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).\n\n<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\")\n\n<img alt=\"voronoi.renderBounds\" src=\"https://raw.githubusercontent.com/d3/d3-delaunay/master/img/voronoi-bounds.png\">\n\nRenders 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).\n\n<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\")\n\n<img alt=\"cell.render\" src=\"https://raw.githubusercontent.com/d3/d3-delaunay/master/img/spectral.png\">\n\nRenders 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).\n","gitHead":"bcdfe5546a8696ce3f457d2ac62bf6c178781397","license":"ISC","scripts":{"test":"tape -r esm 'test/**/*-test.js'","build":"rm -rf dist && mkdir dist && rollup -c","postpublish":"git push && git push --tags && zip -j dist/d3-delaunay.zip -- LICENSE README.md dist/d3-delaunay.js dist/d3-delaunay.min.js","prepublishOnly":"yarn build && yarn test"},"_npmUser":{"name":"mbostock","email":"mike@ocks.org"},"homepage":"https://github.com/d3/d3-delaunay","keywords":["voronoi","delaunay","geometry"],"repository":{"url":"git+https://github.com/d3/d3-delaunay.git","type":"git"},"_npmVersion":"5.6.0","description":"Compute the Voronoi diagram of a set of two-dimensional points.","directories":{},"maintainers":[{"name":"mbostock","email":"mike@ocks.org"}],"_nodeVersion":"8.9.4","contributors":[{"url":"http://agafonkin.com/en/","name":"Vladimir Agafonkin"}],"dependencies":{"delaunator":"^2.0.0"},"publishConfig":{"tag":"next"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"esm":"^3.0.7","tape":"4","rollup":"^0.57.1","@observablehq/tape":"~0.0.1","rollup-plugin-uglify":"^3.0.0","rollup-plugin-node-resolve":"^3.3.0"},"_npmOperationalInternal":{"tmp":"tmp/d3-delaunay_3.0.0-alpha.1_1523392739151_0.8423757779081258","host":"s3://npm-registry-packages"},"_id":"d3-delaunay@3.0.0-alpha.1","version":"3.0.0-alpha.1"}