Zero-Area Polygon Check

How would I go about checking for zero area polygons and paths. I tried iterating through all the layers of each cell then through all the shapes, and checking the area of each shape, but that didn't work for some reason. Are there any other methods?

Comments

  • Hi @aarush,

    Maybe pasting some code is helpful to see what you did.

    In DRC, you cannot directly iterate, as the normal iteration through "each" will give you merged polygons and this means, zero-area polygons vanish.

    However, you can switch to "raw" mode which gives you the original polygons:

    l1 = input(1, 0)
    l1.raw.each do |polygon|
      if polygon.area == 0
        # zero-area polygon
      end
    end
    

    Matthias

  • Hi @Matthias,

    This is my current main logic block:

       issues = []
    
        for cell in layout.each_cell():
            for idx in layout.layer_indexes():
                itr = layout.begin_shapes(cell, idx)
                while not itr.at_end():
                    shp = itr.shape()
                    if shp.is_polygon():
                        pg = shp.polygon.transformed(itr.trans())
                        if pg.area() == 0:
                            info = layout.get_info(idx)
                            issues.append(
                                f"In '{cell.name}' (L={info.layer}, DT={info.datatype})"
                            )
                    itr.next()
    

    Could I just use the code you sent above to iterate through all the layers and get the zero order polygons?

  • Hi @aarush,

    your code is Python acting directly on the shapes, not DRC.

    You should not use a recursive shape iterator from every cell, as it will dive down in the hierarchy. Instead just iterate the shapes of the individual cell:

                for shp in cell.shapes(idx).each():
                    if shp.is_polygon():
                        pg = shp.polygon
                        if pg.area() == 0:
                            info = layout.get_info(idx)
                            issues.append(
                                f"In '{cell.name}' (L={info.layer}, DT={info.datatype})"
                            )
    

    Matthias

  • Hi Matthias,

    Unfortunately, this still doesn't replicate the behavior from the app. This is my main run function:

    def run(file_path, **_):
        t0 = time.perf_counter()
    
        layout = pya.Layout()
        try:
            layout.read(os.path.normpath(file_path))
        except Exception as e:
            return f"[ERROR] Could not read GDS file: {e}\n", False
    
        issues = []
    
        for cell in layout.each_cell():
            for idx in layout.layer_indexes():
                for shp in cell.shapes(idx).each():
                    if shp.is_polygon():
                        pg = shp.polygon
                        if pg.area() == 0:
                            info = layout.get_info(idx)
                            issues.append(
                                f"In '{cell.name}' (L={info.layer}, DT={info.datatype})"
                            )
    
    
        elapsed = time.perf_counter() - t0
        header  = f"[INFO] Check finished in {elapsed:.3f} s\n"
    
        if issues:
            report = header + "[FAIL] Zero-area polygons found:\n"
            report += "\n".join(f"  - {m}" for m in issues) + "\n"
            return report, False
        else:
            return header + "[PASS] No zero-area polygons detected.\n", True
    

    What is going wrong?

    Best,
    Aarush

  • edited July 1

    Hi @aarush,

    In which way are the results different? Do you get an error?

    Maybe it's best to attach a test case. You cannot attach GDS directly, but you can attach .zip archives.

    Matthias

Sign In or Register to comment.