File size: 1,866 Bytes
06db6e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 box = shrink_box(roomPoly, entrancePoly, doorOrient)

[PG, shapeId, ~] = subtract(roomPoly, entrancePoly);
idx1 = find(shapeId==1);
d = idx1(2:end) - idx1(1:end-1);
i = find(d~=1);
if ~isempty(i)
    idx1 = idx1([i+1:end 1:i]);
end

idx2 = find(shapeId~=1);
d = idx2(2:end) - idx2(1:end-1);
i = find(d~=1);
if ~isempty(i)
    idx2 = idx2([i+1:end 1:i]);
end

remainPoint = length(idx1);
if remainPoint == 2
    box = [min(PG.Vertices) max(PG.Vertices)];
elseif remainPoint == 3
    assert(length(idx2) == 3);
    pointSet1 = PG.Vertices([idx1(1:2); idx2(2)], :);
    pointSet2 = PG.Vertices([idx1(2:3); idx2(2)], :);
    if mod(doorOrient, 2) == 0 % door grow vertically
        if pointSet1(1,1) ==  pointSet1(2,1)
            box = [min(pointSet1) max(pointSet1)];
        else
            box = [min(pointSet2) max(pointSet2)];
        end
    else
        if pointSet1(1,2) ==  pointSet1(2,2)
            box = [min(pointSet1) max(pointSet1)];
        else
            box = [min(pointSet2) max(pointSet2)];
        end
    end
elseif remainPoint == 4 
    % elseif remainPoint == 4 && length(idx2) == 4
%     pointSet = PG.Vertices([idx1(2:3); idx2(2:3)], :);
%     box = [min(pointSet) max(pointSet)];
% elseif remainPoint == 4 % door inside the box
    [x1, y1] = centroid(roomPoly);
    [x2, y2] = centroid(entrancePoly);
    box = [min(roomPoly.Vertices)  max(roomPoly.Vertices)];
    if mod(doorOrient, 2) == 0 % door grow vertically
        if x1 < x2
            box(3) = min(entrancePoly.Vertices(:,1));
        else
            box(1) = max(entrancePoly.Vertices(:,1));
        end
    else
        if y1 < y2
            box(4) = min(entrancePoly.Vertices(:,2));
        else
            box(2) = max(entrancePoly.Vertices(:,2));
        end
    end
else
    disp(['There are other cases with point number = ', num2str(length(shapeId))]);
end