Mercurial > octave
comparison scripts/geometry/delaunayn.m @ 19172: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 | ba167badef9f |
children | 0e1f5a750d00 |
comparison
equal
deleted
inserted
replaced
19171:702aa79dc482 | 19172:4318cb91deac |
---|---|
57 endif | 57 endif |
58 | 58 |
59 T = __delaunayn__ (pts, varargin{:}); | 59 T = __delaunayn__ (pts, varargin{:}); |
60 | 60 |
61 if (isa (pts, "single")) | 61 if (isa (pts, "single")) |
62 myeps = eps ("single"); | 62 tol = 1e3 * eps ("single"); |
63 else | 63 else |
64 myeps = eps; | 64 tol = 1e3 * eps; |
65 endif | 65 endif |
66 | 66 |
67 ## Try to remove the zero volume simplices. The volume of the i-th simplex is | 67 ## Try to remove the zero volume simplices. The volume of the i-th simplex is |
68 ## given by abs(det(pts(T(i,1:end-1),:)-pts(T(i,2:end),:)))/prod(1:n) | 68 ## given by abs(det(pts(T(i,1:end-1),:)-pts(T(i,2:end),:)))/prod(1:n) |
69 ## (reference http://en.wikipedia.org/wiki/Simplex). Any simplex with a | 69 ## (reference http://en.wikipedia.org/wiki/Simplex). Any simplex with a |
76 idx = []; | 76 idx = []; |
77 [nt, n] = size (T); | 77 [nt, n] = size (T); |
78 ## FIXME: Vectorize this for loop or convert delaunayn to .oct function | 78 ## FIXME: Vectorize this for loop or convert delaunayn to .oct function |
79 for i = 1:nt | 79 for i = 1:nt |
80 X = pts(T(i,1:end-1),:) - pts(T(i,2:end),:); | 80 X = pts(T(i,1:end-1),:) - pts(T(i,2:end),:); |
81 if (abs (det (X)) / sqrt (sum (X .^ 2, 2)) < 1e3 * myeps) | 81 if (abs (det (X)) / sqrt (sumsq (X, 2)) < tol) |
82 idx(end+1) = i; | 82 idx(end+1) = i; |
83 endif | 83 endif |
84 endfor | 84 endfor |
85 T(idx,:) = []; | 85 T(idx,:) = []; |
86 | 86 |
87 endfunction | 87 endfunction |
88 | 88 |
89 | 89 |
90 %!testif HAVE_QHULL | |
91 %! x = [-1, 0; 0, 1; 1, 0; 0, -1; 0, 0]; | |
92 %! assert (sortrows (sort (delaunayn (x), 2)), [1,2,5;1,4,5;2,3,5;3,4,5]); | |
93 | |
94 ## Test 3-D input | |
95 %!testif HAVE_QHULL | |
96 %! x = [-1, -1, 1, 0, -1]; y = [-1, 1, 1, 0, -1]; z = [0, 0, 0, 1, 1]; | |
97 %! assert (sortrows (sort (delaunayn ([x(:) y(:) z(:)]), 2)), [1,2,3,4;1,2,4,5]) | |
98 | |
90 %% FIXME: Need tests for delaunayn | 99 %% FIXME: Need tests for delaunayn |
91 | 100 |
92 %% FIXME: Need input validation tests | 101 %% Input validation tests |
102 %!error delaunayn () | |
93 | 103 |