Missing polygon point after substraction of two rectangles leads to "flagging" artefact

When I substract or XOR two rectangles, Klayout transforms this into a polygon with a hole, as shown in the sketch below. I added the numbers to show the order of the polygon points for this example. When I now apply a rotation to the polygon, a small gap along the line between points 2 and 3 appears. I assume this is due to snapping of the points to the grid, which leads to slightly different angles for the lines 2-3 vs. 6-7.
This "flagging" artefact could be overcome if point 3 was included as an additional point between 6 and 7. Is there a way to tell KLayout to do so in the substraction algorithm?
Thanks for any assistance with this.

Comments

  • Hello,

    This is indeed a snapping issue as explained above. Not sure if 3 or more points on one line are kept except for the outer two... Why not rotating the two rectangles first and do the subtraction at the end?

    Cheers,

    Tomas

  • Hi @ChristianP,

    A rotation by any angle will induce snapping as @tomas2004 explained. I think his approach is the right one.

    Problem is that the rotation is "stupid" and does not remove the cut line before rotation.

    Using a short DRC script you can merge all shapes on a layer - this will create polygons with holes which rotate without this artefact:

    # merge polygons from layer 1/0
    input(1, 0).merged.output(1, 0)
    

    However, this function has side effects: it will merge all shapes, turn boxes and paths into polygons and combine overlapping shapes. If you do not want that, here is a Python script that merges selected polygons into ones without cut lines:

    import klayout.lay as klay
    import klayout.db as kdb
    
    lv = klay.LayoutView.current()
    
    lv.transaction("Merge selected polygons")
    
    try:
    
      for sel in lv.each_object_selected():
        if not sel.is_cell_inst() and sel.shape.is_polygon():
          r = kdb.Region(sel.shape.polygon).merged()
          if r.size() == 1:
            # Note: "downcast" converts a PolygonWithProperties to a Polygon
            sel.shape.polygon = r[0].downcast()
    
    finally:
      lv.commit()
    

    Note that on saving to GDS or OASIS, the cut lines will re-appear as GDS does not have polygons with holes.

    Matthias

Sign In or Register to comment.