Mercurial > hg > octave-terminal
changeset 13203:b6aba5b4edb1
voronoin: accept options as a cell array of character strings
* __voronoi__.cc (F__voronoi__): Accept options as cell array of
character strings. Use std::string for buffer. Don't use fixed size
for char* buffer that is passed to qh_new_qhull.
* voronoin.m: Accept options as cell array of character strings.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 23 Sep 2011 15:03:29 -0400 |
parents | 92095e0ba372 |
children | be7bfd59300a |
files | scripts/geometry/voronoin.m src/DLD-FUNCTIONS/__voronoi__.cc |
diffstat | 2 files changed, 19 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/geometry/voronoin.m +++ b/scripts/geometry/voronoin.m @@ -47,10 +47,10 @@ if (np > dims) if (nargin == 1) [C, F, infi] = __voronoi__ (pts); - elseif (ischar (options)) + elseif (ischar (options) || iscellstr (options)) [C, F, infi] = __voronoi__ (pts, options); else - error ("voronoin: second argument must be a string"); + error ("voronoin: second argument must be a string or cell array of strings"); endif else
--- a/src/DLD-FUNCTIONS/__voronoi__.cc +++ b/src/DLD-FUNCTIONS/__voronoi__.cc @@ -73,20 +73,25 @@ return retval; } - const char *options; + std::string options = "qhull v Fv T0"; if (nargin == 2) { - if (! args (1).is_string ()) + if (args(1).is_cellstr ()) { - error ("__voronoi__: OPTIONS argument must be a string"); + Array<std::string> tmp = args(1).cellstr_value (); + + for (octave_idx_type i = 0; i < tmp.numel (); i++) + options += " " + tmp(i); + } + else if (args(1).is_string ()) + options += " " + args(1).string_value (); + else + { + error ("__voronoi__: OPTIONS argument must be a string or cellstr"); return retval; } - - options = args (1).string_value().c_str (); } - else - options = ""; Matrix p (args(0).matrix_value ()); @@ -107,17 +112,17 @@ boolT ismalloc = false; - OCTAVE_LOCAL_BUFFER (char, flags, 250); - - // hmm lot's of options for qhull here - sprintf (flags, "qhull v Fv T0 %s", options); - // If you want some debugging information replace the 0 pointer // with stdout or some other file open for writing. FILE *outfile = 0; FILE *errfile = stderr; + // Qhull flags argument is not const char*... + OCTAVE_LOCAL_BUFFER (char, flags, options.length () + 1); + + strcpy (flags, options.c_str ()); + if (! qh_new_qhull (dim, np, pt_array, ismalloc, flags, outfile, errfile)) { facetT *facet;