You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
The text was updated successfully, but these errors were encountered:
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
andyfact=-1
.The default value of
origin
inshapely.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 needorigin=(0, 0)
.The text was updated successfully, but these errors were encountered: