changeset 8460:e4c9ecb64411

diffuse.m, specular.m, surfl.m: style fixes
author John W. Eaton <jwe@octave.org>
date Mon, 12 Jan 2009 11:47:09 -0500
parents d17874a6f161
children 9d456730b7a8
files scripts/ChangeLog scripts/plot/diffuse.m scripts/plot/specular.m scripts/plot/surfl.m
diffstat 4 files changed, 45 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Mon Jan 12 14:03:28 2009 +0100
+++ b/scripts/ChangeLog	Mon Jan 12 11:47:09 2009 -0500
@@ -1,3 +1,7 @@
+2009-01-12  John W. Eaton  <jwe@octave.org>
+
+	* plot/diffuse.m, plot/surfl.m, plot/specular.m: Style fixes.
+
 2009-01-11  Jaroslav Hajek  <highegg@gmail.com>
 
 	* general/sortrows.m: Fix invalid `{x:y} = z' assignment.
--- a/scripts/plot/diffuse.m	Mon Jan 12 14:03:28 2009 +0100
+++ b/scripts/plot/diffuse.m	Mon Jan 12 11:47:09 2009 -0500
@@ -30,24 +30,23 @@
 
 function retval = diffuse (sx, sy, sz, lv)
 
-  ## general checks
   if (nargin != 4)
-    usage ("number of arguments must be 4")
+    print_usage ();
   endif
 
   ## check for normal vector
   if (!size_equal (sx, sy, sz))
-    usage ("SX, SY, and SZ must have same size")
+    error ("diffuse: SX, SY, and SZ must have same size");
   endif
   
   ## check for light vector (lv) argument
   if (length (lv) < 2 || length (lv) > 3)
-    usage ("light vector LV must be a 2- or 3-element vector");
+    error ("diffuse: light vector LV must be a 2- or 3-element vector");
   elseif (length (lv) == 2)
     [lv(1), lv(2), lv(3)] = sph2cart (lv(1) * pi/180, lv(2) * pi/180, 1.0);
   endif
 
-  ## normalize view and light vector
+  ## Normalize view and light vector.
   if (sum (abs (lv)) > 0)
     lv  /= norm (lv);
   endif
--- a/scripts/plot/specular.m	Mon Jan 12 14:03:28 2009 +0100
+++ b/scripts/plot/specular.m	Mon Jan 12 11:47:09 2009 -0500
@@ -31,40 +31,39 @@
 
 function retval = specular (sx, sy, sz, lv, vv, se)
 
-  ## general checks
-  if ((nargin < 5) || (nargin > 6))
-    usage ("number of arguments must be 5 or 6")
+  if (nargin < 5 || nargin > 6)
+    print_usage ();
   endif
 
-  ## checks for specular exponent (se)
+  ## Checks for specular exponent (se).
   if (nargin < 6)
     se = 10;
   else
-    if (!isnumeric (se) || (numel (se) != 1) || (se <= 0))
-      usage ("specular exponent must be positive scalar");
+    if (!isnumeric (se) || numel (se) != 1 || se <= 0)
+      error ("specular: exponent must be positive scalar");
     endif
   endif
 
-  ## checks for normal vector
+  ## Checks for normal vector.
   if (!size_equal (sx, sy, sz))
-    usage ("SX, SY, and SZ must have same size")
+    error ("specular: SX, SY, and SZ must have same size");
   endif
   
-  ## check for light vector (lv) argument
+  ## Check for light vector (lv) argument.
   if (length (lv) < 2 || length (lv) > 3)
-    usage ("light vector LV must be a 2- or 3-element vector");
+    error ("specular: light vector LV must be a 2- or 3-element vector");
   elseif (length (lv) == 2)
     [lv(1), lv(2), lv(3)] = sph2cart (lv(1) * pi/180, lv(2) * pi/180, 1.0);
   endif
 
-  ## check for view vector (vv) argument
-  if ((length (vv) < 2) || (length (lv) > 3))
+  ## Check for view vector (vv) argument.
+  if (length (vv) < 2 || length (lv) > 3)
     error ("view vector VV must be a 2- or 3-element vector");
   elseif (length (vv) == 2)
     [vv(1), vv(2), vv(3)] = sph2cart (vv(1) * pi / 180, vv(2) * pi / 180, 1.0);
   endif
 
-  ## normalize view and light vector
+  ## Normalize view and light vector.
   if (sum (abs (lv)) > 0)
     lv  /= norm (lv);
   endif
@@ -72,18 +71,18 @@
     vv  /= norm (vv);
   endif
 
-  ## calculate normal vector lengths and dot-products
+  ## Calculate normal vector lengths and dot-products.
   ns = sqrt (sx.^2 + sy.^2 + sz.^2);
   l_dot_n = (sx * lv(1) + sy * lv(2) + sz * lv(3)) ./ ns;
   v_dot_n = (sx * vv(1) + sy * vv(2) + sz * vv(3)) ./ ns;
 
-  ## calculate specular reflection using Phong's approximation
+  ## Calculate specular reflection using Phong's approximation.
   retval = 2 * l_dot_n .* v_dot_n - dot (lv, vv);
   
-  ## set zero if light is on the other side
+  ## Set zero if light is on the other side.
   retval(l_dot_n < 0) = 0;
 
-  ## allow postive values only
+  ## Allow postive values only.
   retval(retval < 0) = 0;
   retval = retval .^ se;
   
--- a/scripts/plot/surfl.m	Mon Jan 12 14:03:28 2009 +0100
+++ b/scripts/plot/surfl.m	Mon Jan 12 11:47:09 2009 -0500
@@ -68,38 +68,37 @@
     axes (h);
     newplot ();
 
-    ## check for lighting type
+    ## Check for lighting type.
     use_cdata = true;
     if (ischar (varargin{end}))
       lstr = varargin{end};
-      if strncmp (tolower (lstr), "light", 5)
+      if (strncmp (tolower (lstr), "light", 5))
         warning ("light method not supported (yet), using cdata method instead");
-        # this can be implemented when light objects are being
-        # supported.
+	## This can be implemented when light objects are supported.
         use_cdata = false;
       elseif (strncmp (tolower (lstr), "cdata", 5))
         use_cdata = true;
       else
-        usage ("unknown lighting method");
+        error ("surfl: unknown lighting method");
       endif
       varargin(end) = [];
     endif
 
-    ## check for reflection properties argument
+    ## Check for reflection properties argument.
+    ##
     ## r = [ambient light strength,
     ##      diffuse reflection strength,
     ##      specular reflection strength,
     ##      specular shine] 
-    if ((length (varargin{end}) == 4) && isnumeric (varargin{end}))
+    if (length (varargin{end}) == 4 && isnumeric (varargin{end}))
       r = varargin{end};
       varargin(end) = [];
     else
-      ## default values
+      ## Default values.
       r = [0.55, 0.6, 0.4, 10];
     endif
-    
 
-    ## check for light vector (lv) argument
+    ## Check for light vector (lv) argument.
     have_lv = false;
     if (isnumeric (varargin{end}))
       len = numel (varargin{end});
@@ -121,35 +120,35 @@
 	   "xgrid", "on", "ygrid", "on", "zgrid", "on", "clim", [0 1]);
     endif
 
-    ## get view vector (vv)
+    ## Get view vector (vv).
     a = axis;
     [az, el] = view;
     [vv(1), vv(2), vv(3)] = sph2cart ((az - 90) * pi/180.0, el * pi/180.0, 1.0);
     vv /= norm (vv);
 
     if (!have_lv)
-      ## calculate light vector (lv) from view vector
+      ## Calculate light vector (lv) from view vector.
       Phi = 45.0 / 180.0 * pi;
-      R = [cos(Phi), -sin(Phi), 0;\
-           sin(Phi),  cos(Phi), 0;\
+      R = [cos(Phi), -sin(Phi), 0;
+           sin(Phi),  cos(Phi), 0;
            0,          0,         1];
       lv = (R * vv.').';
     endif
 
     vn = get (tmp, "vertexnormals");
     dar = get (h, "dataaspectratio");
-    vn(:, :, 1) *= dar(1);
-    vn(:, :, 2) *= dar(2);
-    vn(:, :, 3) *= dar(3);
+    vn(:,:,1) *= dar(1);
+    vn(:,:,2) *= dar(2);
+    vn(:,:,3) *= dar(3);
 
-    ## normalize vn
+    ## Normalize vn.
     vn = vn ./ repmat (sqrt (sumsq (vn, 3)), [1, 1, 3]);
     [nr, nc] = size(get(tmp, "zdata"));
 
-    ## ambient, diffuse, and specular term
-    cdata = r(1) * ones (nr, nc) \
-          + r(2) * diffuse  (vn(:, :, 1), vn(:, :, 2), vn(:, :, 3), lv) \
-          + r(3) * specular (vn(:, :, 1), vn(:, :, 2), vn(:, :, 3), lv, vv, r(4));
+    ## Ambient, diffuse, and specular term.
+    cdata = (r(1) * ones (nr, nc)
+             + r(2) * diffuse  (vn(:,:,1), vn(:,:,2), vn(:,:,3), lv)
+             + r(3) * specular (vn(:,:,1), vn(:,:,2), vn(:,:,3), lv, vv, r(4)));
 
     set (tmp, "cdata", cdata ./ sum (r(1:3)));