0.1.0
A Cell instance defines a polygon from a Voronoi diagram and its seed.
(Array)
Array of points
(any)
[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.
Get the polygon of this cell
ConvexPolygon
:
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.
(Cell)
another cell to intersect with
ConvexPolygon
:
the polygon resulting from the intersection
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 )
(any)
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.
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
(CellCollection)
a cell collection with the original seeds + 1 pixel as a seed
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.
(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.
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.
(Array)
an array of
[
x, y
]
Array
:
an array of
[
x, y
]
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.
(Polygon)
another polygon the get the intersection with.
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.
(ConvexPolygon)
another polygon
Boolean
:
true is the same, false if not
The Interpolator is the API provider of natninter.
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.
(Object)
of form {x: Number, y: Number, value: Number}
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
(any)
[PRIVATE] Generate the voronoi diagram where sites are only seeds
VectorTools is not instanciable and provide some static functions for computing things about vectors.
performs a cross product between v1 and v2.
(Array)
a vector
[
x, y, z
]
. To use with 2D vectors, just use
[
x, y, 0
]
(Array)
a vector
[
x, y, z
]
. To use with 2D vectors, just use
[
x, y, 0
]
(Boolean
= false
)
will force normalization of the output vector if true (default: false)
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
Number
:
the dot product
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
(Array)
first point of the u vector as
[
x, y
]
(Array)
second point of the u vector as
[
x, y
]
(Array)
first point of the v vector as
[
x, y
]
(Array)
second point of the v vector as
[
x, y
]
(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
(Array)
a point as
[
x, y
]
(Array)
first point of the u vector as
[
x, y
]
(Array)
second point of the u vector as
[
x, y
]
Number
:
the distance