voronoi2svg.py revision 2a1cece0da69dfd97d4d6d78c1e978cc7f969118
"""
Create Voronoi diagram from seeds (midpoints of selected objects)
- Voronoi Diagram algorithm and C code by Steven Fortune, 1987, http://ect.bell-labs.com/who/sjf/
- Python translation to file voronoi.py by Bill Simons, 2005, http://www.oxfish.com/
Copyright (C) 2011 Vincent Nivoliers and contributors
Contributors
~suv, <suv-sf@users.sf.net>
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
import voronoi
import gettext
class Point:
self.x = x
self.y = y
#{{{ Additional options
'--diagram-type',
action = 'store',
default = 'Voronoi',
dest='diagramType',
help = 'Defines the type of the diagram')
'--clip-box',
action = 'store',
default = 'Page',
dest='clipBox',
help = 'Defines the area bounding the Voronoi diagram')
'--show-clip-box',
action = 'store',
type = 'inkbool',
dest='showClipBox',
help = 'Set this to true to write the bounding box of the bounding area')
#}}}
#{{{ Clipping a line by a bounding box
return x[0]*y[0] + x[1]*y[1]
else:
if tmp == 0:
v = 1-u
#bounding box corners
bbc = []
#record intersections of the line with bounding box edges
interpoints = []
for i in range(4):
if (p[2]):
#if the edge has no intersection, return empty intersection
return []
#points of the edge
#sorting the points in the widest range to get them in order on the line
for point in interpoints:
else:
start = []
for point in interpoints:
if inside:
if startWrite:
else:
return []
else:
if startWrite:
else: #The point is a segment endpoint
if startWrite:
if inside:
#a vertex ends the line inside the bounding box
else:
return []
else:
if inside:
startWrite = not startWrite
#}}}
#{{{ Transformation helpers
#invert the translational part
else:
if myTrans:
if parent is not None:
if parentTrans:
else:
return myTrans
else:
if parent is not None:
else:
return None
#}}}
#{{{ Check that elements have been selected
return
#}}}
#{{{ Drawing styles
linestyle = {
'stroke' : '#000000',
'linewidth' : '1',
'fill' : 'none'
}
facestyle = {
'stroke' : '#ff0000',
'linewidth' : '1',
'fill' : 'none'
}
#}}}
#{{{ Handle the transformation of the current group
invtrans = None
if trans:
#}}}
#{{{ Recovery of the selected objects
pts = []
nodes = []
seeds = []
if bbox:
if trans:
#}}}
#{{{ Creation of groups to store the result
# Voronoi
if invtrans:
# Delaunay
#}}}
#{{{ Clipping box handling
#Clipping bounding box creation
#Clipbox is the box to which the Voronoi diagram is restricted
clipBox = ()
else:
#Safebox adds points so that no Voronoi edge in clipBox is infinite
#Add the clip box to the drawing
#}}}
#{{{ Voronoi diagram generation
continue # infinite lines have no need to be handled in the clipped box
else:
#segment = [vertices[vindex1],vertices[vindex2]] # deactivate clipping
['Z',[]]]
#}}}
if __name__ == "__main__":
e = Voronoi2svg()
e.affect()
# vim: expandtab shiftwidth=2 tabstop=2 softtabstop=2 fileencoding=utf-8 textwidth=99