How to finding if a point lies inside a specified layer.

Hello, I am looking for a function that returns true if a given point is inside a function.

The following function returns true if a point lies inside a polygon (specified by layer and a cell).
However I don't want to use this method because I don't want to iterate over all the shapes.
Is there a simpler way of finding if a point is inside or outside (touching or not touching) a specified layer.

iter = pya.RecursiveShapeIterator.new(layout, cell, layer_index)
specified_region = iter.shape().polygon
is_point_inside = specified_region.inside(pya.Point(x, y))

Thanks for the help!

Comments

  • edited October 22

    Perhaps you could use Layout.begin_shapes_touching. You would need to make a Region out of your point.

  • edited October 23

    @jheinsoo You're right. Confining the search does the trick.

    But you do not necessarily need a Region. Iterating probably won't hurt if you confine the search to a small area around the test point. This will return only those polygons whose bounding boxes already contain the point:

    test_box = pya.Box(x - 1, y - 1, x + 1 y + 1)
    iter = pya.RecursiveShapeIterator.new(layout, cell, layer_index, test_box, True)
    ...
    

    I think this is the most efficient way to do the test.

    Matthias

Sign In or Register to comment.