-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetBlockSidePositions.m
More file actions
61 lines (58 loc) · 2.09 KB
/
getBlockSidePositions.m
File metadata and controls
61 lines (58 loc) · 2.09 KB
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
53
54
55
56
57
58
59
60
61
function sidePositions = getBlockSidePositions(blocks, side)
% GETBLOCKSIDEPOSITIONS Find the *unique* block positions for a given side
% of a set of blocks.
%
% Inputs:
% blocks Cell array of the full names of block(s). If a cell
% array is given for one of the block names, the first
% element is used.
%
% side Number respesenting the following:
% 1 - Left
% 2 - Top
% 3 - Right
% 4 - Bottom
% 5 - Midpoint between results of 1 and 3
% 6 - Midpoint between results of 2 and 4
%
% Outputs:
% sidePositions Vector of unique doubles for the positions.
%
% Calculated the selected side position based on the side selected
if side == 5
sidePositions = [];
for i = 1:length(blocks)
if iscell(blocks{i})
blocks{i} = char(blocks{i});
end
pos = get_param(blocks{i}, 'Position');
midX = (pos(1) + pos(3)) / 2;
if ~ismember(midX, sidePositions)
sidePositions = [sidePositions, midX];
end
end
elseif side == 6
sidePositions = [];
for i = 1:length(blocks)
if iscell(blocks{i})
blocks{i} = char(blocks{i});
end
pos = get_param(blocks{i}, 'Position');
midY = (pos(2) + pos(4)) / 2;
if ~ismember(midY, sidePositions)
sidePositions = [sidePositions, midY];
end
end
else
sidePositions = [];
for i = 1:length(blocks)
if iscell(blocks{i})
blocks{i} = char(blocks{i});
end
pos = get_param(blocks{i}, 'Position');
if ~ismember(pos(side), sidePositions)
sidePositions = [sidePositions , pos(side)];
end
end
end
end