I’m starting with using of ruby language, I need help for a script which should looking for all polygons which can be in different hierarchical levels in my gds layout database, as condition the polygon must be closest to a point that I know.
For example I know that in a cell A I have a point x=200,y=200
I have to find all polygons with layer map 20 and datatype 0 which are containing the point, the problem is that the polygon can be in different hierarchical level than the point with X and Y coordinates.
I don’t know if my explanation was very clear, anyway I ask if someone kindly can help me.
Comments
Hi gabry123,
A simple solution is the RecursiveShapeIterator object:
The RecursiveShapeIterator (here in "si") will deliver all shapes whose bounding box overlaps the given search box (here a single-point box). Having these objects we can perform a more detailed check using the inside test for the polygon transformed into the top cell's coordinate space.
Matthias
First of all thanks a lot for your help and support is really appreciated. I tried your code in a real case:
cell = "DSA_core_FIN" # cell name of the top where I'm starting
layer = 1 # index of the layer for which I have to find the polygon coordinates
pt1 = 9742 # the point (in database units) at which you are looking
pt2 = 191932
si = cell.begin_shapes_rec_overlapping(RBA::Box::new(pt1, pt2), layer)
while !si.at_end?
if si.shape.renders_polygon?
poly = si.shape.polygon.transformed(si.trans)
if poly.inside(pt)
puts poly
# ... point is inside the polygon
end
end
si.next
end
I got this error:
ERROR: RuntimeError: Unexpected object type (expected argument of class Point, got Fixnum) in Box::new
../../script_gotten.rb:22:in `initialize'
../../script_gotten.rb:22:in `new'
../../script_gotten.rb:22:
this is the command line that I used to run the script:
klayout -rx -r script_gotten.rb -z -rd input=DSA_core_FIN.gds
Maybe I made some mistake?
cell = "DSA_core_FIN" # cell name of the top where I'm starting
layer = 1 # index of the layer for which I have to find the polygon coordinates
pt = 9742;191932 # the point (in database units) at which I'm looking
si = cell.begin_shapes_rec_overlapping(RBA::Box::new(pt, pt), layer)
while !si.at_end?
if si.shape.renders_polygon?
poly = si.shape.polygon.transformed(si.trans)
if poly.inside(pt)
puts poly
# ... point is inside the polygon
end
end
si.next
end
I got this error:
ERROR: RuntimeError: Unexpected object type (expected argument of class Point, got Fixnum) in Box::new
../../script_gotten.rb:22:in `initialize'
../../script_gotten.rb:22:in `new'
../../script_gotten.rb:22:
this is the command line that I used to run the script:
klayout -rx -r script_gotten.rb -z -rd input=DSA_core_FIN.gds
Maybe I made some mistake?
Hi gabry123,
to initialize the point "pt" you'll have to use
Matthias
Gabriele