# HG changeset patch # User Rik # Date 1669398072 28800 # Node ID c664627d601efdc9d2e43628a326578d76b01e65 # Parent 85a073f7c5f9ac11e8698e1ab7542c4728b7ce57 tsearchn.m: Use Octave coding conventions. * tsearchn.m: Use function name in error() messages. Use "endif" rather than bare "end". Capitalize function input parameters in error() messages to match documentation. Cuddle parentheses to variable when performing indexing. Use '!' for logical not operator. Use two newlines between end of function and start of BIST tests. Add BIST tests for input validation. diff -r 85a073f7c5f9 -r c664627d601e scripts/geometry/tsearchn.m --- a/scripts/geometry/tsearchn.m Fri Nov 25 11:33:20 2022 -0500 +++ b/scripts/geometry/tsearchn.m Fri Nov 25 09:41:12 2022 -0800 @@ -46,16 +46,16 @@ endif if (columns (x) != columns (xi)) - error ("columns (x) should equal columns (xi)") - end + error ("tsearchn: number of columns of X and XI must match"); + endif if (max (t(:)) > rows (x)) - error ("triangles should only access points in x") - end + error ("tsearchn: triangulation T must not access points outside X"); + endif if (nargout <= 1 && columns (x) == 2) # pass to the faster tsearch.cc idx = tsearch (x(:,1), x(:,2), t, xi(:,1), xi(:,2)); - return + return; endif nt = rows (t); @@ -88,13 +88,14 @@ ## (all (b >= 0) && all (b <= 1)). As sum (b,2) == 1, we only need to ## test all(b>=0). inside = all (b >= -1e-12, 2); # -1e-12 instead of 0 for rounding errors - idx (ni (inside)) = i; + idx(ni(inside)) = i; p(ni(inside), :) = b(inside, :); - ni = ni (~inside); + ni = ni(! inside); endfor endfunction + %!shared x, tri %! x = [-1,-1;-1,1;1,-1]; %! tri = [1, 2, 3]; @@ -118,3 +119,10 @@ %! [idx, p] = tsearchn (x,tri,[1,1]); %! assert (idx, NaN); %! assert (p, [NaN, NaN, NaN]); + +## Test input validation +%!error tsearchn () +%!error tsearchn (1) +%!error tsearchn (1, 2) +%!error tsearchn ([1,2], 3, 4) +%!error tsearchn (1, 2, 3)