It looks like you're new here. If you want to get involved, click one of these buttons!
For Region constructor, I want to ask whether we can specify the method to construct it? I mean like in Python, we can use keyword to restrict them, then we can use specific method to construct our classes.
Currently, I think the region constructor in KLayout select the way to create the class by determining the input automatically. But when I wrap the pya.Polygon into my own class, then I create my own polygon and use region to combine them, and the constructor failed. Here is the code, you can reproduce such problem.
import pya
class MyPolygon:
def __init__(self, pts):
self.obj = pya.DPolygon(pts)
if __name__ == '__main__':
polygon1 = MyPolygon([pya.Point(0, 0),
pya.Point(0, 20),
pya.Point(20, 20),
pya.Point(20, 0),
pya.Point(0, 0)])
polygon2 = MyPolygon([pya.Point(0, 0),
pya.Point(0, -20),
pya.Point(-20, -20),
pya.Point(-20, 0),
pya.Point(0, 0), ])
print(polygon1.obj) # (0,0;0,20;20,20;20,0;0,0)
print(polygon2.obj) # (-20,-20;-20,0;0,0;0,0;0,-20)
print(type(polygon1.obj)) # <class 'klayout.pyacore.DPolygon'>
print(type(polygon2.obj)) # <class 'klayout.pyacore.DPolygon'>
region = pya.Region([polygon1.obj, polygon2.obj])
The error information are seen like below.
Comments
vs
Oh my god, is this mean that for region stuff, we can not use float coordinates? Is this mean that if we want to deal with nm, we need to use dbu as coordinate first, and to make integer coordinates, and then we convert to um? Seems this is not convenient. It will take a lot of effort!
The constructors
from Polygon to DPolygon
andfrom DPolygon to Polygon
are provided, but not betweenan array of them
, which is the root cause.Therefore, the two cases below work if you want to keep
pya.DPolygon
in class MyPolygon.I think
f2650C.py
would be practical.f2650B.py
f2650C.py
Yes, got it. Thanks