RoboHome / code /robohome /src /tools /rplan_library /test_usable_walls.py
RoboParty Release
Unify robohome source, assets and scenes delivery
3f15e9f
Raw History Blame Contribute Delete
5.74 kB
import copy
import unittest
import usable_walls as uw
def room(rid='living', rtype='living_room', bounds=(0, 0, 4, 4)):
return dict(room_id=rid, room_type=rtype, bounds_m=list(bounds))
def opening(side, interval, kind='door', rid='living'):
orient, line = {'W': ('V', 0), 'E': ('V', 4), 'S': ('H', 0), 'N': ('H', 4)}[side]
return dict(room_ids=[rid], wall_orientation=orient, wall_line_m=line,
**{kind + '_interval_m': list(interval)})
class UsableWalls(unittest.TestCase):
def test_four_occupied_sides_fail(self):
plan = dict(rooms=[room()], doors=[opening(s, (0, 4)) for s in 'WESN'])
result = uw.check_usable_walls(plan)
self.assertFalse(result['passed'])
self.assertEqual(result['failures'], ['no_usable_wall:living'])
self.assertEqual(result['rooms']['living']['max_usable_wall_m'], 0)
def test_sofa_wall_can_have_a_window_but_tv_needs_another_side(self):
window = dict(room_id='living', wall_orientation='V', wall_line_m=0, window_interval_m=[0, 4])
plan = dict(rooms=[room()], windows=[window], doors=[opening(s, (0, 4)) for s in 'SN'])
before = copy.deepcopy(plan)
result = uw.check_usable_walls(plan)['rooms']['living']
self.assertTrue(result['passed'])
self.assertEqual(result['walls']['W']['longest_m'], 4)
self.assertEqual(result['walls']['W']['windowless_longest_m'], 0)
self.assertNotEqual(result['sofa_side'], result['tv_side'])
self.assertEqual(plan, before)
def test_one_long_side_cannot_hold_both_sofa_and_tv(self):
plan = dict(rooms=[room(bounds=(0, 0, 8, 4))],
doors=[opening('W', (0, 4)), opening('E', (0, 4)), opening('N', (0, 8))])
plan['doors'][1]['wall_line_m'] = 8
self.assertFalse(uw.check_usable_walls(plan)['passed'])
def test_margin_union_and_clipping_preserve_continuous_lengths(self):
plan = dict(rooms=[room()], doors=[opening('S', (0.5, 1.5)), opening('S', (1.4, 2.0))])
wall = uw.check_usable_walls(plan)['rooms']['living']['walls']['S']
self.assertEqual(wall['free_intervals_m'], [[0, 0.4], [2.1, 4]])
self.assertAlmostEqual(wall['longest_m'], 1.9)
def test_open_interval_wins_over_overlap_and_suppressed_adjacency_is_solid(self):
adj = dict(opening('S', (1, 2), 'open'), open_connection=True, overlap_interval_m=[0, 4])
solid = dict(opening('N', (0, 4), 'open'), open_connection=False,
balcony_opening_suppressed_v16_21p=True)
plan = dict(rooms=[room()], topology_adjacencies=[adj, solid])
walls = uw.check_usable_walls(plan)['rooms']['living']['walls']
self.assertAlmostEqual(walls['S']['longest_m'], 1.9)
self.assertEqual(walls['N']['longest_m'], 4)
def test_unselected_topology_contact_is_not_an_inferred_door(self):
plan = dict(rooms=[room(), room('guest', 'guest_bedroom', (4, 0, 8, 4))],
topology_adjacencies=[dict(room_ids=['living', 'guest'], open_connection=False,
wall_orientation='V', wall_line_m=4, overlap_interval_m=[0, 4])])
self.assertEqual(uw.check_usable_walls(plan)['rooms']['living']['walls']['E']['longest_m'], 4)
def test_conversion_approximation_uses_full_open_contacts_and_centered_door(self):
plan = dict(rooms=[room(), room('dining', 'dining_room', (0, 4, 4, 7)),
room('guest', 'guest_bedroom', (4, 0, 8, 4)),
room('balcony', 'balcony', (0, -2, 4, 0))])
walls = uw.check_usable_walls(plan, approximate=True)['rooms']['living']['walls']
self.assertEqual(walls['N']['longest_m'], 0)
self.assertEqual(walls['S']['longest_m'], 0)
self.assertAlmostEqual(walls['E']['longest_m'], 1.4)
def test_conversion_kitchen_contact_is_a_centered_door_estimate(self):
plan = dict(rooms=[room(), room('kitchen', 'kitchen', (4, 0, 8, 4))])
wall = uw.check_usable_walls(plan, approximate=True)['rooms']['living']['walls']['E']
self.assertEqual(wall['occupied'][0]['kind'], 'door')
self.assertEqual(wall['occupied'][0]['interval_m'], [1.4, 2.6])
def test_explicit_door_replaces_topology_door_without_double_subtraction(self):
adj = dict(opening('S', (1.5, 2.5)), open_connection=False)
plan = dict(rooms=[room()], topology_adjacencies=[adj], doors=[opening('S', (0.1, 1.1))])
wall = uw.check_usable_walls(plan)['rooms']['living']['walls']['S']
self.assertAlmostEqual(wall['longest_m'], 2.8)
self.assertEqual(len(wall['occupied']), 1)
def test_bedroom_threshold_and_dining_centered_table_exception(self):
plan = dict(rooms=[room('child', 'child_bedroom', (0, 0, 2, 2)),
room('dining', 'dining_room', (0, 4, 2.6, 6.6))],
doors=[dict(room_ids=['dining'], wall_orientation=o, wall_line_m=l, door_interval_m=i)
for o, l, i in [('H', 4, [0, 2.6]), ('H', 6.6, [0, 2.6]),
('V', 0, [4, 6.6]), ('V', 2.6, [4, 6.6])]])
result = uw.check_usable_walls(plan)
self.assertTrue(result['rooms']['child']['passed'])
self.assertTrue(result['rooms']['dining']['passed'])
self.assertEqual(result['rooms']['dining']['max_usable_wall_m'], 0)
plan['rooms'][0]['bounds_m'] = [0, 0, 1.99, 1.99]
self.assertIn('no_usable_wall:child', uw.check_usable_walls(plan)['failures'])
plan['rooms'][1]['bounds_m'] = [0, 4, 2.59, 6.59]
self.assertIn('no_usable_wall:dining', uw.check_usable_walls(plan)['failures'])
if __name__ == '__main__':
unittest.main()