File size: 1,048 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
function [constraint, box, updated] = align_with_boundary(box, boundary, threshold, rType)
tempBox = box;
updated = false(size(box));
closedSeg = zeros(size(box));
distSeg = zeros(size(box));
for i = 1:length(box)
    [closedSeg(i,:), distSeg(i,:)] = find_close_seg(box(i,:), boundary); 
end


box(distSeg <= threshold) = closedSeg(distSeg <= threshold);
updated(distSeg <= threshold) = true;
idx = find(distSeg <= threshold);
constraint = [idx closedSeg(idx)];


% check if any room box blocks the door
entranceBox = get_entrance_space(boundary(1:2, 1:2), boundary(1,3), threshold);
entrancePoly = polyshape(entranceBox([1 1 3 3]), entranceBox([2 4 4 2]));
for i = 1:length(box)
    if rType(i) ~= 10 && rType(i) ~= 0
        roomPoly = polyshape(box(i, [1 1 3 3]), box(i, [2 4 4 2]));
        if overlaps(entrancePoly, roomPoly)
            box(i,:) = shrink_box(roomPoly, entrancePoly, boundary(1,3));
            updated(i, box(i,:)==tempBox(i,:)) = false;
            updated(i, box(i,:)~=tempBox(i,:)) = true;
        end
    end        
end