Run a polygon Convex decomposition from DRC

Good evening,
I am looking into runa Polygon Decomposition into Convex polygons from a DRC script.

Is this possible, or should I just make a lym script?

Comments

  • As so often, after I asked I found more and more similar questions, and I found an answer. I post it here, perhaps there are ways to make it faster, or somebody else wonders the same.

    The solution is to extend the DRCLayer Class inside the DRC file.

        class DRC::DRCLayer
          def decompose_convex()
            res = []
            self.data.each do |p|
              res.concat p.decompose_convex()
            end
            return DRC::DRCLayer::new(@engine, RBA::Region::new(res))
          end
        end
    
        polys = polygons("INPUT_LAYER")
        polys.decompose_convex().output(1001)
    
  • Ok, and I came across a bug report, the way to go is probably like this:

    polys = polygons("INPUT_LAYER")
    polys.data = polys.data.decompose_trapezoids_to_region
    polys.output(1001)
    

    Not sure why this works, but it does the same thing without making the class.

  • edited January 18

    Hi @gyger,

    the first version is actually the better one IMHO as it blends nicely into the DRC scheme. But it is not efficient as it uses a loop over the polygons. The second version is faster, but does a "decompose_trapezoids" which is not exactly the same thing as "decompose_convex" - but delivers convex polygons.

    If that is good enough, you can combine both approaches:

    class DRC::DRCLayer
      def decompose_convex()
        return DRC::DRCLayer::new(@engine, self.data.decompose_trapezoids_to_region)
      end
    end
    
    polys = polygons("INPUT_LAYER")
    polys.decompose_convex.output(1001)
    

    "Region" has a "decompose_convex_to_region" too, so you could write:

    class DRC::DRCLayer
      def decompose_convex()
        return DRC::DRCLayer::new(@engine, self.data.decompose_convex_to_region)
      end
    end
    
    polys = polygons("INPUT_LAYER")
    polys.decompose_convex.output(1001)
    

    The difference is this:

    decompose_trapezoids

    decompose_convex

    The decomposition into trapezoids generates minimal convex shapes (quadrangles or triangles) while the convex decomposition generates larger ones, but not necessarily the minimum number.

    Matthias

  • Thank you so much for responding, and for making this software happen.

Sign In or Register to comment.