## [Octave-cvsupdate] octave-forge/main/general polyarea.m,1.2,1.3

 [Octave-cvsupdate] octave-forge/main/general polyarea.m,1.2,1.3 From: Paul Kienzle - 2005-11-14 01:23:35 ```Update of /cvsroot/octave/octave-forge/main/general In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20538 Modified Files: polyarea.m Log Message: [with Torsten Finke] save half the computation; add simple test Index: polyarea.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/general/polyarea.m,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- polyarea.m 31 Jan 2002 06:09:55 -0000 1.2 +++ polyarea.m 14 Nov 2005 01:23:25 -0000 1.3 @@ -37,13 +37,17 @@ ## 2000-01-15 Paul Kienzle ## * use matlab compatible interface ## * return absolute value of area so traversal order doesn't matter +## 2005-10-13 Torsten Finke +## * optimization saving half the sums and multiplies function a = polyarea (x, y) - if (nargin != 2) + if nargin != 2 usage ("polyarea (x, y)"); elseif any (size(x) != size(y)) error ("polyarea: x and y must have the same shape"); else - a = abs ( sum (x .* shift (y,-1)) - sum (y .* shift (x, -1)) ) / 2; + a = abs (sum (x .* (shift (y, -1) - shift (y, 1)))) / 2; endif endfunction + +%!assert (polyarea([1;1;3;3;1],[1;3;3;1;1]), 4, eps) ```

 [Octave-cvsupdate] octave-forge/main/general polyarea.m,1.2,1.3 From: Paul Kienzle - 2005-11-14 01:23:35 ```Update of /cvsroot/octave/octave-forge/main/general In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20538 Modified Files: polyarea.m Log Message: [with Torsten Finke] save half the computation; add simple test Index: polyarea.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/general/polyarea.m,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- polyarea.m 31 Jan 2002 06:09:55 -0000 1.2 +++ polyarea.m 14 Nov 2005 01:23:25 -0000 1.3 @@ -37,13 +37,17 @@ ## 2000-01-15 Paul Kienzle ## * use matlab compatible interface ## * return absolute value of area so traversal order doesn't matter +## 2005-10-13 Torsten Finke +## * optimization saving half the sums and multiplies function a = polyarea (x, y) - if (nargin != 2) + if nargin != 2 usage ("polyarea (x, y)"); elseif any (size(x) != size(y)) error ("polyarea: x and y must have the same shape"); else - a = abs ( sum (x .* shift (y,-1)) - sum (y .* shift (x, -1)) ) / 2; + a = abs (sum (x .* (shift (y, -1) - shift (y, 1)))) / 2; endif endfunction + +%!assert (polyarea([1;1;3;3;1],[1;3;3;1;1]), 4, eps) ```