changeset 19206:4318cb91deac

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.
author Rik <rik@octave.org>
date Sat, 27 Sep 2014 20:36:53 -0700
parents 702aa79dc482
children 3d24778a8b12
files scripts/geometry/delaunayn.m
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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 ()