]> Creatis software - CreaPhase.git/blob - octave_packages/geometry-1.5.0/io/deprecated/svgpath2polygon.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / geometry-1.5.0 / io / deprecated / svgpath2polygon.m
1 %% Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
2 %% 
3 %%    This program is free software: you can redistribute it and/or modify
4 %%    it under the terms of the GNU General Public License as published by
5 %%    the Free Software Foundation, either version 3 of the License, or
6 %%    any later version.
7 %%
8 %%    This program is distributed in the hope that it will be useful,
9 %%    but WITHOUT ANY WARRANTY; without even the implied warranty of
10 %%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 %%    GNU General Public License for more details.
12 %%
13 %%    You should have received a copy of the GNU General Public License
14 %%    along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 %% -*- texinfo -*-
17 %% @deftypefn {Function File} @var{P} = svgpath2polygon (@var{SVGpath})
18 %% Converts the SVG path structure @var{SVGpath} to an array of polygons 
19 %% compatible with the geometry package and matGeom (@url{http://matgeom.sf.net}).
20 %% 
21 %% @var{SVGpath} is a substructure of the SVG structure output by loadSVG. This
22 %% function extracts the field named "coord" if there is only one path. If there
23 %% are more than oe path it puts the "coord" field of each path in the same 
24 %% array, separated by nans.
25 %%
26 %% @seealso{svgnormalize, svgload}
27 %% @end deftypefn
28
29 function P = svgpath2polygon (SVGpath)
30
31     P = SVGpath(1).coord;
32     for ip = 2:numel (SVGpath)
33         P = [P; nan(1,2); SVGpath(ip).coord];
34     end
35
36 end
37
38 %!demo
39 %! file    = 'tmp__.svg';
40 %! fid     = fopen (file,'w');
41 %! svgfile = '<html><body><svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="250" width="250"><path d="M150,0 75,200 225,200 Z" /></svg></body></html>';
42 %! fprintf (fid,"%s\n",svgfile);
43 %! fclose (fid);
44 %! SVG     = svgload (file);
45 %! SVG     = svgnormalize (SVG);
46 %! P       = svgpath2polygon (SVG.path);
47 %! plot (P(:,1),P(:,2));
48 %! delete (file);
49
50 %!demo
51 %! file    = 'tmp__.svg';
52 %! fid     = fopen (file,'w');
53 %! svgfile = '<html><body><svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="250" width="250"><path d="M150,0 75,200 225,200 Z" /><path d="M0,0 100,0 100,100 0,100 Z" /></svg></body></html>';
54 %! fprintf (fid,"%s\n",svgfile);
55 %! fclose (fid);
56 %! SVG     = svgload (file);
57 %! SVG     = svgnormalize (SVG);
58 %! P       = svgpath2polygon (SVG.path);
59 %! plot (P(:,1),P(:,2));
60 %! delete (file);