forked from ff6347/Illustrator-Javascript-Voronoi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Voronoi_README
128 lines (98 loc) · 4.79 KB
/
Voronoi_README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
A Javascript implementation of Steven J. Fortune's algorithm to
efficiently compute Voronoi diagrams. The Voronoi object's purpose is
to solely compute a Voronoi diagram, it is completely standalone, with
no dependency on external code: it contains no rendering code, that is
left to the user of the library. MIT license.
Files
-----
rhill-voronoi-core.js
Where the Voronoi object is implemented. This is a standalone library,
there is no dependency.
rhill-voronoi-core.min.js
The minimized version (using YUI compressor)
rhill-voronoi-demo1.php
rhill-voronoi-demo2.php
rhill-voronoi-demo3.php
Demo pages to demonstrate usage of the Voronoi object.
excanvas/*
Used by demo pages
ExplorerCanvas, giving pre-HTML5 Internet Explorer the ability
to make sense of HTML5's canvas element. Pulled from
http://code.google.com/p/explorercanvas/
mootools/*
Used by rhill-voronoi-demo3.php
Above pages available at
http://www.raymondhill.net/voronoi/
Main object: Voronoi
--------------------
A Javascript object which allows to compute a Voronoi diagram.
The Voronoi object doesn't render the resulting Voronoi diagram,
the user is responsible for rendering the diagram.
Usage
-----
Roughly:
var voronoi = new Voronoi();
var bbox = {xl:0,xr:800,yt:0,yb:600};
var vertices = [{x:200, y:200}, {x:50, y:250}, {x:400, y:100} /* , ... */];
// a 'vertex' is an object exhibiting 'x' and 'y' properties. The
// Voronoi object will add a unique 'voronoiId' property to all
// vertices. The 'voronoiId' can be used as a key to lookup the
// associated cell in 'diagram.cells'.
var diagram = voronoi.compute(vertices, bbox);
The returned 'diagram' variable is a Javascript object with the
following properties:
diagram.edges:
An array of unordered, unique Voronoi.Edge objects making up the
Voronoi diagram. Edges are defined by two vertices, 'va' and 'vb',
which vertices are shared by connected edges. This mean that
if you change one vertex belonging to an edge, other connected edges
will also be changed.
diagram.cells:
An array of Voronoi.Cell objects making up the Voronoi diagram. A Cell object
might have an empty array of halfedges, meaning no Voronoi cell could be computed for a
particular cell.
diagram.execTime:
The time it took to compute the Voronoi diagram, in milliseconds.
Objects:
Voronoi:
The Voronoi object which computes a Voronoi diagram.
Voronoi.Edge:
lSite: the Voronoi site object at the left of this Voronoi.Edge object.
rSite: the Voronoi site object at the right of this Voronoi.Edge object (can be null,
when this is a border edge).
va: an object with an 'x' and a 'y' property defining the start point
(relative to the Voronoi site on the left) of this Voronoi.Edge object.
vb: an object with an 'x' and a 'y' property defining the end point
(relative to Voronoi site on the left) of this Voronoi.Edge object.
Voronoi.Cell:
site: the Voronoi site object associated with the Voronoi cell.
halfedges: an array of Voronoi.Halfedge objects, ordered counterclockwise, defining the
polygon for this Voronoi cell.
Voronoi.Halfedge:
site: the Voronoi site object owning this Voronoi.Halfedge object.
edge: a reference to the unique Voronoi.Edge object underlying this Voronoi.Halfedge object.
getStartpoint(): a method returning an object with an 'x' and a 'y' property for the start
point of this halfedge. Keep in mind halfedges are always countercockwise.
getEndpoint(): a method returning an object with an 'x' and a 'y' property for the end
point of this halfedge. Keep in mind halfedges are always countercockwise.
License
-------
Copyright (c) 2010,2011 Raymond Hill
https://github.com/gorhill/Javascript-Voronoi
Licensed under The MIT License
http://en.wikipedia.org/wiki/MIT_License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.