[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: __plt__.m redundancies
From: |
Rik |
Subject: |
Re: __plt__.m redundancies |
Date: |
Thu, 27 Jun 2013 11:50:26 -0700 |
On 06/27/2013 10:31 AM, Daniel J Sebald wrote:
> On 06/27/2013 11:44 AM, Rik wrote:
>> 6/27/13
>>
>> All,
>>
>> I happened to be looking in scripts/plot/private/__plt__.m and found that
>> there is a dispatch table in the subfunction __plt2__ which checks whether
>> the x input is a scalar, vector, or matrix and whether the y input is a
>> scalar, vector, or matrix and then calls the appropriate subfunction such
>> as __plt2sv__ for scalar/vector plotting.
>>
>> I checked in each of the 6 subfunctions and they check the number of input
>> arguments with nargin as well as re-checking that each of the inputs is a
>> scalar, vector, or matrix. This is redundant and probably arose as the
>> code evolved in time. Does anyone know why the input checks in the leaf
>> functions cannot be deleted in favor of the earlier checks?
>>
>> --Rik
>
> I'm not seeing this redundancy. What line numbers or code hunks?
The dispatch table is in the __plt2__ subfunction at line 231. Here it is
just to give the flavor:
if (isempty (x1) && isempty (x2))
retval = zeros (0, 1);
elseif (isscalar (x1))
if (isscalar (x2))
retval = __plt2ss__ (h, x1, x2, options, properties);
elseif (isvector (x2))
retval = __plt2sv__ (h, x1, x2, options, properties);
else
error ("__plt2__: invalid data for plotting");
endif
elseif (isvector (x1))
if (isscalar (x2))
retval = __plt2vs__ (h, x1, x2, options, properties);
elseif (isvector (x2))
retval = __plt2vv__ (h, x1, x2, options, properties);
elseif (ismatrix (x2))
retval = __plt2vm__ (h, x1, x2, options, properties);
else
error ("__plt2__: invalid data for plotting");
endif
elseif (ismatrix (x1))
if (isvector (x2))
retval = __plt2mv__ (h, x1, x2, options, properties);
elseif (ismatrix (x2))
retval = __plt2mm__ (h, x1, x2, options, properties);
else
error ("__plt2__: invalid data for plotting");
endif
else
error ("__plt2__: invalid data for plotting");
endif
Each of the subfunctions is __plt2[svm][svm]__ where s is scalar, v is
vector, and m is matrix. As an example, here is the start of __plt2ss__
which is for plotting scalar/scalar such as plot (1,1).
function retval = __plt2ss__ (h, x, y, options, properties)
if (nargin < 3 || nargin > 5)
print_usage ();
endif
if (nargin < 4 || isempty (options))
options = __default_plot_options__ ();
endif
if (nargin < 5)
properties = {};
endif
if (numel (options) > 1)
options = options(1);
endif
if (isscalar (x) && isscalar (y))
linestyle = options.linestyle;
marker = options.marker;
if (isempty (marker) && isempty (linestyle))
## If unspecified, marker for a single point is always "."
linestyle = "-";
marker = ".";
endif
color = options.color;
if (isempty (color))
color = __next_line_color__ ();
endif
retval = line (x, y, "color", color,
"linestyle", linestyle,
"marker", marker, properties{:});
else
error ("__plt2ss__: arguments must be scalars");
endif
As you can see, there is quite a bit of option validating and this seems
unnecessary.
--Rik