# HG changeset patch # User Arun Giridhar # Date 1669394000 18000 # Node ID 85a073f7c5f9ac11e8698e1ab7542c4728b7ce57 # Parent 8459f7f216790398d2c0e3e26926958472e84b94# Parent 2f08a53e0a23e24a7220162f32011cd4f53ab20c maint: Merge away extra head diff -r 2f08a53e0a23 -r 85a073f7c5f9 libgui/languages/zh_CN.ts --- a/libgui/languages/zh_CN.ts Fri Nov 25 08:30:30 2022 -0800 +++ b/libgui/languages/zh_CN.ts Fri Nov 25 11:33:20 2022 -0500 @@ -6,7 +6,7 @@ Invalid filename - + 无效的文件名 @@ -1359,7 +1359,9 @@ The file %1 is not a valid XBEL file version 1.0. - + 文件 +%1 +不是合法的XBEL 1.0版本文件。 @@ -2054,7 +2056,8 @@ The changes could not be saved to the file %1 - + 改动无法保存到文件 +%1 @@ -3596,7 +3599,7 @@ Color of highlighted current line (magenta (255,0,255) for automatic color) - + 当前行高亮显示的颜色 (品红 (255,0,255) 为自动颜色) @@ -4389,7 +4392,8 @@ Add Shift modifier (allows one to enter number keys) - + 添加Shift修改器 +(允许输入数字键) @@ -5256,7 +5260,7 @@ Dock widgets window icons - + 停靠组件窗口图标 @@ -5266,7 +5270,7 @@ Icon theme (requires restart) - + 图标样式(需要重启) @@ -5306,7 +5310,7 @@ Highlight current line (color adjustable below with editor styles) - + 高亮当前行(颜色可用下方编辑器样式调整) @@ -5631,7 +5635,7 @@ Disable menu accelerators of main window menus when Command Window has focus - + 当命令窗口获得焦点时,禁用主窗口的菜单快捷键 diff -r 2f08a53e0a23 -r 85a073f7c5f9 scripts/geometry/tsearchn.m --- a/scripts/geometry/tsearchn.m Fri Nov 25 08:30:30 2022 -0800 +++ b/scripts/geometry/tsearchn.m Fri Nov 25 11:33:20 2022 -0500 @@ -26,15 +26,17 @@ ## -*- texinfo -*- ## @deftypefn {} {@var{idx} =} tsearchn (@var{x}, @var{t}, @var{xi}) ## @deftypefnx {} {[@var{idx}, @var{p}] =} tsearchn (@var{x}, @var{t}, @var{xi}) -## Search for the enclosing Delaunay convex hull. +## Find the simplexes enclosing the given points. ## -## For @code{@var{t} = delaunayn (@var{x})}, finds the index in @var{t} -## containing the points @var{xi}. For points outside the convex hull, -## @var{idx} is NaN. +## @code{tsearchn} is typically used with @code{delaunayn}: +## @code{@var{t} = delaunayn (@var{x})} returns a set of simplexes @code{t}, +## then @code{tsearchn} returns the row index of @var{t} containing each point +## of @var{xi}. For points outside the convex hull, @var{idx} is NaN. ## -## If requested @code{tsearchn} also returns the Barycentric coordinates -## @var{p} of the enclosing triangles. -## @seealso{delaunay, delaunayn} +## If requested, @code{tsearchn} also returns the barycentric coordinates +## @var{p} of the enclosing simplexes. +## +## @seealso{delaunay, delaunayn, tsearch} ## @end deftypefn function [idx, p] = tsearchn (x, t, xi) @@ -43,61 +45,56 @@ print_usage (); endif + if (columns (x) != columns (xi)) + error ("columns (x) should equal columns (xi)") + end + + if (max (t(:)) > rows (x)) + error ("triangles should only access points in x") + end + + if (nargout <= 1 && columns (x) == 2) # pass to the faster tsearch.cc + idx = tsearch (x(:,1), x(:,2), t, xi(:,1), xi(:,2)); + return + endif + nt = rows (t); [m, n] = size (x); mi = rows (xi); idx = NaN (mi, 1); p = NaN (mi, n + 1); + ni = [1:mi].'; - ni = [1:mi].'; - for i = 1 : nt - ## Only calculate the Barycentric coordinates for points that have not - ## already been found in a triangle. - b = cart2bary (x (t (i, :), :), xi(ni,:)); + for i = 1 : nt # each simplex in turn + + T = x(t(i, :), :); # T is the current simplex + P = xi(ni, :); # P is the set of points left to calculate - ## Our points xi are in the current triangle if - ## (all (b >= 0) && all (b <= 1)). However as we impose that - ## sum (b,2) == 1 we only need to test all(b>=0). Note need to add - ## a small margin for rounding errors - intri = all (b >= -1e-12, 2); - idx(ni(intri)) = i; - p(ni(intri),:) = b(intri, :); - ni(intri) = []; + ## Convert to barycentric coords: these are used to express a point P + ## as P = Beta * T + ## where T is a simplex. + ## + ## If 0 <= Beta <= 1, then the linear combination is also convex, + ## and the point P is inside the simplex T, otherwise it is outside. + ## Since the equation system is underdetermined, we apply the constraint + ## sum (Beta) == 1 to make it unique up to scaling. + ## + ## Note that the code below is vectorized over P, one point per row. + + b = (P - T(end,:)) / (T(1:end-1,:) - T(end,:)); + b(:, end+1) = 1 - sum (b, 2); + + ## The points xi are inside the current simplex if + ## (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; + p(ni(inside), :) = b(inside, :); + ni = ni (~inside); endfor endfunction -function Beta = cart2bary (T, P) - - ## Conversion of Cartesian to Barycentric coordinates. - ## Given a reference simplex in N dimensions represented by an - ## N+1-by-N matrix, an arbitrary point P in Cartesian coordinates, - ## represented by an N-by-1 column vector can be written as - ## - ## P = Beta * T - ## - ## Where Beta is an N+1 vector of the barycentric coordinates. A criteria - ## on Beta is that - ## - ## sum (Beta) == 1 - ## - ## and therefore we can write the above as - ## - ## P - T(end, :) = Beta(1:end-1) * (T(1:end-1,:) - ones (N,1) * T(end,:)) - ## - ## and then we can solve for Beta as - ## - ## Beta(1:end-1) = (P - T(end,:)) / (T(1:end-1,:) - ones (N,1) * T(end,:)) - ## Beta(end) = sum (Beta) - ## - ## Note code below is generalized for multiple values of P, one per row. - [M, N] = size (P); - Beta = (P - ones (M,1) * T(end,:)) / (T(1:end-1,:) - ones (N,1) * T(end,:)); - Beta (:,end+1) = 1 - sum (Beta, 2); - -endfunction - - %!shared x, tri %! x = [-1,-1;-1,1;1,-1]; %! tri = [1, 2, 3];