sizing of DPolygon object and area calculation

Hi!
I am trying to run a DRC script that calculates areas of different polygons with and without sizing.
But I get behaviour I do not understand. Please find below a test case
1. I attached simple layout, with 2 boxes of 100um X 100um with layer 1/0 called testCase.gds.gz.
2. Created the following sctipt that:
a. Calculates the area
b. Calculates the area of each polygon sized up by 1um/side
c. Calculates the area of each polygon sized down by 1um/side

Here is the DRC script:

l=1.0.um #set sizing parameter for test
my_layer=input(1,0)
#Go through each of the 100X100 boxes
my_layer.each do |polygon|
  #calculate the area of each box after sizing by +l
  ep_plus = RBA::EdgeProcessor::new #Using Edgeprocessor per Klayout documentation reccommendation
  sized_plus_L = ep_plus.simple_merge_p2p([polygon.sized(l)], false, true)
  #calculate the area of each box after sizing by -l
  ep_minus = RBA::EdgeProcessor::new
  sized_minus_L = ep_minus.simple_merge_p2p([polygon.sized(-1.0*l)], false, true)
  puts("original area=#{polygon.area}. sized +l area= #{sized_plus_L[0].area}.sized -l area=\ #{sized_minus_L[0].area}")
  ep_plus._destroy
  ep_minus.destroy
end

When running it, I get the following result in the Ruby console window, showing that area of original polygons is fine (10000). But the sized polygons is not

original area=10000.0. sized +l area= 10404.sized -l area= 1
original area=10000.0. sized +l area= 10404.sized -l area= 1

I am using Klayout version 0.26.3
Can you please advise?
Thanks! Allon

Comments

  • PS: sizing up area seems OK. Issue is sizing down.

  • There are several bugs in that code.

    First of all, you can't use micrometer units in Polygon#sized and second you skipped the last argument to "simple_merge_p2p" which is 1 and it's important here. Please check the documentation.

    But basically the features you are using are outdated and provide the low-level API. A DRC script works on a more abstract level.

    If you really need to act on a per-polygon level, you should use the Region object which provides an easier interface to use, such as

    l = 1.0.um
    single_polygon = RBA::Region::new(polygon)
    area_sized_positive_in_um2 = single_polygon.sized(l / dbu).area * (dbu * dbu)
    area_sized_negative_in_um2 = single_polygon.sized(-l / dbu).area * (dbu * dbu)
    

    Matthias

  • Thanks Matthias. I modified a little bit as Region object uses long integers while Dpolyon is double
    This worked
    Thanks! Allon

    l=1.0.um #set sizing parameter for test
    my_layer=input(1,0)
    #Go through each of the 100X100 boxes.  
    
    my_layer.merge.each do |dpolygon|
      #calculate the area of each box after sizing by +l
      single_region = RBA::Region::new(dpolygon.to_itype(dbu)) #store the Dpolygon as Region. Region coordinates are long, so units are transformed
    
      single_region_sized_positive=single_region.sized(l/dbu)
      single_region_sized_positive_area=single_region_sized_positive.area*dbu**2
    
      single_region_sized_negative=single_region.sized(-l/dbu)
      single_region_sized_negative_area=single_region_sized_negative.area*dbu**2
    
      puts ("Area of region #{single_region.area*dbu**2}. Area of sized+ polygon = #{single_region_sized_positive.area*dbu**2}. Area of sized- polygon = #{single_region_sized_negative.area*dbu**2}")
    end
    
Sign In or Register to comment.