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)
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.
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.
Ok, and I came across a bug report, the way to go is probably like this:
Not sure why this works, but it does the same thing without making the class.
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:
"Region" has a "decompose_convex_to_region" too, so you could write:
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.