Skip to content

Commit

Permalink
Version 0.5.5
Browse files Browse the repository at this point in the history
* Add flip rotate scale move operations for layers.
  • Loading branch information
Hideousmon committed Jul 5, 2024
1 parent 761abfa commit d12f640
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
5 changes: 4 additions & 1 deletion history.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,7 @@

### Version 0.5.4 (May 21, 2024)
* Automatically search for Ansys Lumerical Python API.
* Add use_gpu option for fdtd_region.
* Add use_gpu option for fdtd_region.
*
### Version 0.5.5 (Jul 21, 2024)
* Add flip rotate scale move operations for layers.
2 changes: 1 addition & 1 deletion splayout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.4"
__version__ = "0.5.5"

## Submodules
from . import utils
Expand Down
85 changes: 84 additions & 1 deletion splayout/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def inversion(self, distance = 2, output_layer = None):
Notes
-----
The sub-cells will be taken into calculation but will not be revised.s
The sub-cells will be taken into calculation but will not be revised.
"""
if output_layer is None:
output_layer = self
Expand All @@ -296,6 +296,89 @@ def inversion(self, distance = 2, output_layer = None):
top_cell.remove_polygons(lambda p, l, d: (l == output_layer.layer and d == output_layer.datatype))
top_cell.add(inversion_components)

def flip_horizontally(self):
"""
Flip the components in this layer horizontally relative to Point(0, 0).
"""
top_cell = common_lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
flipped_components = []
for poly in polygons[(self.layer, self.datatype)]:
flipped_components.append(gdspy.Polygon(poly, self.layer, self.datatype).mirror((0, -1), (0, 1)))
top_cell.remove_polygons(lambda p, l, d: (l == self.layer and d == self.datatype))
top_cell.add(flipped_components)

def flip_vertically(self):
"""
Flip the components in this layer vertically relative to Point(0, 0).
"""
top_cell = common_lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
flipped_components = []
for poly in polygons[(self.layer, self.datatype)]:
flipped_components.append(gdspy.Polygon(poly, self.layer, self.datatype).mirror((-1, 0), (1, 0)))
top_cell.remove_polygons(lambda p, l, d: (l == self.layer and d == self.datatype))
top_cell.add(flipped_components)


def rotate(self, radian):
"""
Rotate the components in this layer relative to Point(0, 0).
Parameters
----------
radian : Float
Rotation angle in radian.
"""
top_cell = common_lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
rotated_components = []
for poly in polygons[(self.layer, self.datatype)]:
rotated_components.append(gdspy.Polygon(poly, self.layer, self.datatype).rotate(radian, (0, 0)))
top_cell.remove_polygons(lambda p, l, d: (l == self.layer and d == self.datatype))
top_cell.add(rotated_components)


def scale(self, scalex, scaley=None):
"""
Scale the components in this layer relative to Point(0, 0).
Parameters
----------
scalex : Float
Scaling ratio in x-axis.
scaley : Float
Scaling ratio in y-axis. (default: same with scalex)
"""
if scaley is None:
scaley = scalex
top_cell = common_lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
scaled_components = []
for poly in polygons[(self.layer, self.datatype)]:
scaled_components.append(gdspy.Polygon(poly, self.layer, self.datatype).scale(scalex, scaley, (0, 0)))
top_cell.remove_polygons(lambda p, l, d: (l == self.layer and d == self.datatype))
top_cell.add(scaled_components)

def move(self, distance_x=0, distance_y=0):
"""
Move the components in this layer by a certain distance.
Parameters
----------
distance_x : Int or Float
Moving distance in x-axis. (unit: micrometer, default: 0)
distance_y : Int or Float
Moving distance in y-axis. (unit: micrometer, default: 0)
"""
top_cell = common_lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
scaled_components = []
for poly in polygons[(self.layer, self.datatype)]:
scaled_components.append(gdspy.Polygon(poly, self.layer, self.datatype).translate(distance_x, distance_y))
top_cell.remove_polygons(lambda p, l, d: (l == self.layer and d == self.datatype))
top_cell.add(scaled_components)




Expand Down

0 comments on commit d12f640

Please sign in to comment.