mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Updated "delaunator" typings to version 3.0 (#35165)
* Updated "delaunator" typings to version 3.0 * delaunator: fix wrong $ExpectType in test * delaunator: export class -> export default class * delaunator: handle both: UMD & ES module files. * TypeScript >= 2.7 required * flag 'esModuleInterop' in tsconfig required * thanks @weswigham for the help
This commit is contained in:
parent
89341bfde5
commit
d58e1fcc50
@ -1,4 +1,4 @@
|
||||
import * as Delaunator from 'delaunator';
|
||||
import Delaunator from 'delaunator';
|
||||
|
||||
// Zipped points [x0, y0, x1, y1, ...]
|
||||
const zippedPoints = [168, 180, 168, 178, 168, 179, 168, 181, 168, 183, 167, 183, 167, 184];
|
||||
@ -13,7 +13,7 @@ interface CustomPoint {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
const customPoints = [{x: 168, y: 180}, {x: 168, y: 178}, {x: 168, y: 179}, {x: 168, y: 181}, {x: 168, y: 183}, {x: 167, y: 183}, {x: 167, y: 184}];
|
||||
const customPoints = [{ x: 168, y: 180 }, { x: 168, y: 178 }, { x: 168, y: 179 }, { x: 168, y: 181 }, { x: 168, y: 183 }, { x: 167, y: 183 }, { x: 167, y: 184 }];
|
||||
|
||||
const getX = (point: CustomPoint) => point.x;
|
||||
const getY = (point: CustomPoint) => point.y;
|
||||
@ -22,9 +22,10 @@ Delaunator.from(customPoints, point => point.x, point => point.y);
|
||||
Delaunator.from(customPoints, getX, getY);
|
||||
|
||||
// To get the coordinates of all triangles, use:
|
||||
const triangles = d.triangles;
|
||||
const halfedges = d.halfedges;
|
||||
const hull = d.hull;
|
||||
const triangles = d.triangles; // $ExpectType Uint32Array
|
||||
const halfedges = d.halfedges; // $ExpectType Int32Array
|
||||
const hull = d.hull; // $ExpectType Uint32Array
|
||||
const coords = d.coords; // $ExpectType ArrayLike<number> | Float64Array
|
||||
const coordinates: number[][][] = [];
|
||||
for (let i = 0; i < triangles.length; i += 3) {
|
||||
coordinates.push([
|
||||
@ -33,3 +34,16 @@ for (let i = 0; i < triangles.length; i += 3) {
|
||||
defaultPoints[triangles[i + 2]]
|
||||
]);
|
||||
}
|
||||
|
||||
// Or use Delaunator.coords (but coords is a flat array in the form of [x0, y0, x1, y1, ...])
|
||||
const coordinates2: number[][][] = [];
|
||||
for (let i = 0; i < triangles.length; i += 3) {
|
||||
coordinates2.push([
|
||||
[coords[triangles[i] * 2], coords[triangles[i] * 2 + 1]],
|
||||
[coords[triangles[i + 1] * 2], coords[triangles[i + 1] * 2 + 1]],
|
||||
[coords[triangles[i + 2] * 2], coords[triangles[i + 2] * 2 + 1]]
|
||||
]);
|
||||
}
|
||||
|
||||
// both approaches should give the same result
|
||||
JSON.stringify(coordinates) === JSON.stringify(coordinates2);
|
||||
|
||||
34
types/delaunator/index.d.ts
vendored
34
types/delaunator/index.d.ts
vendored
@ -1,17 +1,20 @@
|
||||
// Type definitions for delaunator 2.0
|
||||
// Type definitions for delaunator 3.0
|
||||
// Project: https://github.com/mapbox/delaunator#readme
|
||||
// Definitions by: Denis Carriere <https://github.com/DenisCarriere>
|
||||
// Bradley Odell <https://github.com/BTOdell>
|
||||
// Tobias Kraus <https://github.com/tobiaskraus>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.7
|
||||
|
||||
declare class Delaunator<P> {
|
||||
/**
|
||||
* A flat Uint32Array array of triangle vertex indices (each group of three numbers forms a triangle). All triangles are directed counterclockwise.
|
||||
* A Uint32Array array of triangle vertex indices (each group of three numbers forms a triangle).
|
||||
* All triangles are directed counterclockwise.
|
||||
*/
|
||||
triangles: Uint32Array;
|
||||
|
||||
/**
|
||||
* A flat Int32Array array of triangle half-edge indices that allows you to traverse the triangulation.
|
||||
* A Int32Array array of triangle half-edge indices that allows you to traverse the triangulation.
|
||||
* i-th half-edge in the array corresponds to vertex triangles[i] the half-edge is coming from.
|
||||
* halfedges[i] is the index of a twin half-edge in an adjacent triangle (or -1 for outer half-edges on the convex hull).
|
||||
*
|
||||
@ -20,36 +23,31 @@ declare class Delaunator<P> {
|
||||
halfedges: Int32Array;
|
||||
|
||||
/**
|
||||
* A circular doubly-linked list that holds a convex hull of the delaunay triangulation.
|
||||
* A Uint32Array array of indices that reference points on the convex hull of the input data, counter-clockwise.
|
||||
*/
|
||||
hull: Delaunator.Node;
|
||||
hull: Uint32Array;
|
||||
|
||||
/**
|
||||
* An array of input coordinates in the form [x0, y0, x1, y1, ....], of the type provided in the constructor (or Float64Array if you used Delaunator.from).
|
||||
*/
|
||||
coords: ArrayLike<number> | Float64Array;
|
||||
|
||||
/**
|
||||
* Constructs a delaunay triangulation object given a typed array of point coordinates of the form: [x0, y0, x1, y1, ...].
|
||||
* (use a typed array for best performance).
|
||||
*/
|
||||
constructor(points: ArrayLike<number>);
|
||||
|
||||
/**
|
||||
* Constructs a delaunay triangulation object given an array of points (e.g. [x, y]). Duplicate points are skipped.
|
||||
* Constructs a delaunay triangulation object given an array of points ([x, y] by default).
|
||||
*/
|
||||
static from(points: ArrayLike<ArrayLike<number>>): Delaunator<ArrayLike<number>>;
|
||||
|
||||
/**
|
||||
* Constructs a delaunay triangulation object given an array of custom points. Duplicate points are skipped.
|
||||
* getX and getY are optional functions for custom point formats. Duplicate points are skipped.
|
||||
*/
|
||||
static from<P>(points: ArrayLike<P>, getX: (point: P) => number, getY: (point: P) => number): Delaunator<P>;
|
||||
}
|
||||
|
||||
declare namespace Delaunator {
|
||||
interface Node {
|
||||
i: number;
|
||||
x: number;
|
||||
y: number;
|
||||
t: number;
|
||||
prev: Node|null;
|
||||
next: Node|null;
|
||||
removed: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
export = Delaunator;
|
||||
|
||||
@ -14,7 +14,8 @@
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user