function inout = classify(x, y, tol)
%CLASSIFY In, on, or outside of a circle.
%   INOUT = CLASSIFY(X, Y, TOL) classifies a scalar point (X, Y)
%   as being inside, on, or outside of the unit circle.
%   INOUT is -1 if the point is inside the circle,
%   0 if the point is on the circle, and 1 if the point is outside
%   the circle.
%
%   A point is considered on the circle if (X^2 + Y^2) is inside the
%   range (1 + TOL) to (1 - TOL).


s = x .^ 2 + y .^ 2;

% it is easiest to check the 'on' case first
if abs(s - 1) < tol
    inout = 0;
elseif s < 1
    inout = -1;
else
    inout = 1;
end
