-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scadSquare.m
52 lines (52 loc) · 1.42 KB
/
scadSquare.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function object = scadSquare(size1, varargin)
%scadSquare - Creates a square or rectangle in the first quadrant. When
%center is true the square is centered on the origin. Argument names are
%optional if given in the order shown here.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% parameters:
%
% size - single value, square with both sides this length
% 2 value array [x,y], rectangle with dimensions x and y
%
% center - false (default), 1st (positive) quadrant, one corner at (0,0)
% true, square is centered at (0,0)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
center = true;
position = [];
color = [];
%
while ~isempty(varargin)
switch lower(varargin{1})
case 'center'
center = varargin{2};
case 'position'
position = varargin{2};
case 'color'
color = varargin{2};
otherwise
error(['scadSquare: unknown paramiter - ' varargin{1}])
end
varargin(1:2) = [];
end
%
if max(size(size1)) == 1
size1 = num2str(size1);
else
size1 = ['[' char(strjoin(compose('%d', size1), ',')) ']'];
end
%
parallelogram = ['square(size = ' size1 ','...
' center =' boolean2string(center) ');' ];
object = scadStructure();
%
object.structure = parallelogram;
%
if ~isempty(color)
object = scadColor(color, object);
end
if ~isempty(position)
object = scadTranslate(position, object);
end
end