changeset 9427:47d3769b9919 octave-forge

geometry: Bug fixes
author jpicarbajal
date Fri, 10 Feb 2012 13:22:25 +0000
parents 0736e119746d
children e1d4f5fe5675
files main/geometry/NEWS main/geometry/inst/io/@svg/path2polygon.m main/geometry/inst/polygons2d/simplifypolygon.m main/geometry/inst/shape2d/shapecentroid.m main/geometry/inst/shape2d/shapeplot.m
diffstat 5 files changed, 35 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/main/geometry/NEWS	Fri Feb 10 12:32:17 2012 +0000
+++ b/main/geometry/NEWS	Fri Feb 10 13:22:25 2012 +0000
@@ -1,6 +1,17 @@
 Summary of important user-visible changes for releases of the geometry package
 
 ===============================================================================
+geometry-1.4.X   Release Date: XX   Release Manager: Juan Pablo Carbajal
+===============================================================================
+
+* Bug fixes
+ - @svg/path2polygon.m
+
+* Known issues
+ - simplifypolygon.m returns empty polygons when points are repeated, i.e when
+  the polygon is not correctly formed.
+
+===============================================================================
 geometry-1.4.0   Release Date: 2012-01-25   Release Manager: Juan Pablo Carbajal
 ===============================================================================
 
--- a/main/geometry/inst/io/@svg/path2polygon.m	Fri Feb 10 12:32:17 2012 +0000
+++ b/main/geometry/inst/io/@svg/path2polygon.m	Fri Feb 10 13:22:25 2012 +0000
@@ -1,5 +1,5 @@
 %% Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
-%% 
+%%
 %%    This program is free software: you can redistribute it and/or modify
 %%    it under the terms of the GNU General Public License as published by
 %%    the Free Software Foundation, either version 3 of the License, or
@@ -16,13 +16,13 @@
 %% -*- texinfo -*-
 %% @deftypefn {Function File} @var{P} = path2polygon (@var{id})
 %% Converts the SVG path to an array of polygons.
-%% 
+%%
 %% @end deftypefn
 
 function P = path2polygon (obj,varargin)
 
     narg = numel(varargin);
-    
+
     if narg == 1
 
      id = varargin{1};
@@ -38,16 +38,21 @@
       error("svg:path2polygon:InvalidArgument", "Wrong number of arguments.");
 
     end
-    
+
+    P = shape2polygon(getpath(obj, id));
+
+endfunction
+
+%{
     pd = obj.Path.(id).data;
     P = cellfun(@(x)convertpath(x,n),pd,'UniformOutput',false);
     P = cell2mat(P);
-    
+
 end
 
 function p = convertpath(x,np)
   n = size(x,2);
-  
+
   switch n
     case 2
       p = zeros(2,2);
@@ -63,3 +68,4 @@
   end
 
 end
+%}
--- a/main/geometry/inst/polygons2d/simplifypolygon.m	Fri Feb 10 12:32:17 2012 +0000
+++ b/main/geometry/inst/polygons2d/simplifypolygon.m	Fri Feb 10 13:22:25 2012 +0000
@@ -35,6 +35,11 @@
 
   polygonsimp = polygon(circshift (ind,1),:);
 
+  if isempty(polygonsimp)
+    warning('simplifypolygon:devel',"The simplification gives an empty polygon. Returning original\n");
+    polygonsimp = polygon;
+  end
+
 endfunction
 
 %!test
--- a/main/geometry/inst/shape2d/shapecentroid.m	Fri Feb 10 12:32:17 2012 +0000
+++ b/main/geometry/inst/shape2d/shapecentroid.m	Fri Feb 10 13:22:25 2012 +0000
@@ -57,6 +57,10 @@
 %! square = {[1 -0.5; 0 -0.5]; [0 0.5; 1 -0.5]; [-1 0.5; 0 0.5]; [0 -0.5; -1 0.5]};
 %! CoM = shapecentroid (square);
 %! assert (CoM, [0 0], sqrt(eps));
+%! square_t = shapetransform (square,[1;1]);
+%! CoM_t = shapecentroid (square_t);
+%! assert (CoM, [0 0], sqrt(eps));
+%! assert (CoM_t, [1 1], sqrt(eps));
 
 %!test
 %! circle = {[1.715729  -6.715729    0   5; ...
@@ -69,3 +73,5 @@
 %!            -1.715729   6.715729    0  -5]};
 %! CoM = shapecentroid (circle);
 %! assert (CoM , [0 0], 5e-3);
+
+%!test
--- a/main/geometry/inst/shape2d/shapeplot.m	Fri Feb 10 12:32:17 2012 +0000
+++ b/main/geometry/inst/shape2d/shapeplot.m	Fri Feb 10 13:22:25 2012 +0000
@@ -17,7 +17,7 @@
 %% @deftypefn {Function File} {@var{h} = } shapeplot (@var{shape})
 %% @deftypefnx {Function File} {@var{h} = } shapeplot (@var{shape}, @var{N})
 %% @deftypefnx {Function File} {@var{h} = } shapeplot (@dots{}, @var{param}, @var{value})
-%% Pots a 2D shape defined by piecewise smooth polynomials.
+%% Pots a 2D shape defined by piecewise smooth polynomials in the current axis.
 %%
 %% @var{pp} is a cell where each elements is a 2-by-(poly_degree+1) matrix
 %% containing a pair of polynomials.