Merge pull request #1390 from andrewb1999/overlay

Add overlay.py to allow for overlay architecture generation
This commit is contained in:
litghost 2020-07-15 14:03:43 -07:00 committed by GitHub
commit 2d12859e82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

29
prjxray/overlay.py Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2020 The Project X-Ray Authors.
#
# Use of this source code is governed by a ISC-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/ISC
#
# SPDX-License-Identifier: ISC
class Overlay(object):
""" Object that represents an overlay.
Can be used to iterate over tiles and sites not inside a partition region.
"""
def __init__(self, region_dict):
self.region_dict = region_dict
def tile_in_roi(self, grid_loc):
""" Returns true if grid_loc (GridLoc tuple) is within the overlay. """
x = grid_loc.grid_x
y = grid_loc.grid_y
for _, bounds in self.region_dict.items():
x1, x2, y1, y2 = bounds
if x1 <= x and x <= x2 and y1 <= y and y <= y2:
return False
return True

View File

@ -21,7 +21,9 @@ from unittest import TestCase, main
environ['XRAY_DATABASE_ROOT'] = '.'
environ['XRAY_PART'] = './'
from prjxray.util import get_roi
from prjxray.util import get_roi, get_db_root
from prjxray.overlay import Overlay
from prjxray.grid_types import GridLoc
@contextmanager
@ -69,6 +71,17 @@ class TestUtil(TestCase):
self.assertListEqual(
list(get_roi().gen_sites()), [('ATILE', 'FOO', 'BAR')])
def test_in_roi_overlay(self):
region_dict = {}
region_dict['pr1'] = (10, 58, 0, 51)
region_dict['pr2'] = (10, 58, 52, 103)
overlay = Overlay(region_dict)
self.assertFalse(overlay.tile_in_roi(GridLoc(18, 50)))
self.assertFalse(overlay.tile_in_roi(GridLoc(18, 84)))
self.assertTrue(overlay.tile_in_roi(GridLoc(8, 50)))
self.assertTrue(overlay.tile_in_roi(GridLoc(18, 112)))
self.assertTrue(overlay.tile_in_roi(GridLoc(80, 40)))
if __name__ == '__main__':
main()