A Cell instance defines a polygon from a Voronoi diagram and its seed.
Parameters
contourPoints
Array Array of pointsseed
Return if this cell is valid
Returns Boolean true if valid, false if not
Get the hash of this cell
Returns String
Get the seed of the cell.
Returns Object should be of form {x: Number, y: Number, seedIndex: Number}
Get the polygon of this cell
Returns ConvexPolygon
Get the area of the cell (calls the polygon method)
Returns Number the area
Get the polygon resulting from the intersection of a voronoi cell with another cell (this second cell comes from another voronoi diagramm where a seed has been added). NOTE: This does NOT implement a standard polygon intersection algorithm, its use is stricly for the use case of voronoi cells being replaced, making it quite faster but not suitable for other cases.
Parameters
anotherCell
Cell another cell to intersect with
Returns ConvexPolygon the polygon resulting from the intersection
Compare if this cell has the same polygon as another cell. Read the doc of ConvexPolygon.getPolygon() for more info.
Parameters
otherCell
anotherCell
Cell another cell to compare the polygon with.
Returns Boolean true if the same polygon, false if not
[STATIC] Get a unique hash from 2 floats. I am pretty sure these super simple stringified coordinate hashes are not the most robust, though the point is mainly to be as fast as possible.
Parameters
n1
Number a number, most likely the x of a coordn2
Number a number, most likely the y of a coorda
String (probably unique enough) hash
A CellCollection stores Cell objects. It is the interface between the Voronoi diagram and the Cells/Polygons.
Builds the collection of cell using a voronoi diagram object from the Javascript-Voronoi library by Gorhill ( http://bit.ly/2FoapPI )
Parameters
vd
Get the list of hashes (ID) of cells in the collection
Returns Array all the hashes
Get the cell of this collection that has this hash
Parameters
hash
String the unique hash of the cell
Returns Cell a Cell instance of null if hash not found
Store the hash of a given position of a seed, meaning, store a reference to a cell. This seed is the one added to the 'another' diagram, when we introduce a pixel as a seed. For instance, the seed-only cell collection does not have a reference to a seed.
Parameters
Get the cell that was referenced by referenceSeed()
Returns Cell
When comparing a seed-only CellCollection with a seed-and-one-pixel CellCollection with getStolenAreaInfo(), we get a list of original cell index (from the seed-only collection) as well as the area ratio that comes from them to build the pixel-based cell
Parameters
anotherCellCollection
CellCollection a cell collection with the original seeds + 1 pixel as a seed
Returns Array list of {seedIndex: Number, weight: Number}
ConvexPolygon is a simple approach of a polygon, it's actually a simple approcah of what is a convex polygon and is mainly made to be used in the context of a polygon representing a cell of a Voronoi diagram. Here, a polygon is a list of 2D points that represent a convex polygon, with the list of point being no closed (= the last point is not a repetition of the first). The list of points describing a polygon can not be modified later.
Parameters
points
Array can be an array of [x, y] (both being of type Number) or it can be an array of {x: Number, y: Number}. Depending on what is the source of points, both exist. Note: there is no integrity checking that the given list of point represent an actually convex polygon.
Get if the polygon is valid
Returns Boolean [description]
Get the area of a this polygon. If never computed, computes it and stores it
Returns Number the area
This is reliable ONLY in the context of Voronoi cells! This is NOT a generally valid way to find the intersection polygon between 2 convex polygons! For this context only, we believe it's much faster tho.
Parameters
anotherPolygon
Polygon another polygon the get the intersection with.
Get the Array of vertices. This is a reference and the point should not be modified!
Returns Array the points of the hull
Compare with another polygon and tells if it's the same. Predicate: polygons are convex + the first point of the list starts at noon and the following are going clock-wise.
Parameters
otherPolygon
ConvexPolygon another polygon
Returns Boolean true is the same, false if not
[STATIC] Removes the duplicates of a hull so that a polygon hull does not have twice the same [x, y] points;
Parameters
polygonPoints
Array an array of [x, y]
Returns Array an array of [x, y], with duplicates removed
Get the center coordinate of a polygon by averaging all the pointd of the hull
Parameters
polygonPoints
Array an array of [x, y]
Returns Array the center as [x, y]
A list of polygon points representing a convex hull are not always listed in a clock-wise of ccw order, by default, we cannot count on it. This methods reorder the vertices of the in a clock-wise fashion, starting by the one that at noon or immediately after. Note: this is necessary to compute the area and to compare two polygons.
Parameters
polygonPoints
Array an array of [x, y]
Returns Array an array of [x, y]
The Interpolator is the API provider of natninter.
Define a callback for the progress of making the map and the progress of making the output image It will be called with 2 args: the progress in percentage (Number), and a description string
Parameters
cb
Function callback function
Removes all the seeds
Add a seed to the interpolator. Note that the seed is not copied, only its reference is. This is convenient for updating the value of the seed from the outside and ecompute the interpolation without having to recompute the whole weight map.
Parameters
seed
Object of form {x: Number, y: Number, value: Number}
Add an array of seed
Parameters
seedArr
Array array of seeds, where each seed is of form {x: Number, y: Number, value: Number}
Define the size of the output image
Parameters
Check if all the seeds are inside the output area defined with setOutputSize()
Returns Boolean true if all are inside, false if at leas one is out
Compute the sampling map. Automatically called by the update method when the
map was never computed or when a seed have been added since.
Though this method is not private and can be called to force recomputing the map.
Note: if you have already computed a map for the exact same seed positions and output size,
you can avoid recomputing it and use getMap
and setMap
.
Get the sampling map object
Parameters
m
When you don't want to recompute the sampling map with computeMap()
and reuse
the exact same seed position and output size (of course, seed values can change)
Parameters
map
Array an already existing sampling map
is the given position at the position of a seed?
Parameters
Returns Boolean -1 if not, of the index of the seed if yes
[PRIVATE] Generate the voronoi diagram where sites are only seeds
Generate the output image as a floating points 1D array representing a 2D (1band) image.
Returns Object of form {_data: Float32Array, _metadata: {width: Number, height: Number}}
VectorTools is not instanciable and provide some static functions for computing things about vectors.
performs a cross product between v1 and v2.
Parameters
v1
Array a vector [x, y, z]. To use with 2D vectors, just use [x, y, 0]v2
Array a vector [x, y, z]. To use with 2D vectors, just use [x, y, 0]normalize
Boolean will force normalization of the output vector if true (default: false) (optional, defaultfalse
)
Returns Array a vector [x, y, z], result of the cross product
Perform the dot product of two vectors. They need to be of the same dimension but they can be 2D, 3D or aother. Note: If v1 and v2 are normalize, the dot product is also the cosine
Parameters
Returns Number the dot product
Normalizes a 3D vector
Parameters
v
Array 3D vector to normalize
Returns Array the normalized 3D vector
return the norm (length) of a vector [x, y, z]
Parameters
v
Array 3D vector to get the norm of
Returns Number the norm
rotate the vector v using the rotation matrix m.
Parameters
Returns Array the rotated vector [ax + by + cz, dx + ey + fz, gx + hy + iz]
Compute the angle p1p2p3 in radians. Does not give the sign, just absolute angle!
Parameters
Returns Number [description]
Checks if the 2D vector u crosses the 2D vector v. The vector u goes from point u1 to point u2 and vector v goes from point v1 to point v2. Based on Gavin from SO http://bit.ly/2oNn741 reimplemented in JS
Parameters
u1
Array first point of the u vector as [x, y]u2
Array second point of the u vector as [x, y]v1
Array first point of the v vector as [x, y]v2
Array second point of the v vector as [x, y]
Returns (Array | null) crossing point as [x, y] or null if vector don't cross.
Get the distance between the 2D point p and a 2D segment u (defined by its points u1 and u2) Stolen from SO http://bit.ly/2oQG3yX
Parameters
p
Array a point as [x, y]u1
Array first point of the u vector as [x, y]u2
Array second point of the u vector as [x, y]
Returns Number the distance