Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDSIIImport handles mirrored instantiations incorrectly. Here's the fix. #69

Open
ebflagg opened this issue Jul 20, 2024 · 0 comments
Open

Comments

@ebflagg
Copy link

ebflagg commented Jul 20, 2024

An instance of a cell can be scaled, mirrored, rotated, and/or translated. GDSIIImport's .get_as_shapely() method applies shapely affine transformations during conversion of cell instances into shapely objects. However, there are two problems in how the mirror transformation is implemented in .get_as_shapely(). First, the mirroring is done across the y-axis (i.e., x -> -x) instead of across the x-axis (i.e., y -> -y) as is done in Klayout. Second, the mirror plane is at the center of the bounding box rather than at the location of the origin as in Klayout. This means that instances that include "Mirrored (at X-axis)" in Klayout are not treated correctly in version 1.2.1 (53970dd), which is current as of July 2024.

The fix is to change line 50 in gdshelpers/parts/pattern_import.py
from this:
sub_geometry = scale(sub_geometry, -1) if reference.x_reflection else sub_geometry
to this:
sub_geometry = scale(sub_geometry, xfact=1, yfact=-1, origin=(0, 0)) if reference.x_reflection else sub_geometry

The -1 argument in the current version mirrors across the y-axis because it changes all x positions to (-x) positions. What we want is to mirror across the x-axis, so we want (x, y) -> (x, -y). Thus, xfact=1 and yfact=-1.

The default value of origin in shapely.affinity.scale is 'center', which means the mirror plane intersects the center of the 2D bounding box of the polygons. In contrast, in Klayout, the mirror plane intersects the origin. This is relevant if the polygons are arranged so the origin of their cell is not coincident with their bounding box. I have found such a situation very helpful in aligning structures in one sub-cell with structures in sub-cell. So, to have the shapely objects match the corresponding polygons in Klayout, we need origin=(0, 0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant