# HG changeset patch # User Rik # Date 1411875413 25200 # Node ID 4318cb91deacdb3a600e9909e305ef9474493a4c # Parent 702aa79dc482b46f5196f11d6f3d8d8a7f3827c6 delaunayn.m: Slight performance increase and addition of BIST tests. * delaunayn.m: Calculate tolerance condition just once rather than every time in loop. Use sumsq rather than sum (x.^2) for another slight performance gain. Add BIST tests. diff -r 702aa79dc482 -r 4318cb91deac scripts/geometry/delaunayn.m --- a/scripts/geometry/delaunayn.m Sat Sep 27 20:21:46 2014 -0700 +++ b/scripts/geometry/delaunayn.m Sat Sep 27 20:36:53 2014 -0700 @@ -59,9 +59,9 @@ T = __delaunayn__ (pts, varargin{:}); if (isa (pts, "single")) - myeps = eps ("single"); + tol = 1e3 * eps ("single"); else - myeps = eps; + tol = 1e3 * eps; endif ## Try to remove the zero volume simplices. The volume of the i-th simplex is @@ -78,7 +78,7 @@ ## FIXME: Vectorize this for loop or convert delaunayn to .oct function for i = 1:nt X = pts(T(i,1:end-1),:) - pts(T(i,2:end),:); - if (abs (det (X)) / sqrt (sum (X .^ 2, 2)) < 1e3 * myeps) + if (abs (det (X)) / sqrt (sumsq (X, 2)) < tol) idx(end+1) = i; endif endfor @@ -87,7 +87,17 @@ endfunction +%!testif HAVE_QHULL +%! x = [-1, 0; 0, 1; 1, 0; 0, -1; 0, 0]; +%! assert (sortrows (sort (delaunayn (x), 2)), [1,2,5;1,4,5;2,3,5;3,4,5]); + +## Test 3-D input +%!testif HAVE_QHULL +%! x = [-1, -1, 1, 0, -1]; y = [-1, 1, 1, 0, -1]; z = [0, 0, 0, 1, 1]; +%! assert (sortrows (sort (delaunayn ([x(:) y(:) z(:)]), 2)), [1,2,3,4;1,2,4,5]) + %% FIXME: Need tests for delaunayn -%% FIXME: Need input validation tests +%% Input validation tests +%!error delaunayn ()