It looks like you're new here. If you want to get involved, click one of these buttons!
I'd like to filter the output of Cell.each_touching_shape(layer_index, box)
or Cell.each_overlapping_shape(layer_index, box)
so that I only get the shapes that actually interact with the box, not just if their bounding boxes touch/overlap.
What's the cleanest way to do this, non-recursively?
Comments
After playing around with the different APIs, I think I'm reasonably happy with the following approach:
Cell.shapes
to get my selection candidates.Polygon.touches?
method which appears to be geometrically equivalent to theRegion.interacting
method but actually returns a boolean. Luckily, shape can be converted to a polygon.Polygon.touches?
doesn't support points, I'll have to make anEdge
from aPoint
selection.Polygon.touches?
, I'm usingShapes.each_touching
to filter out shapes that aren't in the vicinity. Note that even though it's called touching, it actually only tests the bounding boxes of the shapes, not the actual geometry (i.e. interaction), so I'll have to use point 2 above with the resulting set.Here's my complete test code:
To further optimise the results of the
shapes.each_touching
call, it probably makes sense to limit the types toSBoxes
,SPaths
andSPolygons
since only those can be converted to polygons.Hi,
sorry for the delayed reply.
Your solution isn't bad although I'd say the Ruby loop is probably going to be a bit slow.
The solution I'd suggest is to use Region objects. Regions are the basic building blocks of DRC scripts and they provide an "interacting" selector. Regions can be made from shape iterators and boxes, so you have everything you need:
Regards,
Matthias
Hi Matthias, thanks for the Region code.
I had looked into
Region
s, but I couldn't think of a way to get the original shapes back from the resulting Region of "selected" objects.To explain, I want to manipulate/delete (via Ruby code) the
Shape
s after "selecting" them from a givenCell
. But since I read Regions merge all geometric shapes of the same layer, I'm not sure this is possible.Hi,
you can try using "region_a.merged_semantics = false". This should leave the shapes unmerged.
But regions are collections of polygons and everything will be polygonized. If you want to the other shape types such as paths your code is better.
Kind regards,
Matthias