changeset 24315:0d4db91b7299

maint: periodic merge of stable to default.
author Rik <rik@octave.org>
date Sun, 26 Nov 2017 21:06:04 -0800
parents 7ba994876f3a (current diff) 678912855789 (diff)
children 01fc0e70d4c1
files libgui/src/m-editor/file-editor-tab.cc scripts/plot/draw/trimesh.m scripts/plot/draw/trisurf.m
diffstat 2 files changed, 39 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/draw/trimesh.m	Sun Nov 26 20:59:28 2017 -0800
+++ b/scripts/plot/draw/trimesh.m	Sun Nov 26 21:06:04 2017 -0800
@@ -39,9 +39,10 @@
 ## change the colormap to control the appearance.
 ##
 ## Optionally, the color of the mesh can be specified independently of @var{z}
-## by supplying a color matrix, @var{c}.  If @var{z} has N elements, then
-## @var{c} should be an Nx1 vector for colormap data or an Nx3 matrix for
-## RGB data.
+## by supplying @var{c}, which is a vector for colormap data, or a matrix with
+## three columns for RGB data.  The number of colors specified in @var{c} must
+## either equal the number of vertices in @var{z} or the number of triangles
+## in @var{tri}.
 ##
 ## Any property/value pairs are passed directly to the underlying patch object.
 ##
@@ -66,12 +67,12 @@
       c = varargin{1};
       varargin(1) = [];
       if (isvector (c))
-        if (numel (c) != numel (z))
-          error ("trimesh: C must have 'numel (Z)' elements");
-        endif
         c = c(:);
-      elseif (rows (c) != numel (z) || columns (c) != 3)
-        error ("trimesh: TrueColor C matrix must be 'numel (Z)' rows by 3 columns");
+      end
+      if (rows (c) != numel (z) && rows (c) != rows (tri))
+        error ("trimesh: the numbers of colors specified in C must equal the number of vertices in Z or the number of triangles in TRI");
+      elseif (columns (c) != 1 && columns (c) != 3)
+        error ("trimesh: TrueColor C matrix must have 3 columns");
       endif
     else
       c = z(:);
@@ -80,10 +81,11 @@
     hax = newplot ();
 
     ## Tag object as "trimesh" so that hidden() can find it.
-    htmp = patch ("Vertices", [x(:), y(:), z(:)], "Faces", tri,
+    htmp = patch ("Faces", tri, "Vertices", [x(:), y(:), z(:)],
                   "FaceVertexCdata", c, "EdgeColor", "flat", "FaceColor", "w",
                   "FaceLighting", "none", "EdgeLighting", "flat",
                   "Tag", "trimesh", varargin{:});
+
     if (! ishold ())
       set (hax, "view", [-37.5, 30],
                 "xgrid", "on", "ygrid", "on", "zgrid", "on");
@@ -114,7 +116,8 @@
 %!error trimesh ()
 %!error trimesh (1)
 %!error trimesh (1,2)
-%!error <C must have 'numel \(Z\)' elements> trimesh (1,2,3,4,[5 6])
-%!error <C must have 'numel \(Z\)' elements> trimesh (1,2,3,4,[5 6]')
-%!error <TrueColor C matrix must> trimesh ([1;1],[2;2],[3;3],[4;4],zeros(3,3))
-%!error <TrueColor C matrix must> trimesh ([1;1],[2;2],[3;3],[4;4],zeros(2,2))
+%!error <the numbers of colors> trimesh (1,2,3,4,[5 6])
+%!error <the numbers of colors> trimesh (1,2,3,4,[5 6]')
+%!error <the numbers of colors> trimesh ([1;1],[2;2],[3;3],[4;4], zeros (3,3))
+%!error <TrueColor C matrix must have 3 columns>
+%! trimesh ([1;1],[2;2],[3;3],[4;4],zeros (2,2))
--- a/scripts/plot/draw/trisurf.m	Sun Nov 26 20:59:28 2017 -0800
+++ b/scripts/plot/draw/trisurf.m	Sun Nov 26 21:06:04 2017 -0800
@@ -28,18 +28,22 @@
 ##
 ## @var{tri} is typically the output of a Delaunay triangulation over the
 ## grid of @var{x}, @var{y}.  Every row of @var{tri} represents one triangle
-## and contains three indices into [@var{x}, @var{y}] which are the
-## vertices of the triangles in the x-y plane.  @var{z} determines the
-## height above the plane of each vertex.
+## and contains three indices into [@var{x}, @var{y}] which are the vertices of
+## the triangles in the x-y plane.  @var{z} determines the height above the
+## plane of each vertex.
 ##
-## The color of the trimesh is computed by linearly scaling the @var{z} values
-## to fit the range of the current colormap.  Use @code{caxis} and/or
-## change the colormap to control the appearance.
+## The color of the trisurf is computed by linearly scaling the @var{z} values
+## to fit the range of the current colormap.  Use @code{caxis} and/or change
+## the colormap to control the appearance.
 ##
 ## Optionally, the color of the mesh can be specified independently of @var{z}
-## by supplying a color matrix, @var{c}.  If @var{z} has N elements, then
-## @var{c} should be an Nx1 vector for colormap data or an Nx3 matrix for
-## RGB data.
+## by supplying @var{c}, which is a vector for colormap data, or a matrix with
+## three columns for RGB data.  The number of colors specified in @var{c} must
+## either equal the number of vertices in @var{z} or the number of triangles
+## in @var{tri}.  When specifying the color at each vertex the triangle will
+## be colored according to the color of the first vertex only (see patch
+## documentation and the @qcode{"FaceColor"} property when set to
+## @qcode{"flat"}).
 ##
 ## Any property/value pairs are passed directly to the underlying patch object.
 ##
@@ -58,12 +62,12 @@
     c = varargin{1};
     varargin(1) = [];
     if (isvector (c))
-      if (numel (c) != numel (z))
-        error ("trisurf: C must have 'numel (Z)' elements");
-      endif
       c = c(:);
-    elseif (rows (c) != numel (z) || columns (c) != 3)
-      error ("trisurf: TrueColor C matrix must be 'numel (Z)' rows by 3 columns");
+    end
+    if (rows (c) != numel (z) && rows (c) != rows (tri))
+      error ("trisurf: the numbers of colors specified in C must equal the number of vertices in Z or the number of triangles in TRI");
+    elseif (columns (c) != 1 && columns (c) != 3)
+      error ("trisurf: TrueColor C matrix must have 3 columns");
     endif
   else
     c = z(:);
@@ -161,7 +165,8 @@
 %!error trisurf (1)
 %!error trisurf (1,2)
 %!error trisurf (1,2,3)
-%!error <C must have 'numel \(Z\)' elements> trisurf (1,2,3,4,[5 6])
-%!error <C must have 'numel \(Z\)' elements> trisurf (1,2,3,4,[5 6]')
-%!error <TrueColor C matrix must> trisurf ([1;1],[2;2],[3;3],[4;4],zeros(3,3))
-%!error <TrueColor C matrix must> trisurf ([1;1],[2;2],[3;3],[4;4],zeros(2,2))
+%!error <the numbers of colors> trisurf (1,2,3,4,[5 6])
+%!error <the numbers of colors> trisurf (1,2,3,4,[5 6]')
+%!error <the numbers of colors> trisurf ([1;1],[2;2],[3;3],[4;4], zeros (3,3))
+%!error <TrueColor C matrix must have 3 columns>
+%! trisurf ([1;1],[2;2],[3;3],[4;4], zeros (2,2))