-
Notifications
You must be signed in to change notification settings - Fork 0
/
distance.m
57 lines (51 loc) · 1.33 KB
/
distance.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
53
54
55
56
57
function [r] = distance(walls, i, si, j, sj, d, handle_thickness=1)
X = 0;
Y = 1;
L = 2;
T = 3;
Horiz = 1;
Verti = 2;
N = 1;
E = 2;
S = 3;
W = 4;
r = zeros(1, size(walls, 2) * 4 + 1);
r(1, end) = d;
for k = [i j]
if k == i
w = -1;
s = si;
else
w = 1;
s = sj;
end
orientation = walls(k);
c = (k - 1) * 4 + 1;
switch [s, orientation]
case [N, Verti]
r(1, c + Y) = w;
case [S, Verti]
r(1, c + Y) = w;
r(1, c + L) = w;
case [E, Verti]
r(1, c + X) = w;
r(1, c + T) = w/2 * handle_thickness;
case [W, Verti]
r(1, c + X) = w;
r(1, c + T) = -w/2 * handle_thickness;
case [N, Horiz]
r(1, c + Y) = w;
r(1, c + T) = -w/2 * handle_thickness;
case [S, Horiz]
r(1, c + Y) = w;
r(1, c + T) = w/2 * handle_thickness;
case [E, Horiz]
r(1, c + X) = w;
r(1, c + L) = w;
case [W, Horiz]
r(1, c + X) = w;
otherwise
error('Inconsistent orientations')
end
end
end