diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-04-01 13:24:08 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-04-01 13:24:08 +0000 |
| commit | addacd4d38a479c1dbb84197ab2c0295b49bad47 (patch) | |
| tree | 33c1f903f59dac4e63fcb77c1dc564793cfdcc6e | |
| parent | bzrignore: inkview.pod (diff) | |
| download | inkscape-addacd4d38a479c1dbb84197ab2c0295b49bad47.tar.gz inkscape-addacd4d38a479c1dbb84197ab2c0295b49bad47.zip | |
Bug #1553497 Voronoi Extension: Delaunay triangulate can get fill color from sources.
Fixed bugs:
- https://launchpad.net/bugs/1553497
(bzr r14756)
| -rw-r--r--[-rwxr-xr-x] | share/extensions/voronoi.py | 2 | ||||
| -rw-r--r-- | share/extensions/voronoi2svg.inx | 6 | ||||
| -rw-r--r--[-rwxr-xr-x] | share/extensions/voronoi2svg.py | 61 |
3 files changed, 58 insertions, 11 deletions
diff --git a/share/extensions/voronoi.py b/share/extensions/voronoi.py index 8661bc9bf..ac2c13f8f 100755..100644 --- a/share/extensions/voronoi.py +++ b/share/extensions/voronoi.py @@ -395,6 +395,8 @@ class Edge(object): else: # set formula of line, with y fixed to 1 newedge.b = 1.0 + if dy <= 0: + dy = 0.01 newedge.a = dx/dy newedge.c /= dy diff --git a/share/extensions/voronoi2svg.inx b/share/extensions/voronoi2svg.inx index d86ebd819..c07dbb8e5 100644 --- a/share/extensions/voronoi2svg.inx +++ b/share/extensions/voronoi2svg.inx @@ -18,6 +18,12 @@ <_item value="Automatic from seeds">Automatic from selected objects</_item> </param> <param name="show-clip-box" type="boolean" _gui-text="Show the bounding box"></param> + <_param name="Delaunay Options" type="description" appearance="header">Options for Delaunay Triangulation</_param> + <param name="delaunay-fill-options" _gui-text="Triangles color" type="optiongroup"> + <_option value="delaunay-no-fill">Default (Stroke black and no fill)</_option> + <_option value="delaunay-fill">Triangles with item color</_option> + <_option value="delaunay-fill-random">Triangles with item color (random on apply)</_option> + </param> </page> <page name="help" _gui-text="Help"> <_param name="help_text" type="description">Select a set of objects. Their centroids will be used as the sites of the Voronoi diagram. Text objects are not handled.</_param> diff --git a/share/extensions/voronoi2svg.py b/share/extensions/voronoi2svg.py index c7033b23b..d4740b7f5 100755..100644 --- a/share/extensions/voronoi2svg.py +++ b/share/extensions/voronoi2svg.py @@ -24,7 +24,7 @@ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ # standard library @@ -36,6 +36,7 @@ import simplestyle import simplepath import simpletransform import voronoi +import random inkex.localize() @@ -76,7 +77,13 @@ class Voronoi2svg(inkex.Effect): default = False, dest='showClipBox', help = 'Set this to true to write the bounding box') - + self.OptionParser.add_option( + '--delaunay-fill-options', + action = 'store', + type = 'string', + default = "delaunay-no-fill", + dest='delaunayFillOptions', + help = 'Set the Delaunay triangles color options') #}}} #{{{ Clipping a line by a bounding box @@ -191,7 +198,8 @@ class Voronoi2svg(inkex.Effect): #}}} def effect(self): - + #saveout = sys.stdout + #sys.stdout = sys.stderr #{{{ Check that elements have been selected if len(self.options.ids) == 0: @@ -203,15 +211,19 @@ class Voronoi2svg(inkex.Effect): #{{{ Drawing styles linestyle = { - 'stroke' : '#000000', - 'stroke-width' : str(self.unittouu('1px')), - 'fill' : 'none' + 'stroke' : '#000000', + 'stroke-width' : str(self.unittouu('1px')), + 'fill' : 'none', + 'stroke-linecap' : 'round', + 'stroke-linejoin' : 'round' } - + facestyle = { - 'stroke' : '#ff0000', - 'stroke-width' : str(self.unittouu('1px')), - 'fill' : 'none' + 'stroke' : '#000000', + 'stroke-width' : str(self.unittouu('1px')), + 'fill' : 'none', + 'stroke-linecap' : 'round', + 'stroke-linejoin' : 'round' } #}}} @@ -231,6 +243,7 @@ class Voronoi2svg(inkex.Effect): pts = [] nodes = [] seeds = [] + fills = [] for id in self.options.ids: @@ -244,6 +257,20 @@ class Voronoi2svg(inkex.Effect): if trans: simpletransform.applyTransformToPoint(trans,pt) pts.append(Point(pt[0],pt[1])) + fill = 'none' + if self.options.delaunayFillOptions != "delaunay-no-fill": + if node.attrib.has_key('style'): + style = node.get('style') # fixme: this will break for presentation attributes! + if style: + declarations = style.split(';') + for i,decl in enumerate(declarations): + parts = decl.split(':', 2) + if len(parts) == 2: + (prop, val) = parts + prop = prop.strip().lower() + if prop == 'fill': + fill = val.strip() + fills.append(fill) seeds.append(Point(cx,cy)) #}}} @@ -327,6 +354,9 @@ class Voronoi2svg(inkex.Effect): if self.options.diagramType != 'Voronoi': triangles = voronoi.computeDelaunayTriangulation(seeds) + i = 0; + if self.options.delaunayFillOptions == "delaunay-fill": + random.seed("inkscape") for triangle in triangles: p1 = seeds[triangle[0]] p2 = seeds[triangle[1]] @@ -335,11 +365,20 @@ class Voronoi2svg(inkex.Effect): ['L',[p2.x,p2.y]], ['L',[p3.x,p3.y]], ['Z',[]]] + if self.options.delaunayFillOptions == "delaunay-fill" or self.options.delaunayFillOptions == "delaunay-fill-random": + facestyle = { + 'stroke' : fills[triangle[random.randrange(0, 2)]], + 'stroke-width' : str(self.unittouu('0.005px')), + 'fill' : fills[triangle[random.randrange(0, 2)]], + 'stroke-linecap' : 'round', + 'stroke-linejoin' : 'round' + } path = inkex.etree.Element(inkex.addNS('path','svg')) path.set('d',simplepath.formatPath(cmds)) path.set('style',simplestyle.formatStyle(facestyle)) groupDelaunay.append(path) - + i += 1; + #sys.stdout = saveout #}}} |
