1 %% Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
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
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.
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/>.
17 %% @deftypefn {Function File} @var{P} = path2polygon (@var{id})
18 %% Converts the SVG path to an array of polygons.
22 function P = path2polygon (obj,varargin)
24 narg = numel(varargin);
38 error("svg:path2polygon:InvalidArgument", "Wrong number of arguments.");
42 P = shape2polygon(getpath(obj, id));
47 pd = obj.Path.(id).data;
48 P = cellfun(@(x)convertpath(x,n),pd,'UniformOutput',false);
53 function p = convertpath(x,np)
60 p(:,1) = polyval (x(1,:), [0; 1]);
61 p(:,2) = polyval (x(2,:), [0; 1]);
65 t = linspace (0, 1, np).';
66 p(:,1) = polyval (x(1,:),t);
67 p(:,2) = polyval (x(2,:),t);