## Copyright (C) 2017 Nicholas Jankowski
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see .
## -*- texinfo -*-
## @deftypefn {} {@var{thetatick_values} =} thetaticks
## @deftypefnx {} thetaticks (@var{'thetatick_values'})
## @deftypefnx {} thetaticks (@var{hax}, @dots{})
## Query or set the properties related to tick values on the r-axis of the
## current axis.
##
## When @code{thetaticks} is called without argument, @code{thetaticks} returns the
## current locations as specified in the @var{ttick} axis property. These values
## can be changed by calling @code{thetaticks} with a vector of tick values. Note:
## ascending order is not required.
##
## If the first argument @var{hax} is an axes handle, then operate on
## this axis rather than the current axes returned by @code{gca}.
##
## Requesting a return value when calling @code{thetaticks} to set a property value
## will result in an error.
##
## NOTE: Octave does not currently have polaraxes obects implented. It is
## not currently possible to query or set a 'mode' for the @var{ttick} property
## as can be done with equivalent functions for @var{x}, @var{y} and @var{z}
## axes.
##
## @seealso{thetaticks, xticks, yticks, zticks, polar, get, set}
## @end deftypefn
## Author: Nicholas Jankowski
## Created: 2017-08-24
function [retval] = thetaticks (varargin)
#identify and set input values, shortcut simple cases
## FIXME: update function to work with polaraxes objects once that function
## is implement in octave. for compatibilty with matlab this may need
## to function with both the property names ttick and thetatick
switch nargin
case 0
retval = get (gca , 'ttick'); #will error if no rtick exists.
return;
case 1
axis_to_use = gca;
option = varargin{1};
case 2
#if 2 inputs, first must specify an axis handle.
if (~ishandle (varargin{1}) || ishandle (varargin{2}))
print_usage;
else
axis_to_use = varargin{1};
option = varargin{2};
endif
otherwise
print_usage;
endswitch
# axis and option are set, perform requested actions based on 'option' class
if ishandle(option)
retval = get (option, 'ttick');
elseif ischar(option)
error('mode is currently not implemented for the ttick property')
## FIXME: enable mode options if/when they are enabled in polar or polarplot
## option = tolower(option);
## switch option
## case 'mode'
## retval = get (axis_to_use, 'ttickmode');
##
## case {'auto','manual'}
## if (nargout > 0)
## error(['too many output arguments requested for option "', option, '"'])
## else
## set(axis_to_use, 'ttickmode', option);
## endif
## otherwise
## error(['invalid option "', option, '"'])
## endswitch
elseif (isnumeric(option))
if (nargout > 0)
error('too many output arguments requested')
else
## NOTE: Matlab errors if tick points are not in ascending order. Octave
## permits out of order tick points, so error is not produced.
set(axis_to_use, 'ttick', option);
endif
else
print_usage;
endif
endfunction
## Test input validation
%!test
%! hf = figure ("visible", "off");
%! unwind_protect
%! polar (linspace (0, pi, 20), rand(20,1));
%! hax = gca;
%! vals1 = thetaticks;
%! assert (thetaticks (hax), vals1);
%! thetaticks (hax, [0 45 90 135 180]);
%! assert (thetaticks (hax), [0 45 90 135 180]);
%! unwind_protect_cleanup
%! close (hf);
%! end_unwind_protect