Skip to content

Commit

Permalink
geom2d/drawCircle.m fix drawing multiple circles
Browse files Browse the repository at this point in the history
  • Loading branch information
dlegland committed Sep 5, 2023
1 parent bfdde08 commit ffe80f5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
31 changes: 26 additions & 5 deletions matGeom/geom2d/drawCircle.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
% Created: 2003-10-31
% Copyright 2003-2023 INRA - TPV URPOI - BIA IMASTE


%% Parse input arguments

% extract handle of axis to draw on
if isAxisHandle(varargin{1})
ax = varargin{1};
Expand Down Expand Up @@ -75,11 +78,6 @@
error('bad format for input in drawCircle');
end

% ensure each parameter is column vector
x0 = x0(:);
y0 = y0(:);
r = r(:);

% default number of discretization steps
N = 72;

Expand All @@ -92,6 +90,14 @@
end
end


%% Pre-processing

% ensure each parameter is column vector
x0 = x0(:);
y0 = y0(:);
r = r(:);

% parametrization variable for circle (use N+1 as first point counts twice)
t = linspace(0, 2*pi, N+1);
cot = cos(t);
Expand All @@ -100,6 +106,13 @@
% empty array for graphic handles
h = zeros(size(x0));

% save hold state
holdState = ishold(ax);
hold(ax, 'on');


%% Display each circle

% compute discretization of each circle
for i = 1:length(x0)
xt = x0(i) + r(i) * cot;
Expand All @@ -108,6 +121,14 @@
h(i) = plot(ax, xt, yt, varargin{:});
end


%% post-processing

% restore hold state
if ~holdState
hold(ax, 'off');
end

if nargout > 0
varargout = {h};
end
46 changes: 46 additions & 0 deletions tests/geom2d/test_drawCircle.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function tests = test_drawCircle
% Test suite for the file drawCircle.
%
% Test suite for the file drawCircle
%
% Example
% test_drawCircle
%
% See also
% drawCircle

% ------
% Author: David Legland
% e-mail: david.legland@inrae.fr
% Created: 2023-09-05, using Matlab 9.14.0.2206163 (R2023a)
% Copyright 2023 INRAE - BIA-BIBS.

tests = functiontests(localfunctions);

function test_Simple(testCase) %#ok<*DEFNU>
% Test call of function without argument.

circ = [40 30 10];

hf = 101;
figure(hf); clf;
hc = drawCircle(circ);

assertTrue(testCase, ishghandle(hc));

close(hf);


function test_DrawMany(testCase) %#ok<*DEFNU>
% Test call of function without argument.

circ = [40 30 10; 50 40 20];

hf = 101;
figure(hf); clf;
hc = drawCircle(circ);

assertTrue(testCase, all(ishghandle(hc)));
assertEqual(testCase, length(hc), 2);

close(hf);

0 comments on commit ffe80f5

Please sign in to comment.