How to erase polygons from each other

edited August 2013 in General
Hi,

In the menu are the options "add", "merge", "erase", "mask" and "diff" for polygons.

For "merge" I use:

edge = EdgeProcessor.new
edge.simple_merge_p2p([polygon_1, polygon_2], false, false, 1)

For "diff" I use:

edge.simple_merge_p2p([polygon_1, polygon_2], false, false, 0)

For "mask" I use:

edge.simple_merge_p2p([polygon_1, polygon_2], false, false, 2)

I couldn't figure out how I can get "erase" to work. Is it possible with the same "simple_merge_p2p" or something completely different?

Thanks
Stefan

Comments

  • edited November -1

    Not sure if this is what you want but there is an erase method in Shapes. http://klayout.de/doc/code/class_Shapes.html

    So you could do

    module EraseSelectedShape
    
      app = RBA::Application.instance
      mw = app.main_window
    
      lv = mw.current_view
      if lv == nil
        raise "No view selected"
      end
    
      lv.transaction("Erase selected shape")
      begin
    
        lv.each_object_selected do |obj|
          obj.shape.shapes.erase(obj.shape)
        end
    
        ensure 
        lv.commit
      end
    
    end
    
  • edited November -1

    Hallo,

    "erase" in the menu is basically a boolean "not", "mask" is "and" and "diff" is "xor".

    Is that comment helpful?

    Matthias

  • edited November -1

    Here's one more comment:

    The boolean operations are available with EdgeProcessor#boolean_p2p:

    # "not" aka "erase":
    edge.boolean_p2p([ polygon_1 ], [ polygon_2 ], EdgeProcessor::ModeANotB, false, false)
    
    # "xor" aka "diff":     
    edge.boolean_p2p([ polygon_1 ], [ polygon_2 ], EdgeProcessor::ModeXor, false, false)
    
    # "and" aka "mask":
    edge.boolean_p2p([ polygon_1 ], [ polygon_2 ], EdgeProcessor::ModeAnd, false, false)
    

    It's worth a note that using the boolean operations has some advantages over "simple_merge". The boolean operations will normalize self-overlapping regions of the original polygons automatically for example.

    Matthias

Sign In or Register to comment.