File size: 3,352 Bytes
870b85a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
import unittest

import screen_library as sl


def plan_of(*boxes):
    return dict(rooms=[dict(room_id='r%d' % i, room_type='x', bounds_m=list(b)) for i, b in enumerate(boxes)])


class PinchedFloor(unittest.TestCase):
    def test_two_rooms_that_meet_at_a_corner_pinch_the_floor(self):
        self.assertTrue(sl.pinched_floor(plan_of((0, 0, 4, 4), (4, 4, 8, 8))))
        self.assertTrue(sl.pinched_floor(plan_of((0, 4, 4, 8), (4, 0, 8, 4))))

    def test_a_third_room_in_the_missing_quadrant_closes_it(self):
        self.assertFalse(sl.pinched_floor(plan_of((0, 0, 4, 4), (4, 4, 8, 8), (4, 0, 8, 4))))

    def test_rooms_that_share_a_wall_and_an_l_shaped_outline_are_fine(self):
        self.assertFalse(sl.pinched_floor(plan_of((0, 0, 4, 4), (4, 0, 8, 4))))
        self.assertFalse(sl.pinched_floor(plan_of((0, 0, 8, 4), (0, 4, 4, 8))))              # the reflex corner has three quadrants filled

    def test_a_void_in_the_middle_that_touches_nothing_else_is_not_a_pinch(self):
        ring = plan_of((0, 0, 9, 3), (0, 3, 3, 6), (6, 3, 9, 6), (0, 6, 9, 9))
        self.assertFalse(sl.pinched_floor(ring))

    def test_a_void_whose_outline_meets_the_outside_at_a_single_point_is_a_pinch(self):
        closed = plan_of((0, 0, 6, 3), (0, 3, 3, 6), (6, 3, 9, 6), (3, 6, 9, 9), (0, 6, 3, 9), (6, 0, 9, 3))
        self.assertFalse(sl.pinched_floor(closed))    # a ring of six rooms around the 3 x 3 void in the middle
        open_corner = plan_of((0, 0, 6, 3), (0, 3, 3, 6), (6, 3, 9, 6), (0, 6, 3, 9), (3, 6, 6, 9))
        self.assertTrue(sl.pinched_floor(open_corner))   # the room at 6,0-9,3 is gone: at (6,3) two rooms touch on a diagonal


class MinimumSides(unittest.TestCase):
    LIMITS = {'living': 2.8, 'bedroom': 2.5, 'kitchen': 1.8, 'hallway': 1.0, 'default': 1.8}

    def test_a_room_uses_its_own_entry_then_its_group_then_the_default(self):
        self.assertEqual(sl.min_side_for(self.LIMITS, 'living'), 2.8)
        for bedroom in ('master', 'guest', 'bedroom_3', 'bedroom_4'):
            self.assertEqual(sl.min_side_for(self.LIMITS, bedroom), 2.5)
        self.assertEqual(sl.min_side_for(self.LIMITS, 'hallway_2'), 1.0)
        self.assertEqual(sl.min_side_for(self.LIMITS, 'bath'), 1.8)

    def test_a_wall_move_may_not_leave_a_room_narrower_than_its_limit(self):
        plan = plan_of((0, 0, 3, 4))
        plan['rooms'][0]['room_id'] = 'master'
        self.assertTrue(sl.valid_bounds(plan, 'master', [0, 0, 2.6, 4], self.LIMITS))
        self.assertFalse(sl.valid_bounds(plan, 'master', [0, 0, 2.4, 4], self.LIMITS))


class WallStub(unittest.TestCase):
    def test_wall_left_beside_an_ordinary_portal(self):
        self.assertAlmostEqual(sl.wall_stub({'overlap_interval_m': [0.0, 2.0], 'door_interval_m': [0.4, 1.4]}), 0.4)
        self.assertAlmostEqual(sl.wall_stub({'overlap_interval_m': [0.0, 1.0], 'open_interval_m': [0.0, 1.0]}), 0.0)
        self.assertAlmostEqual(sl.wall_stub({'overlap_interval_m': [1.0, 3.0], 'door_interval_m': [1.7, 2.7]}), 0.3)

    def test_adjacencies_without_a_portal_and_balcony_openings_have_no_stub(self):
        self.assertIsNone(sl.wall_stub({'overlap_interval_m': [0.0, 2.0]}))
        self.assertIsNone(sl.wall_stub({'overlap_interval_m': [0.0, 3.0], 'open_interval_m': [0.45, 2.55], 'balcony_side_clearance_m': 0.45}))


if __name__ == '__main__':
    unittest.main()