diff -r 804e18e3e320 scripts/geometry/convhull.m --- a/scripts/geometry/convhull.m Sun Nov 25 15:39:23 2018 +0100 +++ b/scripts/geometry/convhull.m Mon Nov 26 21:26:57 2018 +0100 @@ -18,6 +18,7 @@ ## -*- texinfo -*- ## @deftypefn {} {@var{H} =} convhull (@var{x}, @var{y}) +## @deftypefnx {} {[@var{H}, @var{V}] =} convhull (@var{x}, @var{y}) ## @deftypefnx {} {@var{H} =} convhull (@var{x}, @var{y}, @var{z}) ## @deftypefnx {} {@var{H} =} convhull (@var{x}) ## @deftypefnx {} {@var{H} =} convhull (@dots{}, @var{options}) @@ -26,6 +27,7 @@ ## The hull @var{H} is a linear index vector into the original set of points ## that specifies which points form the enclosing hull. For 2-D inputs only, ## the output is ordered in a counter-clockwise manner around the hull. +## @var{V} contains the volume of the convex hull. ## ## The input @var{x} may also be a matrix with two or three columns where the ## first column contains x-data, the second y-data, and the optional third @@ -45,7 +47,7 @@ ## @seealso{convhulln, delaunay, voronoi} ## @end deftypefn -function H = convhull (varargin) +function [H, V] = convhull (varargin) if (nargin < 1 || nargin > 4) print_usage (); @@ -119,13 +121,21 @@ if (! size_equal (x, y)) error ("convhull: X and Y must be the same size"); endif - Htmp = convhulln ([x, y], options); + if nargout > 1 + [Htmp, V] = convhulln ([x, y], options); + else + Htmp = convhulln ([x, y], options); + endif else x = x(:); y = y(:); z = z(:); if (! size_equal (x, y, z)) error ("convhull: X, Y, and Z must be the same size"); endif - H = convhulln ([x, y, z], options); + if nargout > 1 + [H, V] = convhulln ([x, y, z], options); + else + H = convhulln ([x, y, z], options); + endif endif if (isempty (z)) @@ -169,6 +179,10 @@ %! y = abs (sin (x)); %! assert (convhull (x, y), [1;7;13;12;11;10;4;3;2;1]); +%!testif HAVE_QHULL +%! [~, v] = convhull([0,1,1,0],[0,0,1,1]); +%! assert (v == 1); + ## Input validation tests %!error convhull () %!error convhull (1,2,3,4,5)