Options
All
• Public
• Public/Protected
• All

# Class Delaunay

Delaunay is a Group of Pts that can generate Delaunay and Voronoi tessellations. The triangulation algorithm is ported from Pt This implementation is based on Paul Bourke's algorithm with reference to its javascript implementation by ironwallaby

### Indexable

[n: number]: Pt

Delaunay is a Group of Pts that can generate Delaunay and Voronoi tessellations. The triangulation algorithm is ported from Pt This implementation is based on Paul Bourke's algorithm with reference to its javascript implementation by ironwallaby

## Properties

_id: string

### Private _mesh

_mesh: DelaunayMesh = []

### Static length

length: number

Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.

## Accessors

### id

• get id(): string
• set id(s: string): void

### p1

• get p1(): Pt
• The first Pt in this group

### p2

• get p2(): Pt
• The second Pt in this group

### p3

• get p3(): Pt
• The third Pt in this group

### p4

• get p4(): Pt
• The forth Pt in this group

### q1

• get q1(): Pt
• The last Pt in this group

### q2

• get q2(): Pt
• The second-last Pt in this group

### q3

• get q3(): Pt
• The third-last Pt in this group

### q4

• get q4(): Pt
• The forth-last Pt in this group

## Methods

• Apply this group as a matrix and calculate matrix addition

#### Parameters

• ##### g: GroupLike | number[][] | number

a scalar number, an array of numeric arrays, or a group of Pt

a new Group

### \$matrixMultiply

• \$matrixMultiply(g: GroupLike | number, transposed?: boolean, elementwise?: boolean): Group
• Apply this group as a matrix and calculate matrix multiplication

#### Parameters

• ##### g: GroupLike | number

a scalar number, an array of numeric arrays, or a Group of K Pts, each with N dimensions (K-rows, N-columns) -- or if transposed is true, then N Pts with K dimensions

• ##### Default value transposed: boolean = false

(Only applicable if it's not elementwise multiplication) If true, then a and b's columns should match (ie, each Pt should have the same dimensions). Default is `false`.

• ##### Default value elementwise: boolean = false

if true, then the multiplication is done element-wise. Default is `false`.

#### Returns Group

If not elementwise, this will return a new Group with M Pt, each with N dimensions (M-rows, N-columns).

### \$zip

• \$zip(defaultValue?: number | boolean, useLongest?: boolean): Group
• Zip a group of Pt. eg, [[1,2],[3,4],[5,6]] => [[1,3,5],[2,4,6]]

#### Parameters

• ##### Default value defaultValue: number | boolean = undefined

a default value to fill if index out of bound. If not provided, it will throw an error instead.

• ##### Default value useLongest: boolean = false

If true, find the longest list of values in a Pt and use its length for zipping. Default is false, which uses the first item's length for zipping.

### Protected _cache

• _cache(o: any): void
• Record a DelaunayShape in the mesh

#### Parameters

• ##### o: any

DelaunayShape instance

### Protected _circum

• Get a circumcircle and triangle from 3 points in a list of points

#### Parameters

index 1

index 2

index 3

• ##### tri: GroupLike | false

a Group representing a triangle, or `false` to create it from indices

• ##### Default value pts: GroupLike = this

a Group of Pts

### Protected _superTriangle

• _superTriangle(): Group
• Get the initial "super triangle" that contains all the points in this set

#### Returns Group

a Group representing a triangle

### Protected _triangle

• Get a triangle from 3 points in a list of points

#### Parameters

index 1

index 2

index 3

• ##### Default value pts: GroupLike = this

a Group of Pts

#### Returns Group

• Add scalar or vector values to this group's Pts.

#### Parameters

• ##### Rest...args: any[]

a list of numbers, an array of number, or an object with {x,y,z,w} properties

### anchorFrom

• anchorFrom(ptOrIndex?: PtLike | number): void
• Anchor all the Pts in this Group by its absolute position from a target Pt. (ie, add all Pt with the target anchor to get an absolute position). All the Pts' values will be updated.

#### Parameters

• ##### Default value ptOrIndex: PtLike | number = 0

a Pt, or a numeric index to target a specific Pt in this Group

### anchorTo

• anchorTo(ptOrIndex?: PtLike | number): void
• Anchor all the Pts in this Group using a target Pt as origin. (ie, subtract all Pt with the target anchor to get a relative position). All the Pts' values will be updated.

#### Parameters

• ##### Default value ptOrIndex: PtLike | number = 0

a Pt, or a numeric index to target a specific Pt in this Group

### boundingBox

• Find the rectangular bounding box of this group's Pts.

#### Returns Group

a Group of 2 Pts representing the top-left and bottom-right of the rectangle

### centroid

• centroid(): Pt
• Find the centroid of this group's Pts, which is the average middle point.

### clone

• Depp clone this group and its Pts

### delaunay

• Generate Delaunay triangles. This function also caches the mesh that is used to generate Voronoi tessellation in `voronoi()`.

#### Parameters

• ##### Default value triangleOnly: boolean = true

if true, returns an array of triangles in Groups, otherwise return the whole DelaunayShape

#### Returns GroupLike[] | DelaunayShape[]

an array of Groups or an array of DelaunayShapes `{i, j, k, triangle, circle}` which records the indices of the vertices, and the calculated triangles and circumcircles

### divide

• divide(...args: any[]): this
• Divide this group's Pts over scalar or vector values (as element-wise)

#### Parameters

• ##### Rest...args: any[]

a list of numbers, an array of number, or an object with {x,y,z,w} properties

### forEachPt

• forEachPt(ptFn: string, ...args: any[]): this
• Update each Pt in this Group with a Pt function

#### Parameters

• ##### ptFn: string

string name of an existing Pt function. Note that the function must return Pt.

• ##### Rest...args: any[]

arguments for the function specified in ptFn

### insert

• insert(pts: GroupLike, index?: number): this
• Insert a Pt into this group

#### Parameters

• ##### pts: GroupLike

Another group of Pts

• ##### Default value index: number = 0

the index position to insert into

### interpolate

• interpolate(t: number): Pt
• Get an interpolated point on the line segments defined by this Group

#### Parameters

• ##### t: number

a value between 0 to 1 usually

### lines

• Get all the line segments (ie, edges in a graph) of this group

### mesh

• Get the cached mesh. The mesh is an array of objects, each of which representing the enclosing triangles around a Pt in this Delaunay group

#### Returns DelaunayMesh

an array of objects that store a series of DelaunayShapes

### moveBy

• moveBy(...args: any[]): this
• Move every Pt's position by a specific amount. Same as `add`.

#### Parameters

• ##### Rest...args: any[]

a list of numbers, an array of number, or an object with {x,y,z,w} properties

### moveTo

• moveTo(...args: any[]): this
• Move the first Pt in this group to a specific position, and move all the other Pts correspondingly

#### Parameters

• ##### Rest...args: any[]

a list of numbers, an array of number, or an object with {x,y,z,w} properties

### multiply

• multiply(...args: any[]): this
• Multiply scalar or vector values (as element-wise) with this group's Pts.

#### Parameters

• ##### Rest...args: any[]

a list of numbers, an array of number, or an object with {x,y,z,w} properties

### neighborPts

• neighborPts(i: number, sort?: boolean): GroupLike
• Given an index of a Pt in this Delaunay Group, returns its neighboring Pts in the network

#### Parameters

• ##### i: number

index of a Pt

• ##### Default value sort: boolean = false

if true, sort the neighbors so that their edges will form a polygon

#### Returns GroupLike

an array of Pts

### neighbors

• Given an index of a Pt in this Delaunay Group, returns its neighboring DelaunayShapes

#### Parameters

• ##### i: number

index of a Pt

#### Returns DelaunayShape[]

an array of DelaunayShapes `{i, j, k, triangle, circle}`

### op

• op(fn: function): function
• Create an operation using this Group, passing this Group into a custom function's first parameter. See the Op guide for details. For example: `let myOp = group.op( fn ); let result = myOp( [1,2,3] );`

#### Parameters

• ##### fn: function

any function that takes a Group as its first parameter

#### Returns function

a resulting function that takes other parameters required in `fn`

• (...rest: any[]): any

### ops

• ops(fns: function[]): function[]
• This combines a series of operations into an array. See `op()` for details. For example: `let myOps = pt.ops([fn1, fn2, fn3]); let results = myOps.map( (op) => op([1,2,3]) );`

#### Parameters

• ##### fns: function[]

an array of functions for `op`

#### Returns function[]

an array of resulting functions

### reflect2D

• reflect2D(line: GroupLike, axis?: string): this
• Reflect this group's Pts along a 2D line. Default anchor point is the first Pt in this group.

#### Parameters

• ##### line: GroupLike

a Group of 2 Pts that defines a line for reflection

• ##### Optional axis: string

optional axis such as "yz" to define a 2D plane of reflection

### remove

• remove(index?: number, count?: number): Group
• Like Array's splice function, with support for negative index and a friendlier name.

#### Parameters

• ##### Default value index: number = 0

start index, which can be negative (where -1 is at index 0, -2 at index 1, etc)

• ##### Default value count: number = 1

number of items to remove

#### Returns Group

The items that are removed.

### rotate2D

• rotate2D(angle: number, anchor?: PtLike, axis?: string): this
• Rotate this group's Pt from an anchor point in 2D. Default anchor point is the first Pt in this group.

#### Parameters

• ##### angle: number

rotate angle

• ##### Optional anchor: PtLike

optional anchor point to scale from

• ##### Optional axis: string

optional string such as "yz" to specify a 2D plane

### scale

• scale(scale: number | number[] | PtLike, anchor?: PtLike): this
• Scale this group's Pts from an anchor point. Default anchor point is the first Pt in this group.

#### Parameters

• ##### scale: number | number[] | PtLike

scale ratio

• ##### Optional anchor: PtLike

optional anchor point to scale from

### segments

• segments(pts_per_segment?: number, stride?: number, loopBack?: boolean): Group[]
• Split this group into an array of sub-group segments

#### Parameters

• ##### Default value pts_per_segment: number = 2

number of Pts in each segment

• ##### Default value stride: number = 1

forward-step to take

• ##### Default value loopBack: boolean = false

if `true`, always go through the array till the end and loop back to the beginning to complete the segments if needed

### shear2D

• shear2D(scale: number | number[] | PtLike, anchor?: PtLike, axis?: string): this
• Shear this group's Pt from an anchor point in 2D. Default anchor point is the first Pt in this group.

#### Parameters

• ##### Optional anchor: PtLike

optional anchor point to scale from

• ##### Optional axis: string

optional string such as "yz" to specify a 2D plane

### sortByDimension

• sortByDimension(dim: number, desc?: boolean): this
• Sort this group's Pts by values in a specific dimension

#### Parameters

• ##### dim: number

dimensional index

• ##### Default value desc: boolean = false

if true, sort descending. Default is false (ascending)

### split

• split(chunkSize: number, stride?: number, loopBack?: boolean): Group[]
• Split this Group into an array of sub-groups

#### Parameters

• ##### chunkSize: number

number of items per sub-group

• ##### Optional stride: number

forward-steps after each sub-group

• ##### Default value loopBack: boolean = false

if `true`, always go through the array till the end and loop back to the beginning to complete the segments if needed

### subtract

• subtract(...args: any[]): this
• Subtract scalar or vector values from this group's Pts.

#### Parameters

• ##### Rest...args: any[]

a list of numbers, an array of number, or an object with {x,y,z,w} properties

### toString

• toString(): string
• Get a string representation of this group

### voronoi

• Generate Voronoi cells. `delaunay()` must be called before calling this function.

#### Returns Group[]

an array of Groups, each of which represents a Voronoi cell

### zipSlice

• zipSlice(index: number, defaultValue?: number | boolean): Pt
• Zip one slice of an array of Pt. Imagine the Pts are organized in rows, then this function will take the values in a specific column.

#### Parameters

• ##### Default value defaultValue: number | boolean = false

a default value to fill if index out of bound. If not provided, it will throw an error instead.

### StaticProtected _dedupe

• _dedupe(edges: number[]): number[]
• Dedupe the edges array

### Static concat

• concat(...items: Pt[][]): Pt[]
• concat(...items: (T[] | T)[]): Pt[]
• Combines two or more arrays.

#### Returns Pt[]

• Combines two or more arrays.

### Static every

• every(callbackfn: function): boolean
• every(callbackfn: function, thisArg: undefined): boolean
• every<Z>(callbackfn: function, thisArg: Z): boolean
• Determines whether all the members of an array satisfy the specified test.

#### Parameters

• ##### callbackfn: function

A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.

• (this: void, value: Pt, index: number, array: Pt[]): boolean

• #### Parameters

• ##### callbackfn: function
• (this: void, value: Pt, index: number, array: Pt[]): boolean

#### Parameters

• ##### callbackfn: function
• (this: Z, value: Pt, index: number, array: Pt[]): boolean

### Static filter

• filter(callbackfn: function): Pt[]
• filter(callbackfn: function, thisArg: undefined): Pt[]
• filter<Z>(callbackfn: function, thisArg: Z): Pt[]
• Returns the elements of an array that meet the condition specified in a callback function.

#### Parameters

• ##### callbackfn: function

A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.

• (this: void, value: Pt, index: number, array: Pt[]): any

• #### Parameters

• ##### callbackfn: function
• (this: void, value: Pt, index: number, array: Pt[]): any

#### Parameters

• ##### callbackfn: function
• (this: Z, value: Pt, index: number, array: Pt[]): any

### Static forEach

• forEach(callbackfn: function): void
• forEach(callbackfn: function, thisArg: undefined): void
• forEach<Z>(callbackfn: function, thisArg: Z): void
• Performs the specified action for each element in an array.

#### Parameters

• ##### callbackfn: function

A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

• (this: void, value: Pt, index: number, array: Pt[]): void

• #### Parameters

• ##### callbackfn: function
• (this: void, value: Pt, index: number, array: Pt[]): void

#### Parameters

• ##### callbackfn: function
• (this: Z, value: Pt, index: number, array: Pt[]): void

### Static fromArray

• Convert an array of numeric arrays into a Group of Pts

example

`Group.fromArray( [[1,2], [3,4], [5,6]] )`

#### Parameters

• ##### list: PtLike[]

an array of numeric arrays

### Static fromPtArray

• Convert an array of Pts into a Group.

#### Parameters

• ##### list: GroupLike

an array of Pts

### Static indexOf

• indexOf(searchElement: Pt, fromIndex?: number): number
• Returns the index of the first occurrence of a value in an array.

#### Parameters

• ##### searchElement: Pt

The value to locate in the array.

• ##### Optional fromIndex: number

The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

### Static join

• join(separator?: string): string
• Adds all the elements of an array separated by the specified separator string.

#### Parameters

• ##### Optional separator: string

A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.

### Static lastIndexOf

• lastIndexOf(searchElement: Pt, fromIndex?: number): number
• Returns the index of the last occurrence of a specified value in an array.

#### Parameters

• ##### searchElement: Pt

The value to locate in the array.

• ##### Optional fromIndex: number

The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.

### Static map

• map<U>(this: [Pt, Pt, Pt, Pt, Pt], callbackfn: function): [U, U, U, U, U]
• map<U>(this: [Pt, Pt, Pt, Pt, Pt], callbackfn: function, thisArg: undefined): [U, U, U, U, U]
• map<Z, U>(this: [Pt, Pt, Pt, Pt, Pt], callbackfn: function, thisArg: Z): [U, U, U, U, U]
• map<U>(this: [Pt, Pt, Pt, Pt], callbackfn: function): [U, U, U, U]
• map<U>(this: [Pt, Pt, Pt, Pt], callbackfn: function, thisArg: undefined): [U, U, U, U]
• map<Z, U>(this: [Pt, Pt, Pt, Pt], callbackfn: function, thisArg: Z): [U, U, U, U]
• map<U>(this: [Pt, Pt, Pt], callbackfn: function): [U, U, U]
• map<U>(this: [Pt, Pt, Pt], callbackfn: function, thisArg: undefined): [U, U, U]
• map<Z, U>(this: [Pt, Pt, Pt], callbackfn: function, thisArg: Z): [U, U, U]
• map<U>(this: [Pt, Pt], callbackfn: function): [U, U]
• map<U>(this: [Pt, Pt], callbackfn: function, thisArg: undefined): [U, U]
• map<Z, U>(this: [Pt, Pt], callbackfn: function, thisArg: Z): [U, U]
• map<U>(callbackfn: function): U[]
• map<U>(callbackfn: function, thisArg: undefined): U[]
• map<Z, U>(callbackfn: function, thisArg: Z): U[]
• Calls a defined callback function on each element of an array, and returns an array that contains the results.

#### Parameters

• ##### callbackfn: function

A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: Z, value: Pt, index: number, array: Pt[]): U

#### Returns [U, U, U, U, U]

• Calls a defined callback function on each element of an array, and returns an array that contains the results.

#### Parameters

• ##### callbackfn: function

A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: Z, value: Pt, index: number, array: Pt[]): U

#### Returns [U, U, U, U]

• Calls a defined callback function on each element of an array, and returns an array that contains the results.

#### Parameters

• ##### callbackfn: function

A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: Z, value: Pt, index: number, array: Pt[]): U

#### Returns [U, U, U]

• Calls a defined callback function on each element of an array, and returns an array that contains the results.

#### Parameters

• ##### callbackfn: function

A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: Z, value: Pt, index: number, array: Pt[]): U

#### Returns [U, U]

• Calls a defined callback function on each element of an array, and returns an array that contains the results.

#### Parameters

• ##### callbackfn: function

A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: void, value: Pt, index: number, array: Pt[]): U

#### Parameters

• ##### callbackfn: function
• (this: Z, value: Pt, index: number, array: Pt[]): U

### Static pop

• pop(): Pt | undefined
• Removes the last element from an array and returns it.

### Static push

• push(...items: Pt[]): number
• Appends new elements to an array, and returns the new length of the array.

#### Parameters

• ##### Rest...items: Pt[]

New elements of the Array.

### Static reduce

• reduce(callbackfn: function, initialValue?: Pt): Pt
• reduce<U>(callbackfn: function, initialValue: U): U
• Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

#### Parameters

• ##### callbackfn: function

A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

• (previousValue: Pt, currentValue: Pt, currentIndex: number, array: Pt[]): Pt

#### Returns Pt

• ##### Optional initialValue: Pt

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

#### Returns Pt

• Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

#### Parameters

• ##### callbackfn: function

A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

• (previousValue: U, currentValue: Pt, currentIndex: number, array: Pt[]): U

#### Returns U

• ##### initialValue: U

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

### Static reduceRight

• reduceRight(callbackfn: function, initialValue?: Pt): Pt
• reduceRight<U>(callbackfn: function, initialValue: U): U
• Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

#### Parameters

• ##### callbackfn: function

A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

• (previousValue: Pt, currentValue: Pt, currentIndex: number, array: Pt[]): Pt

#### Returns Pt

• ##### Optional initialValue: Pt

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

#### Returns Pt

• Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

#### Parameters

• ##### callbackfn: function

A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

• (previousValue: U, currentValue: Pt, currentIndex: number, array: Pt[]): U

#### Returns U

• ##### initialValue: U

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

### Static reverse

• reverse(): Pt[]
• Reverses the elements in an Array.

### Static shift

• shift(): Pt | undefined
• Removes the first element from an array and returns it.

### Static slice

• slice(start?: number, end?: number): Pt[]
• Returns a section of an array.

#### Parameters

• ##### Optional start: number

The beginning of the specified portion of the array.

• ##### Optional end: number

The end of the specified portion of the array.

### Static some

• some(callbackfn: function): boolean
• some(callbackfn: function, thisArg: undefined): boolean
• some<Z>(callbackfn: function, thisArg: Z): boolean
• Determines whether the specified callback function returns true for any element of an array.

#### Parameters

• ##### callbackfn: function

A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.

• (this: void, value: Pt, index: number, array: Pt[]): boolean

• #### Parameters

• ##### callbackfn: function
• (this: void, value: Pt, index: number, array: Pt[]): boolean

#### Parameters

• ##### callbackfn: function
• (this: Z, value: Pt, index: number, array: Pt[]): boolean

### Static sort

• sort(compareFn?: function): this
• Sorts an array.

#### Parameters

• ##### Optional compareFn: function

The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.

• (a: Pt, b: Pt): number

### Static splice

• splice(start: number, deleteCount?: number): Pt[]
• splice(start: number, deleteCount: number, ...items: Pt[]): Pt[]
• Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

#### Parameters

• ##### start: number

The zero-based location in the array from which to start removing elements.

• ##### Optional deleteCount: number

The number of elements to remove.

#### Returns Pt[]

• Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

#### Parameters

• ##### start: number

The zero-based location in the array from which to start removing elements.

• ##### deleteCount: number

The number of elements to remove.

• ##### Rest...items: Pt[]

Elements to insert into the array in place of the deleted elements.

### Static toLocaleString

• toLocaleString(): string

### Static toString

• toString(): string
• Returns a string representation of an array.

### Static unshift

• unshift(...items: Pt[]): number
• Inserts new elements at the start of an array.

#### Parameters

• ##### Rest...items: Pt[]

Elements to insert at the start of the Array.

#### Returns number

Generated using TypeDoc