voronoi2svg.py revision 6ed90202378068e77619b6e8b259ad064dd3fd2b
3427N/ACreate Voronoi diagram from seeds (midpoints of selected objects) 1710N/ACopyright (C) 2011 Vincent Nivoliers and contributors 1710N/A ~suv, <suv-sf@users.sf.net> 1710N/AThis program is free software; you can redistribute it and/or modify 1710N/Ait under the terms of the GNU General Public License as published by 1710N/Athe Free Software Foundation; either version 2 of the License, or 1710N/A(at your option) any later version. 1710N/AThis program is distributed in the hope that it will be useful, 1710N/Abut WITHOUT ANY WARRANTY; without even the implied warranty of 1710N/AMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1710N/AGNU General Public License for more details. 1710N/AYou should have received a copy of the GNU General Public License 1710N/Aalong with this program; if not, write to the Free Software 1710N/AFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1710N/A help =
'Defines the area bounding the Voronoi diagram')
1710N/A help =
'Set this to true to write the bounding box of the bounding area')
1710N/A #{{{ Clipping a line by a bounding box 1710N/A return x[
0]*y[
0] + x[
1]*y[
1]
1710N/A #record intersections of the line with bounding box edges 1710N/A #if the edge has no intersection, return empty intersection 1710N/A #sorting the points in the widest range to get them in order on the line 1710N/A if point[
2]:
#The point is a bounding box intersection 1710N/A else:
#The point is a segment endpoint 1710N/A #a vertex ends the line inside the bounding box 1710N/A #{{{ Transformation helpers 1710N/A if det !=
0:
#det is 0 only in case of 0 scaling 1710N/A #invert the translational part #{{{ Handle the transformation of the current group #{{{ Recovery of the selected objects #{{{ Creation of groups to store the result #{{{ Clipping box handling #Clipping bounding box creation #Clipbox is the box to which the Voronoi diagram is restricted #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 #segment = [vertices[vindex1],vertices[vindex2]] # deactivate clipping # vim: expandtab shiftwidth=2 tabstop=2 softtabstop=2 fileencoding=utf-8 textwidth=99