This module contains non-optimize versions of the many helpers described in Mapbox's guide to Delaunator's data structures, as well as more. An added feature for some of these helpers is clipping of Voronoi regions, based on the bounds field of a Delaunator object. The default bounds are set to the extents of the Delaunay triangulation.
Some conventions on parameter/tuple field naming and their meaning:
- d - a Delaunator object
- sid - a site id, aka a point id
- pid, qid, rid - a point id
- tid - a triangle id
- eid - a halfedge id
- hid - a hull id
- p, q, r - a cartesian point
Procs
func edgeIdsAroundPoint(d: Delaunator; eid: int32): seq[int32]
- The ids of all halfedges pointing to the point that halfedge eid points to. Source Edit
proc grid[F](n, m: int; fromN, toN, fromM, toM: F; leftEdge, rightEdge, topEdge, bottomEdge: bool = true; jitterN, jitterM: F = 0.0; pinHull: bool = false; r: var Rand = randState()): seq[F]
- Returns a flattened seq of points in an n x m grid distributed within a horizontal range fromN .. toN, and a vertical range formM .. toM. By default, points begin and end at range extents, but can be inset by setting leftEdge, rightEdge, topEdge or bottomEdge to false. Set an amount of horizontal or vertical jitter in the range 0.0 .. 1.0 with jitterN and jitterM respectively. When pinHull is true, points on the grid's hull are not jittered. Source Edit
func halfedgeIdsOfTriangle(tid: uint32): array[3, int32] {....raises: [], tags: [].}
- The halfedge ids of a triangle with id tid. Source Edit
func nextHalfedge(eid: int32): int32 {....raises: [], tags: [].}
- The id of the next halfedge of the triangle for which halfedge with id eid is a part. Source Edit
proc normalDist[F](count: int; mu = 0.0; sigma = 1.0; r: var Rand = randState()): seq[ F]
- Returns a seq of count normally distributed random values of given mu and sigme. Source Edit
func pointIdsOfTriangle(d: Delaunator; tid: uint32): seq[uint32]
- The point ids composing the triangle with id tid. Source Edit
func polygonCentroid[T](polygon: seq[array[2, T]]): array[2, T]
- The centroid of points defining polygon. Source Edit
func prevHalfedge(eid: int32): int32 {....raises: [], tags: [].}
- The id of the previous halfedge of the triangle for which halfedge with id eid is a part. Source Edit
func triangleCentroid[T](d: Delaunator[T]; tid: uint32): array[2, T]
- The centroid of triangle with id tid. Source Edit
func triangleCircumcenter[T](d: Delaunator[T]; tid: uint32): array[2, T]
- The circumcenter of triangle with id tid. Source Edit
func triangleIdOfEdge(eid: int32): uint32 {....raises: [], tags: [].}
- The id of the triangle for which halfedge with id eid is a part. (also the id of the 1st point?) Source Edit
func triangleIdsAdjacentToTriangle(d: Delaunator; tid: uint32): seq[uint32]
- The triangle ids adjacent to triangle with id tid. A seq of length 2 or 3. Source Edit
proc uniformDist[F](count: int; a: F; b: F; r: var Rand = randState()): seq[F]
- Returns a seq of count uniformly distributed random values in the range a .. b. Source Edit
proc voronoiRegion[T](d: Delaunator[T]; pid: uint32): tuple[pid: uint32, verts: seq[array[2, T]]]
- Returns the voronoi region of site with id pid. The tuple returned includes the id of the point to which the region belongs, and a seq of vertices describing the region's polygon. Infinite regions are clipped to the bounds as set on the delaunator object, defaulting to the minimum and maximum extents of the points provided. Clipped regions which are completely out of bounds will yield empty vertices, wheras finite regions are always yielded whether in bounds or not, and are not clipped. Source Edit
proc zipDists[F](s1, s2: openArray[F]): seq[F]
- Returns a flattened seq of points by zipping two collections of values, s1 and s2 Source Edit
proc zipPolarDists[F](r, t: openArray[F]; xOffset, yOffset: F = F(0.0)): seq[F]
- Returns a flattened seq of points by zipping two collections of values, r -treated as a radii, and t -treated as an angles, converting each pair of polar coordinates into their cartesian counterpart. Translate the polar origin with xOffset and yOffset. Source Edit
Iterators
iterator iterHullEdges[T](d: Delaunator[T]): tuple[hid: uint32, eid: int32, pid, qid: uint32, p, q: array[2, T]]
- Provides an iterator yielding values for each edge of the triangulation's hull. The values yielded are the hull id (index of the point in d.hull the edge starts at), the halfedge id, the point id from which the edge starts, the point id at which the edge ends, an array describing the point the edge starts at, and an array describing the point the edge ends at. Source Edit
iterator iterHullPoints[T](d: Delaunator[T]): tuple[hid: uint32, pid: uint32, p: array[2, T]]
- Provides an iterator yielding values for each point of the triangulation's hull. The values yielded are the hull id (index of the point in d.hull), the id of the point, and an array describing the point's location. Source Edit
iterator iterPoints[T](d: Delaunator[T]): tuple[pid: uint32, p: array[2, T]]
- Provides an iterator yielding values for each point of the triangulation. The values yielded are the id of the point, and an array describing the point's location. Source Edit
iterator iterTriangleEdges[T](d: Delaunator[T]): tuple[tid: uint32, eid: int32, pid, qid: uint32, p, q: array[2, T]]
- Provides an iterator yielding values for each edge of the triangulation. The values yielded are the id of the triangle, id of the halfedge chosen for the edge, id of starting and ending points, an array describing the point the edge starts at, and an array describing the point the edge ends at. Source Edit
iterator iterTriangles[T](d: Delaunator[T]): tuple[tid: uint32, pid, qid, rid: uint32, p, q, r: array[2, T]]
- Provides an iterator yielding values for each triangle of the triangulation. The values yielded are the id of the triangle, the ids of the points comprising the triangle, and three arrays, each describing a point of the triangle. Source Edit
iterator iterVoronoiEdges[T](d: Delaunator[T]): tuple[eid: int32, p, q: array[2, T]]
- Provides an iterator yielding values for each bisecting voronoi edge of the triangulation. For finite edges, the values yielded are the id of the halfedge chosen for the bisected edge, an array describing the circumcenter of the triangle for which that halfedge is a part, and an array describing the circumcenter of the adjacent triangle for which that halfedge's compliment is a part. For infinite edges, the id is of a halfedge on the hull. The first array describes the circumcenter of the triangle for which that halfedge is a part, and the second, the point projected by the halfedge origin's rightmost ray onto the delaunator object's defined bounds. Source Edit
iterator iterVoronoiRegions[T](d: Delaunator[T]): tuple[pid: uint32, verts: seq[array[2, T]]]
- Provides an iterator yielding values for each region of the voronoi diagram. The values yielded are the id of the point to which the region belongs, and a seq of vertices describing the region's polygon. Infinite regions are clipped to the bounds as set on the delaunator object, defaulting to the minimum and maximum extents of the points provided. Clipped regions which are completely out of bounds are not yielded, wheras finite regions are always yielded whether in bounds or not, and are not clipped. Source Edit