It looks like you're new here. If you want to get involved, click one of these buttons!
Hello! First of all I'd like to say thanks for developing such nice tool! I'm writing python script and I've catched something strange on my way. Today I was confused one more time, so I decided to registrate here to ask my questions.
I've found that "inside" method works incorrect for the distances between point and polygon much lager than it may be according to lack of precision in notation of doubles.
[print(point) for point in dpoly.each_point()]
print(dpoly.inside(dpoint1), dpoint1)
With the output:
-0.507,-0.601
-1.144,0.342
-0.397,0.805
1.094,0.759
1.2,0.071
0.271,0.596
0.36,-0.278
True -1.154,0.342
But this point is obviously out of polygon. The polygon was read from layout and converted to DSimplePolygon via from_ipoly.
Also there is annoying behaviour when script consist of multiple files. When I modify one of the files that are imported in the main I have to relaunch IDE. I suppose this connected with reason mentioned here https://www.klayout.de/forum/comments.php?DiscussionID=905 so I'm asking for workaround.
Anton
Comments
I found that reimporting solved last problem:
Hi,
thanks for the hint about the "reload" feature.
Regarding your "inside" issue: the "inside" detection is based on a certain fuzziness which is far bigger (actually in the order of 0.1) than the actual floating point resolution. In fact, the DSimplePolygon is not intended for these kind of computations. Instead, you should use the integer versions. The floating point objects are provided for representing polygons in physical units, but not for computational purposes.
If you want to use DSimplePolygon and the other "D" objects, you should scale then to units close to your resolution limit (for example nm or even better: DBU).
Regards,
Matthias
By the way, are there any suggestions how can I convert SimplePolygon or usual Polygon, that is actually looks like simple to Polygon with hull and holes?
Regards
Hi,
Actually you can convert a SimplePolygon into "canonical" polygons. Those are: decomposed into hulls and holes, not self-overlapping, normalized in terms of orientation and without redundant points. The canonical form is obtained through "merging". There are cases where the simple polygon can fall apart into pieces during this process. Hence there is no simple "SimplePolygon" to "Polygon" conversion. But it's fairly convenient using the
Region#each_merged
iterator:Usually, the "each_merged" loop will produce only one polygon. But please be aware that multiple or even zero polygons may be produced. You can also put multiple simple polygons into the region. "each_merged" will then also remove overlaps between such polygons.
Matthias