From 7c7d0956862dab8c84b90ded1313cc8f25c0317c Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Sun, 27 Sep 2020 16:54:46 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#48208=20[d3-delaun?= =?UTF-8?q?ay]=20Update=20types=20to=205.0=20by=20@Methuselah96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/d3-delaunay/d3-delaunay-tests.ts | 12 +- types/d3-delaunay/index.d.ts | 163 ++++++++----------------- 2 files changed, 58 insertions(+), 117 deletions(-) diff --git a/types/d3-delaunay/d3-delaunay-tests.ts b/types/d3-delaunay/d3-delaunay-tests.ts index 7f3103f60e..78002c8481 100644 --- a/types/d3-delaunay/d3-delaunay-tests.ts +++ b/types/d3-delaunay/d3-delaunay-tests.ts @@ -39,14 +39,8 @@ for (let i = 0, l = halfedges.length; i < l; i++) { const pjx = points[tj * 2]; const pjy = points[tj * 2 + 1]; } -for (let n = hull.next; n !== hull; n = n.next) { - const i: number = n.i; - const x: number = n.x; - const y: number = n.y; - const t: number = n.t; - const next: d3.Delaunay.Node = n.next; - const prev: d3.Delaunay.Node = n.prev; - const removed: boolean = n.removed; +for (let i = 0, l = hull.length; i < l; i++) { + const a = hull[i]; } for (let i = 0, l = triangles.length; i < l; i++) { const t0 = triangles[i * 3 + 0]; @@ -83,6 +77,8 @@ for (const p of defaultDelaunayFromArray.trianglePolygon(0)) { const y = p[1]; } +defaultDelaunayFromArray.update(); + // Test Voronoi class const v = defaultDelaunayFromArray.voronoi(); diff --git a/types/d3-delaunay/index.d.ts b/types/d3-delaunay/index.d.ts index c5d10e8aa3..c2661464c6 100644 --- a/types/d3-delaunay/index.d.ts +++ b/types/d3-delaunay/index.d.ts @@ -1,12 +1,33 @@ -// Type definitions for d3-delaunay 4.1 +// Type definitions for d3-delaunay 5.0 // Project: https://github.com/d3/d3-delaunay // Definitions by: Bradley Odell +// Nathan Bierema // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /** * Delaunay triangulation */ export class Delaunay

{ + /** + * Returns the Delaunay triangulation for the given flat array [x0, y0, x1, y1, …] of points. + */ + constructor(points: ArrayLike); + + /** + * Returns the Delaunay triangulation for the given array or iterable of points where each point is an array in the form: [x, y]. + */ + static from(points: ArrayLike|Iterable): Delaunay; + /** + * Returns the Delaunay triangulation for the given array or iterable of points. + * Otherwise, the getX and getY functions are invoked for each point in order, and must return the respective x- and y-coordinate for each point. + * If that is specified, the functions getX and getY are invoked with that as this. + * (See Array.from for reference.) + */ + static from

(points: ArrayLike

|Iterable

, + getX: Delaunay.GetCoordinate|Iterable

>, + getY: Delaunay.GetCoordinate|Iterable

>, + that?: any): Delaunay

; + /** * 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. @@ -20,10 +41,10 @@ export class Delaunay

{ halfedges: Int32Array; /** - * An arbitrary node on the convex hull. - * The convex hull is represented as a circular doubly-linked list of nodes. + * An Int32Array of point indexes that form the convex hull in counterclockwise order. + * If the points are collinear, returns them ordered. */ - hull: Delaunay.Node; + hull: Uint32Array; /** * The triangle vertex indices as an Uint32Array [i0, j0, k0, i1, j1, k1, ...]. @@ -39,33 +60,6 @@ export class Delaunay

{ */ inedges: Int32Array; - /** - * The outgoing halfedge indexes as a Int32Array [e0, e1, e2, ...]. - * For each point i on the convex hull, outedges[i] is the halfedge index e of the corresponding outgoing halfedge; for other points, the halfedge index is -1. - */ - outedges: Int32Array; - - /** - * Returns the Delaunay triangulation for the given flat array [x0, y0, x1, y1, …] of points. - */ - constructor(points: ArrayLike); - - /** - * Returns the Delaunay triangulation for the given array or iterable of points where each point is an array in the form: [x, y]. - */ - static from(points: ArrayLike|Iterable): Delaunay; - - /** - * Returns the Delaunay triangulation for the given array or iterable of points. - * Otherwise, the getX and getY functions are invoked for each point in order, and must return the respective x- and y-coordinate for each point. - * If that is specified, the functions getX and getY are invoked with that as this. - * (See Array.from for reference.) - */ - static from

(points: ArrayLike

|Iterable

, - getX: Delaunay.GetCoordinate|Iterable

>, - getY: Delaunay.GetCoordinate|Iterable

>, - that?: any): Delaunay

; - /** * 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. @@ -78,26 +72,10 @@ export class Delaunay

{ */ neighbors(i: number): IterableIterator; - /** - * Returns the closed polygon [[x0, y0], [x1, y1], ..., [x0, y0]] representing the convex hull. - */ - hullPolygon(): Delaunay.Polygon; - - /** - * Returns the closed polygon [[x0, y0], [x1, y1], [x2, y2], [x0, y0]] representing the triangle i. - */ - trianglePolygon(i: number): Delaunay.Triangle; - - /** - * Returns an iterable over the polygons for each triangle, in order. - */ - trianglePolygons(): IterableIterator; - /** * Renders the edges of the Delaunay triangulation to an SVG path string. */ render(): string; - /** * 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. @@ -108,7 +86,6 @@ export class Delaunay

{ * Renders the convex hull of the Delaunay triangulation to an SVG path string. */ renderHull(): string; - /** * 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. @@ -119,7 +96,6 @@ export class Delaunay

{ * Renders triangle i of the Delaunay triangulation to an SVG path string. */ renderTriangle(i: number): string; - /** * 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. @@ -130,12 +106,10 @@ export class Delaunay

{ * Renders the input points of the Delaunay triangulation to an SVG path string as circles with radius 2. */ renderPoints(): string; - /** * Renders the input points of the Delaunay triangulation to an SVG path string as circles with the specified radius. */ renderPoints(context: undefined, radius: number): string; - /** * 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. @@ -143,6 +117,25 @@ export class Delaunay

{ */ renderPoints(context: Delaunay.MoveContext & Delaunay.ArcContext, radius?: number): void; + /** + * Returns the closed polygon [[x0, y0], [x1, y1], ..., [x0, y0]] representing the convex hull. + */ + hullPolygon(): Delaunay.Polygon; + + /** + * Returns the closed polygon [[x0, y0], [x1, y1], [x2, y2], [x0, y0]] representing the triangle i. + */ + trianglePolygon(i: number): Delaunay.Triangle; + /** + * Returns an iterable over the polygons for each triangle, in order. + */ + trianglePolygons(): IterableIterator; + + /** + * Updates the triangulation after the points have been modified in-place — useful for Lloyd’s relaxation. + */ + update(): void; + /** * Returns the Voronoi diagram for the associated points. * When rendering, the diagram will be clipped to the specified bounds = [xmin, ymin, xmax, ymax]. @@ -178,46 +171,6 @@ export namespace Delaunay { */ type GetCoordinate = (point: P, i: number, points: PS) => number; - /** - * A point node on a convex hull (represented as a circular linked list). - */ - interface Node { - /** - * The index of the associated point. - */ - i: number; - - /** - * The x-coordinate of the associated point. - */ - x: number; - - /** - * The y-coordinate of the associated point. - */ - y: number; - - /** - * The index of the (incoming or outgoing?) associated halfedge. - */ - t: number; - - /** - * The previous node on the hull. - */ - prev: Node; - - /** - * The next node on the hull. - */ - next: Node; - - /** - * Whether the node has been removed from the linked list. - */ - removed: boolean; - } - /** * An interface for the rect() method of the CanvasPathMethods API. */ @@ -302,32 +255,16 @@ export class Voronoi

{ xmax: number; ymax: number; - /** - * Internally used to implement Delaunay#voronoi. - */ - constructor(delaunay: Delaunay

, bounds: Delaunay.Bounds); - /** * 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.) */ contains(i: number, x: number, y: number): boolean; - /** - * Returns the convex, closed polygon [[x0, y0], [x1, y1], ..., [x0, y0]] representing the cell for the specified point i. - */ - cellPolygon(i: number): Delaunay.Polygon; - - /** - * Returns an iterable over the polygons for each cell, in order. - */ - cellPolygons(): IterableIterator; - /** * Renders the mesh of Voronoi cells to an SVG path string. */ render(): string; - /** * 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. @@ -338,7 +275,6 @@ export class Voronoi

{ * Renders the viewport extent to an SVG path string. */ renderBounds(): string; - /** * Renders the viewport extent to the specified context. * The specified context must implement the context.rect method from the CanvasPathMethods API. @@ -350,10 +286,19 @@ export class Voronoi

{ * Renders the cell with the specified index i to an SVG path string. */ renderCell(i: number): string; - /** * 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. */ renderCell(i: number, context: Delaunay.MoveContext & Delaunay.LineContext & Delaunay.ClosableContext): void; + + /** + * Returns an iterable over the polygons for each cell, in order. + */ + cellPolygons(): IterableIterator; + + /** + * Returns the convex, closed polygon [[x0, y0], [x1, y1], ..., [x0, y0]] representing the cell for the specified point i. + */ + cellPolygon(i: number): Delaunay.Polygon; }