Closed joamatab closed 6 months ago
This works, but it seems the .pyi didn't pick up the new function overload.
>>> import klayout.db as kdb
>>> kdb.Polygon([[0,0],[10,0],[10.5,10]])
(0,0;10,10;10,0)
>>> kdb.DPolygon([[0,0],[10,0],[10.,10]])
(0,0;10,10;10,0)
The issue seems to be if the list has exactly 4 points, then the creation fails
>>> poly1=kf.kdb.DPolygon([(0,0),[-10,0],[10.,10],[10,0]])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Ambiguous overload variants - multiple method declarations match arguments in DPolygon.__init__
@klayoutmatthias could it be that klayout tries to cast to a Box first here?
Grml ... I knew too much smartness would finally create some trouble ... :(
Basically, the whole scheme why this is works is the inference logic KLayout uses: if an argument expects an object, but is passed an array, KLayout tries to call the object constructor from the arguments of the array. This also works for array elements.
This is way (0,0)
can create a DPoint
in the DPolygon([DPoint, DPoint, ... ])
constructor. In the same fashion a four-element array can be matched to the arguments of DBox
in the DPolygon(DBox)
constructor. This is what happens here and creates that ambiguity.
I can fix this by giving precedence of array matching array (I think).
The best workaround is to use "assign_hull" which does not have a Box
overload:
poly = kf.kdb.DPolygon()
poly.assign_hull([(0,0),[-10,0],[10.,10],[10,0]])
Matthias
awesome! that worked, thank you Matthias!
feel free to close this
Very good, thanks for the feedback.
I'll keep that ticket open to remind me of this stupid ambiguity. I shall be less permissive on the inference paths.
Matthias
When adding polygons with 4 points we get an error
@amccaugh @sebastian-goeldi