Finding shapes that overlap with a Box.

Hi!
I want to find shapes that overlap with a search region box. There is the method 'db.Shapes.each_overlapping' which from the description sounds like exactly what I need. However, this method somehow checks not the shapes for overlapping but the bounding boxes of the shapes.

Here is an example where the path and the search box do not geometrically even touch each other, but the bounding boxes do:

s = db.Shapes() 
path = db.Path([db.Point(0, 0), db.Point(0, 10), db.Point(10, 10)], 2)
s.insert(path) 
search_box = db.Box(db.Point(4, 4), db.Point(5, 5))
overlap = list(s.each_overlapping(search_box))
assert len(overlap) == 0

What is the proper way to find overlapping shapes of a box? For me it is also important to preserve the properties of the shapes, so I cannot convert the Shapes object into a Region.

Thanks in advance!

Comments

  • Hi Thomas,

    "each_overlapping" can act as a preselector. It's not precise in a sense that it really checks the overlaps.

    For a precise check, it's first necessary to convert the shapes into polygons ("Shape#polygon"). You should skip text objects if your layout contains them. After this, you can use "Polygon#touches" to check whether it touches the box. For "overlap", use a box which is smaller by one DBU.

    Sometimes it may be more convenient to work with a "Region" object which represents the flat (or as if flat) content of a layer of a cell and their subcells. Region has an "interacting" method which delivers all polygons of the region (merged or unmerged, depending on the sematics chosen) which interact (touch) polygons of a second region. Using the box for the second region will deliver these. Specifically when you look up polygons from many small regions, picking them separately with "each_overlapping" may be faster.

    Finally, you can also pull shapes from a hierarchy using "Cell#begin_shapes_rec_touching" or "Cell#begin_shapes_rec_overlapping". This is similar to "each_overlapping", but delivers shapes from child cells too.

    Hope this is comprehensible :)

    Best regards,

    Matthias

  • Thanks Matthias! Makes sense :)

Sign In or Register to comment.