def get_sibling_screens( current: Geometry, screens: Iterable[Geometry]) -> Dict[Ordinal, List[Geometry]]: """Given a screen and the list of active screens, return the sibling ones. Each list is ordered from the nearest screen to the furthest one. """ horizontal_screens = [ g for g in screens if current.horizontally_overlap(g) ] vertical_screens = [g for g in screens if current.vertically_overlap(g)] return { Ordinal.SOUTH: sorted([g for g in vertical_screens if g.y > current.y], key=lambda g: g.y), Ordinal.NORTH: sorted([g for g in vertical_screens if g.y < current.y], key=lambda g: -1 * g.y), Ordinal.EAST: sorted([g for g in horizontal_screens if g.x > current.x], key=lambda g: g.x), Ordinal.WEST: sorted([g for g in horizontal_screens if g.x < current.x], key=lambda g: -1 * g.x) }
def test_horizontally_not_overlap(self): g1 = Geometry(0, 0, 1, 1) g2 = Geometry(10, 10, 1, 1) assert not g1.horizontally_overlap(g2) assert not g2.horizontally_overlap(g1)
def test_horizontally_overlap(self): g1 = Geometry(0, 0, 10, 10) g2 = Geometry(100, 0, 10, 10) assert g1.horizontally_overlap(g2) assert g2.horizontally_overlap(g1)