You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Voronoi.js modernization by @SaltyQuetzals
* Changed Voronoi generator to be more class-based, added mediocre documentation.
* Added spaces to JSDoc links so text doesn't bleed into URL
* Found delaunator docs, very helpful in writing function documentation.
* Creates a Voronoi diagram from the given Delaunator, a list of points, and the number of points. The Voronoi diagram is constructed using (I think) the {@link https://en.wikipedia.org/wiki/Bowyer%E2%80%93Watson_algorithm |Bowyer-Watson Algorithm}
4
+
* The {@link https://github.com/mapbox/delaunator/ |Delaunator} library uses {@link https://en.wikipedia.org/wiki/Doubly_connected_edge_list |half-edges} to represent the relationship between points and triangles.
* Gets the IDs of the points comprising the given triangle. Taken from {@link https://mapbox.github.io/delaunator/#triangle-to-points| the Delaunator docs.}
41
+
* @param {number} t The index of the triangle
42
+
* @returns {[number, number, number]} The IDs of the points comprising the given triangle.
* Identifies what triangles are adjacent to the given triangle. Taken from {@link https://mapbox.github.io/delaunator/#triangle-to-triangles| the Delaunator docs.}
50
+
* @param {number} t The index of the triangle
51
+
* @returns {number[]} The indices of the triangles that share half-edges with this triangle.
* Gets the indices of all the incoming and outgoing half-edges that touch the given point. Taken from {@link https://mapbox.github.io/delaunator/#point-to-edges| the Delaunator docs.}
64
+
* @param {number} start The index of an incoming half-edge that leads to the desired point
65
+
* @returns {number[]} The indices of all half-edges (incoming or outgoing) that touch the point.
* Retrieves all of the half-edges for a specific triangle `t`. Taken from {@link https://mapbox.github.io/delaunator/#edge-and-triangle| the Delaunator docs.}
90
+
* @param {number} t The index of the triangle
91
+
* @returns {[number, number, number]} The edges of the triangle.
92
+
*/
93
+
edgesOfTriangle(t){return[3*t,3*t+1,3*t+2];}
94
+
95
+
/**
96
+
* Enables lookup of a triangle, given one of the half-edges of that triangle. Taken from {@link https://mapbox.github.io/delaunator/#edge-and-triangle| the Delaunator docs.}
97
+
* @param {number} e The index of the edge
98
+
* @returns {number} The index of the triangle
99
+
*/
100
+
triangleOfEdge(e){returnMath.floor(e/3);}
101
+
102
+
/**
103
+
* Moves to the next half-edge of a triangle, given the current half-edge's index. Taken from {@link https://mapbox.github.io/delaunator/#edge-to-edges| the Delaunator docs.}
104
+
* @param {number} e The index of the current half edge
105
+
* @returns {number} The index of the next half edge
106
+
*/
107
+
nextHalfedge(e){return(e%3===2) ? e-2 : e+1;}
108
+
109
+
/**
110
+
* Moves to the previous half-edge of a triangle, given the current half-edge's index. Taken from {@link https://mapbox.github.io/delaunator/#edge-to-edges| the Delaunator docs.}
111
+
* @param {number} e The index of the current half edge
112
+
* @returns {number} The index of the previous half edge
113
+
*/
114
+
prevHalfedge(e){return(e%3===0) ? e+2 : e-1;}
115
+
116
+
/**
117
+
* Finds the circumcenter of the triangle identified by points a, b, and c. Taken from {@link https://en.wikipedia.org/wiki/Circumscribed_circle#Circumcenter_coordinates| Wikipedia}
118
+
* @param {[number, number]} a The coordinates of the first point of the triangle
119
+
* @param {[number, number]} b The coordinates of the second point of the triangle
120
+
* @param {[number, number]} c The coordinates of the third point of the triangle
121
+
* @return {[number, number]} The coordinates of the circumcenter of the triangle.
0 commit comments