# HG changeset patch # User John W. Eaton # Date 1321555632 18000 # Node ID 440d7914cf017b6c0ff8185fc4199a9323a1e675 # Parent 0d32a681d943525aa8e6632be99a475a20be2d80 fix regression in __voronoi__ and convhulln option processing * __voronoi__.cc (F__voronoi__): Allow user-supplied options to completely replace defaults. * convhulln.cc (F__convhulln__): Likewise. * __voronoi__.cc (F__voronoi__): New argument, caller. * voronoi.m, voronoin.m: Pass name of function to __voronoi__. * voronoin.m: Don't check options here. * voronoi.m: Don't check nargout. diff -r 0d32a681d943 -r 440d7914cf01 scripts/geometry/voronoi.m --- a/scripts/geometry/voronoi.m Thu Nov 17 05:22:35 2011 -0500 +++ b/scripts/geometry/voronoi.m Thu Nov 17 13:47:12 2011 -0500 @@ -70,8 +70,6 @@ if (nargin < 1) print_usage (); - elseif (nargout > 2) - error ("voronoi: No more than two output arguments supported"); endif narg = 1; @@ -131,7 +129,9 @@ ybox = [xmin - scale * xdelta; xmax + scale * xdelta; ... xmax + scale * xdelta; xmin - scale * xdelta]; - [p, c, infi] = __voronoi__ ([[x(:) ; xbox(:)], [y(:); ybox(:)]], opts{:}); + [p, c, infi] = __voronoi__ ("voronoi", + [[x(:) ; xbox(:)], [y(:); ybox(:)]], + opts{:}); idx = find (! infi); ll = length (idx); diff -r 0d32a681d943 -r 440d7914cf01 scripts/geometry/voronoin.m --- a/scripts/geometry/voronoin.m Thu Nov 17 05:22:35 2011 -0500 +++ b/scripts/geometry/voronoin.m Thu Nov 17 13:47:12 2011 -0500 @@ -48,14 +48,14 @@ if (np <= dim) error ("voronoin: number of points must be greater than their dimension"); - elseif (nargin == 2 && ! (ischar (options) || iscellstr (options))) - error ("voronoin: OPTIONS argument must be a string or cell array of strings"); endif + caller = "voronoin"; + if (nargin == 1) - [C, F] = __voronoi__ (pts); + [C, F] = __voronoi__ (caller, pts); else - [C, F] = __voronoi__ (pts, options); + [C, F] = __voronoi__ (caller, pts, options); endif endfunction diff -r 0d32a681d943 -r 440d7914cf01 src/DLD-FUNCTIONS/__voronoi__.cc --- a/src/DLD-FUNCTIONS/__voronoi__.cc Thu Nov 17 05:22:35 2011 -0500 +++ b/src/DLD-FUNCTIONS/__voronoi__.cc Thu Nov 17 13:47:12 2011 -0500 @@ -57,8 +57,8 @@ DEFUN_DLD (__voronoi__, args, , "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{pts})\n\ -@deftypefnx {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{pts}, @var{options})\n\ +@deftypefn {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts})\n\ +@deftypefnx {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts}, @var{options})\n\ @deftypefnx {Loadable Function} {@var{C}, @var{F}, @var{Inf_Pts} =} __voronoi__ (@dots{})\n\ Undocumented internal function.\n\ @end deftypefn") @@ -70,45 +70,61 @@ retval(0) = 0.0; int nargin = args.length (); - if (nargin < 1 || nargin > 2) + if (nargin < 2 || nargin > 3) { print_usage (); return retval; } - std::string cmd = "qhull v"; - - if (nargin == 2 && ! args(1).is_empty ()) - { - if (args(1).is_string ()) - cmd += " " + args(1).string_value (); - else if (args(1).is_cellstr ()) - { - Array tmp = args(1).cellstr_value (); + std::string caller = args(0).string_value (); - for (octave_idx_type i = 0; i < tmp.numel (); i++) - cmd += " " + tmp(i); - } - else - { - error ("__voronoi__: OPTIONS argument must be a string, cell array of strings, or empty"); - return retval; - } - } - - Matrix points (args(0).matrix_value ()); + Matrix points = args(1).matrix_value (); const octave_idx_type dim = points.columns (); const octave_idx_type num_points = points.rows (); points = points.transpose (); + std::string options; + + if (dim <= 4) + options = " Qbb"; + else + options = " Qbb Qx"; + + if (nargin == 3) + { + octave_value opt_arg = args(2); + + if (opt_arg.is_string ()) + options = " " + args(1).string_value (); + else if (opt_arg.is_empty ()) + ; // Use default options. + else if (args(1).is_cellstr ()) + { + options = ""; + + Array tmp = opt_arg.cellstr_value (); + + for (octave_idx_type i = 0; i < tmp.numel (); i++) + options += " " + tmp(i); + } + else + { + error ("%s: OPTIONS must be a string, cell array of strings, or empty", + caller.c_str ()); + return retval; + } + } + boolT ismalloc = false; // Replace the 0 pointer with stdout for debugging information FILE *outfile = 0; FILE *errfile = stderr; - // Qhull flags and points arguments are not const... + // qh_new_qhull command and points arguments are not const... + + std::string cmd = "qhull v" + options; OCTAVE_LOCAL_BUFFER (char, cmd_str, cmd.length () + 1); @@ -275,7 +291,7 @@ retval(0) = F; } else - error ("__voronoi__: qhull failed"); + error ("%s: qhull failed", caller.c_str ()); // Free memory from Qhull qh_freeqhull (! qh_ALL); @@ -284,11 +300,11 @@ qh_memfreeshort (&curlong, &totlong); if (curlong || totlong) - warning ("__voronoi__: did not free %d bytes of long memory (%d pieces)", - totlong, curlong); + warning ("%s: qhull did not free %d bytes of long memory (%d pieces)", + caller.c_str (), totlong, curlong); #else - error ("__voronoi__: not available in this version of Octave"); + error ("%s: not available in this version of Octave", caller.c_str ()); #endif return retval; diff -r 0d32a681d943 -r 440d7914cf01 src/DLD-FUNCTIONS/convhulln.cc --- a/src/DLD-FUNCTIONS/convhulln.cc Thu Nov 17 05:22:35 2011 -0500 +++ b/src/DLD-FUNCTIONS/convhulln.cc Thu Nov 17 13:47:12 2011 -0500 @@ -100,23 +100,27 @@ points = points.transpose (); - std::string cmd = "qhull"; + std::string options; if (dim <= 4) - cmd += " Qt"; + options = " Qt"; else - cmd += " Qt Qx"; + options = " Qt Qx"; - if (nargin == 2 && ! args(1).is_empty ()) + if (nargin == 2) { if (args(1).is_string ()) - cmd += " " + args(1).string_value (); + options = " " + args(1).string_value (); + else if (args(1).is_empty ()) + ; // Use default options. else if (args(1).is_cellstr ()) { + options = ""; + Array tmp = args(1).cellstr_value (); for (octave_idx_type i = 0; i < tmp.numel (); i++) - cmd += " " + tmp(i); + options += " " + tmp(i); } else { @@ -131,7 +135,9 @@ FILE *outfile = 0; FILE *errfile = stderr; - // Qhull flags and points arguments are not const... + // qh_new_qhull command and points arguments are not const... + + std::string cmd = "qhull" + options; OCTAVE_LOCAL_BUFFER (char, cmd_str, cmd.length () + 1);