Skip to content

Commit

Permalink
geom2d: code cleanup in drawing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dlegland committed Sep 20, 2022
1 parent 6705cf9 commit df42d70
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 51 deletions.
25 changes: 17 additions & 8 deletions matGeom/geom2d/drawArrow.m
@@ -1,5 +1,5 @@
function varargout = drawArrow(varargin)
%DRAWARROW Draw an arrow on the current axis.
% Draw an arrow on the current axis.
%
% drawArrow(x1, y1, x2, y2)
% draws an arrow between the points (x1 y1) and (x2 y2).
Expand All @@ -14,7 +14,7 @@
% also specifies arrow type. TYPE can be one of the following :
% 0: draw only two strokes
% 1: fill a triangle
% .5: draw a half arrow (try it to see ...)
% 0.5: draw a half arrow (try it to see ...)
%
% Arguments can be single values or array of size N-by-1. In this case,
% the function draws multiple arrows.
Expand Down Expand Up @@ -45,6 +45,14 @@
% 2014-09-17 fix managment of handle values as suggested by Benoit Botton
% 2016-05-23 Improve codee and reduce calculations (by JuanPi Carbajal)

% extract handle of axis to draw on
if isAxisHandle(varargin{1})
ax = varargin{1};
varargin(1) = [];
else
ax = gca;
end

if isempty (varargin)
error ('should specify at least one argument');
end
Expand Down Expand Up @@ -90,14 +98,14 @@
end

hold on;
oldHold = ishold (gca);
oldHold = ishold(ax);
if ~oldHold
hold on;
end
axis equal;

% angle of the edge
theta = atan2 (y2-y1, x2-x1);
theta = atan2(y2-y1, x2-x1);

rl = r .* l;
rh = r .* h;
Expand All @@ -114,7 +122,7 @@
ya3 = y2 - rh .* sT;

% draw main edge
tmp = line ([x1.'; x2.'], [y1.'; y2.'], 'color', [0 0 1]);
tmp = line(ax, [x1.'; x2.'], [y1.'; y2.'], 'color', [0 0 1]);
handle.body = tmp;

% draw only 2 wings
Expand All @@ -131,9 +139,10 @@

% draw a full arrow
ind = find (h ~= 0);
if ~isempty (ind)
tmp = patch ([x2(ind) xa1(ind) xa3(ind) xa2(ind) x2(ind)].', ...
[y2(ind) ya1(ind) ya3(ind) ya2(ind) y2(ind)].', [0 0 1]);
if ~isempty(ind)
tmp = patch (ax, ...
[x2(ind) xa1(ind) xa3(ind) xa2(ind) x2(ind)].', ...
[y2(ind) ya1(ind) ya3(ind) ya2(ind) y2(ind)].', [0 0 1]);
handle.head = tmp;
end

Expand Down
13 changes: 8 additions & 5 deletions matGeom/geom2d/drawBezierCurve.m
@@ -1,5 +1,5 @@
function varargout = drawBezierCurve(points, varargin)
%DRAWBEZIERCURVE Draw a cubic bezier curve defined by 4 control points.
% Draw a cubic bezier curve defined by 4 control points.
%
% drawBezierCurve(POINTS)
% Draw the Bezier curve defined by the 4 control points stored in POINTS.
Expand All @@ -25,24 +25,27 @@
% See also
% drawPolyline, cubicBezierToPolyline
%

% ------
% Author: David Legland
% e-mail: david.legland@grignon.inra.fr
% e-mail: david.legland@inrae.fr
% Created: 2011-03-16, using Matlab 7.9.0.529 (R2009b)
% Copyright 2011 INRA - Cepia Software Platform.

% HISTORY
% 2011-10-11 add management of axes handle

% extract handle of axis to draw on
if isAxisHandle(points)
ax = points;
points = varargin{1};
if isAxisHandle(varargin{1})
ax = varargin{1};
varargin(1) = [];
else
ax = gca;
end

points = varargin{1};
varargin(1) = [];

% default number of discretization steps
N = 64;

Expand Down
5 changes: 3 additions & 2 deletions matGeom/geom2d/drawBox.m
@@ -1,5 +1,5 @@
function varargout = drawBox(box, varargin)
%DRAWBOX Draw a box defined by coordinate extents.
% Draw a box defined by coordinate extents.
%
% drawBox(BOX)
% Draws a box defined by its extent: BOX = [XMIN XMAX YMIN YMAX].
Expand All @@ -21,8 +21,9 @@
% axis([0 60 0 60]);
%
% See Also:
% drawOrientedBox, drawRect
% drawOrientedBox, drawRect
%

% ---------
% author : David Legland
% INRA - TPV URPOI - BIA IMASTE
Expand Down
5 changes: 3 additions & 2 deletions matGeom/geom2d/drawCenteredEdge.m
@@ -1,5 +1,5 @@
function varargout = drawCenteredEdge(varargin)
%DRAWCENTEREDEDGE Draw an edge centered on a point.
% Draw an edge centered on a point.
%
% Draws a centered edge, defined by a center, a length and an orientation
% (in degrees). This function can be used to draw principal axes of an
Expand Down Expand Up @@ -41,8 +41,9 @@
% drawCenteredEdge(edges, 'linewidth', 2, 'color', 'g');
%
% See also:
% edges2d, drawOrientedBox, drawEllipse, centeredEdgeToEdge, drawEdge
% edges2d, drawOrientedBox, drawEllipse, centeredEdgeToEdge, drawEdge
%

% ---------
% author : David Legland
% INRA - TPV URPOI - BIA IMASTE
Expand Down
2 changes: 1 addition & 1 deletion matGeom/geom2d/drawCircle.m
@@ -1,5 +1,5 @@
function varargout = drawCircle(varargin)
%DRAWCIRCLE Draw a circle on the current axis.
% Draw a circle on the current axis.
%
% drawCircle(X0, Y0, R);
% Draw the circle with center (X0,Y0) and the radius R. If X0, Y0 and R
Expand Down
5 changes: 3 additions & 2 deletions matGeom/geom2d/drawCircleArc.m
@@ -1,5 +1,5 @@
function varargout = drawCircleArc(varargin)
%DRAWCIRCLEARC Draw a circle arc on the current axis.
% Draw a circle arc on the current axis.
%
% drawCircleArc(ARC);
% Draws circle arc defined by ARC = [XC YC R START EXTENT], with (XC, YC)
Expand Down Expand Up @@ -29,8 +29,9 @@
% drawCircleArc(arc, 'LineWidth', 3, 'Color', 'r')
%
% See also:
% circles2d, drawCircle, drawEllipse, circleArcToPolyline
% circles2d, drawCircle, drawEllipse, circleArcToPolyline
%

% --------
% author: David Legland
% INRA - TPV URPOI - BIA IMASTE
Expand Down
2 changes: 1 addition & 1 deletion matGeom/geom2d/drawEdge.m
@@ -1,5 +1,5 @@
function varargout = drawEdge(varargin)
%DRAWEDGE Draw an edge given by 2 points.
% Draw an edge defined by its two extremities.
%
% drawEdge(x1, y1, x2, y2);
% draw an edge between the points (x1 y1) and (x2 y2).
Expand Down
5 changes: 3 additions & 2 deletions matGeom/geom2d/drawEllipseArc.m
@@ -1,5 +1,5 @@
function varargout = drawEllipseArc(varargin)
%DRAWELLIPSEARC Draw an ellipse arc on the current axis.
% Draw an ellipse arc on the current axis.
%
% drawEllipseArc(ARC)
% draw ellipse arc specified by ARC. ARC has the format:
Expand Down Expand Up @@ -43,8 +43,9 @@
% drawRay(ray2)
%
% See also:
% ellipses2d, drawEllipse, drawCircleArc
% ellipses2d, drawEllipse, drawEllipseAxes, drawCircleArc
%

% ---------
% author : David Legland
% INRA - TPV URPOI - BIA IMASTE
Expand Down
2 changes: 1 addition & 1 deletion matGeom/geom2d/drawLabels.m
Expand Up @@ -35,7 +35,7 @@
end

% extract handle of axis to draw on
if isscalar(varargin{1}) && ishandle(varargin{1})
if isAxisHandle(varargin{1})
ax = varargin{1};
varargin(1) = [];
else
Expand Down
18 changes: 11 additions & 7 deletions matGeom/geom2d/drawLine.m
@@ -1,5 +1,5 @@
function varargout = drawLine(lin, varargin)
%DRAWLINE Draw a straight line clipped by the current axis.
function varargout = drawLine(varargin)
% Draw a straight line clipped by the current axis.
%
% drawLine(LINE);
% Draws the line LINE on the current axis, by using current axis to clip
Expand All @@ -20,8 +20,9 @@
% drawLine([-30 140 10 20]);
%
% See also:
% lines2d, createLine, drawEdge
% lines2d, createLine, drawEdge, clipLine
%

% ---------
% author : David Legland
% INRA - TPV URPOI - BIA IMASTE
Expand All @@ -35,15 +36,18 @@
% 04/08/2010 rewrite using clipLine
% 2011-10-11 add management of axes handle

% extract handle of axis to draw in
if isAxisHandle(lin)
ax = lin;
lin = varargin{1};
% extract handle of axis to draw on
if isAxisHandle(varargin{1})
ax = varargin{1};
varargin(1) = [];
else
ax = gca;
end

% retrieve line
lin = varargin{1};
varargin(1) = [];

% default style for drawing lines
if length(varargin) ~= 1
varargin = [{'color', 'b'}, varargin];
Expand Down
7 changes: 4 additions & 3 deletions matGeom/geom2d/drawOrientedBox.m
@@ -1,5 +1,5 @@
function varargout = drawOrientedBox(box, varargin)
%DRAWORIENTEDBOX Draw centered oriented rectangle.
% Draw centered oriented rectangle.
%
% Syntax
% drawOrientedBox(BOX)
Expand Down Expand Up @@ -34,11 +34,12 @@
% axis equal;
%
% See also
% orientedBox, drawPolygon, drawRect, drawBox, drawCenteredEdge
% orientedBox, drawPolygon, drawRect, drawBox, drawCenteredEdge
%

% ------
% Author: David Legland
% e-mail: david.legland@grignon.inra.fr
% e-mail: david.legland@inrae.fr
% Created: 2011-05-09, using Matlab 7.9.0.529 (R2009b)
% Copyright 2011 INRA - Cepia Software Platform.

Expand Down
4 changes: 2 additions & 2 deletions matGeom/geom2d/drawParabola.m
@@ -1,5 +1,5 @@
function varargout = drawParabola(varargin)
%DRAWPARABOLA Draw a parabola on the current axis.
% Draw a parabola on the current axis.
%
% drawParabola(PARABOLA);
% Draws a vertical parabola, defined by its vertex and its parameter.
Expand Down Expand Up @@ -59,7 +59,7 @@

% Extract parabola
if nargin < 1
error('geom2d:drawParabola:IllegalArgument', ...
error('MatGeom:geom2d:drawParabola:IllegalArgument', ...
'Please specify parabola representation');
end

Expand Down
2 changes: 1 addition & 1 deletion matGeom/geom2d/drawPoint.m
@@ -1,5 +1,5 @@
function h = drawPoint(varargin)
%DRAWPOINT Draw the point on the axis.
% Draw the point on the axis.
%
% drawPoint(X, Y);
% Draws points defined by coordinates X and Y.
Expand Down
5 changes: 3 additions & 2 deletions matGeom/geom2d/drawRay.m
@@ -1,5 +1,5 @@
function varargout = drawRay(ray, varargin)
%DRAWRAY Draw a ray on the current axis.
% Draw a ray on the current axis.
%
% drawRay(RAY)
% With RAY having the syntax: [x0 y0 dx dy], draws the ray starting from
Expand All @@ -13,8 +13,9 @@
% Returns handle on line object
%
% See also:
% rays2d, drawLine
% rays2d, drawLine, clipRay
%

% ---------
%
% author : David Legland
Expand Down
4 changes: 2 additions & 2 deletions matGeom/geom2d/drawRect.m
@@ -1,5 +1,5 @@
function varargout = drawRect(rect, varargin)
%DRAWRECT Draw rectangle on the current axis.
% Draw rectangle on the current axis.
%
% drawRect(RECT)
% draws the rectangles defined by RECT = [X0 Y0 W H].
Expand All @@ -22,7 +22,7 @@
% Returns handle of the created graphic objects.
%
% See Also:
% drawOrientedBox, drawBox, rectToPolygon
% drawOrientedBox, drawBox, rectToPolygon
%

% ---------
Expand Down

0 comments on commit df42d70

Please sign in to comment.