Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions types/delaunator/delaunator-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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];
const zipped = new Delaunator(zippedPoints);
const zippedCoords = zipped.coords; // $ExpectType number[]

// Default [x, y]
const defaultPoints = [
Expand Down Expand Up @@ -45,7 +46,7 @@ Delaunator.from(customPoints, getX, getY);
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 coords = d.coords; // $ExpectType Float64Array
const coordinates: number[][][] = [];
for (let i = 0; i < triangles.length; i += 3) {
coordinates.push([defaultPoints[triangles[i]], defaultPoints[triangles[i + 1]], defaultPoints[triangles[i + 2]]]);
Expand All @@ -65,5 +66,5 @@ for (let i = 0; i < triangles.length; i += 3) {
JSON.stringify(coordinates) === JSON.stringify(coordinates2);

// update call
(zipped.coords as Float64Array)[0] = 1;
zipped.coords[0] = 1;
zipped.update();
14 changes: 9 additions & 5 deletions types/delaunator/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare class Delaunator<P> {
declare class Delaunator<A extends ArrayLike<number>> {
/**
* A Uint32Array array of triangle vertex indices (each group of three numbers forms a triangle).
* All triangles are directed counterclockwise.
Expand All @@ -22,24 +22,28 @@ declare class Delaunator<P> {
/**
* 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;
coords: A;

/**
* 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>);
constructor(points: A);

/**
* Constructs a delaunay triangulation object given an array of points ([x, y] by default).
*/
static from(points: ArrayLike<ArrayLike<number>>): Delaunator<ArrayLike<number>>;
static from(points: ArrayLike<ArrayLike<number>>): Delaunator<Float64Array>;

/**
* 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>;
static from<P>(
points: ArrayLike<P>,
getX: (point: P) => number,
getY: (point: P) => number
): Delaunator<Float64Array>;

/**
* Updates the triangulation if you modified delaunay.coords values in place, avoiding expensive memory
Expand Down