Finding pattern

I'm writing a DRC script to interpret gds files. I need to find a set of polygons in a layer with the exact same shape, or polygons with multiple holes of the same shape. I know that they repeat every 100um and are aligned ortho, but the actual shape may vary between files I need to process. Is there a way to test polygons against themselves independent of location, or a way to test if is_filled, or something like that?

Comments

  • Hi @IanD,

    you can iterate over the polygons of a layer using "each". This will give you a DPolygon object (see https://www.klayout.de/doc-qt5/code/class_DPolygon.html#k_1) which you can analyze using the provided methods.

    Here is an example that classifies polygons:


    l1 = input(1, 0) poly_classes = {} l1.merged.each do |poly| # normalizes the polygon such that the bounding box lower-left # corner sits at 0,0 poly_norm = poly.moved(RBA::DPoint::new - poly.bbox.p1) # counts the polygon classes poly_classes[poly_norm] ||= 0 poly_classes[poly_norm] += 1 end # print classes and count poly_classes.each do |poly,count| puts poly.to_s + ": " + count.to_s end

    For this example

    this script gives 3 instances of "F" and one (the upper right one) which is a litte larger:

    (0,0;0,1.82;1.25,1.82;1.25,1.48;0.47,1.48;0.47,1.15;1.19,1.15;1.19,0.76;0.48,0.76;0.48,0): 3
    (0,0;0,2.04;1.25,2.04;1.25,1.7;0.47,1.7;0.47,1.37;1.19,1.37;1.19,0.98;0.48,0.98;0.48,0): 1
    

    Matthias

  • awesome, Thankyou Matthias

Sign In or Register to comment.