Table Of Contents

Previous topic

gdsCAD.shapes

Next topic

gdsCAD.templates

This Page

gdsCAD.utils

Utility functions for geometric transformations and layer manipulation.

Note

Copyright 2009-2012 Lucas Heitzmann Gabrielli

Copyright 2013 Andrew G. Mark

gdsCAD (based on gdspy) is released under the terms of the GNU GPL

Function Summary

Transformation Functions

translate(obj, displacement) Translate an object, 2D vector, or a sequence of 2D vectors by the given vector
rotate(obj, theta[, center]) Rotate an object by given angle
reflect(obj, axis[, origin, reverse_seq]) Reflect an object in the x or y axis
scale(obj, k[, origin, reverse_seq]) Scale the pt or sequence of pts by the factor k

Layer Organization Functions

split_layers(cell, old_layers) Split the artwork in a cell between two copies according by layer.
relayer(cell, old_layers, new_layer) Move any elements in old_layers to new_layer

Deprecated Functions

These are old gdspy functions that no longer work, but may some day prove useful again

chop(polygon, position, axis) BROKEN: Slice polygon at a given position along a given axis.
slice(layer, objects, position, axis[, datatype]) BROKEN Slice polygons and polygon sets at given positions along an axis.
boolean(layer, objects, operation[, ...]) BROKEN Execute any boolean operation on polygons and polygon sets.

Module Definitions

Utility functions for geometric transformations and layer manipulation.

Note

Copyright 2009-2012 Lucas Heitzmann Gabrielli

Copyright 2013 Andrew G. Mark

gdsCAD (based on gdspy) is released under the terms of the GNU GPL

gdsCAD.utils.boolean(layer, objects, operation, max_points=199, datatype=0, eps=1e-13)[source]

BROKEN Execute any boolean operation on polygons and polygon sets.

Parameters

layer : integer
The GDSII layer number for the resulting element.
objects : array-like
Operands of the boolean operation. Each element of this array must be a Polygon, PolygonSet, CellReference, CellArray, or an array-like[N][2] of vertices of a polygon.
operation : function
Function that accepts as input len(objects) integers. Each integer represents the incidence of the corresponding object. The function must return a bool or integer (interpreted as bool).
max_points : integer
If greater than 4, fracture the resulting polygons to ensure they have at most max_points vertices. This is not a tessellating function, so this number should be as high as possible. For example, it should be set to 199 for polygons being drawn in GDSII files.
datatype : integer
The GDSII datatype for the resulting element (between 0 and 255).
eps : positive number
Small number to be used as tolerance in intersection and overlap calculations.

Returns

out : PolygonSet
Result of the boolean operation.

Notes

Since operation receives a list of integers as input, it can be somewhat more general than boolean operations only. See the examples below.

Because of roundoff errors there are a few cases when this function can cause segmentation faults. If that happens, increasing the value of eps might help.

Examples

>>> circle = gdspy.Round(0, (0, 0), 10)
>>> triangle = gdspy.Round(0, (0, 0), 12, number_of_points=3)
>>> bad_poly = gdspy.L1Path(1, (0, 0), '+y', 2,
        [6, 4, 4, 8, 4, 5, 10], [-1, -1, -1, 1, 1, 1])
>>> union = gdspy.boolean(1, [circle, triangle],
        lambda cir, tri: cir or tri)
>>> intersection = gdspy.boolean(1, [circle, triangle],
        lambda cir, tri: cir and tri)
>>> subtraction = gdspy.boolean(1, [circle, triangle],
        lambda cir, tri: cir and not tri)
>>> multi_xor = gdspy.boolean(1, [badPath], lambda p: p % 2)
gdsCAD.utils.chop(polygon, position, axis)[source]

BROKEN: Slice polygon at a given position along a given axis.

Parameters

polygon : array-like[N][2]
Coordinates of the vertices of the polygon.
position : number
Position to perform the slicing operation along the specified axis.
axis : 0 or 1
Axis along which the polygon will be sliced.

Returns

out : tuple[2]
Each element is a list of polygons (array-like[N][2]). The first list contains the polygons left before the slicing position, and the second, the polygons left after that position.
gdsCAD.utils.reflect(obj, axis, origin=(0, 0), reverse_seq=True)[source]

Reflect an object in the x or y axis

Parameters:
  • obj – a geometric object, 2D vector, or a sequence of 2D vectors.
  • axis – string ‘x’ or ‘y’ indcating which axis in which to make the refln.
  • origin – optional, pt about which to perform the rotation.
  • reverse_seq – if True reverses the order of a sequence.
Returns:

a reflected copy of obj

Sequences of points are reversed to maintain the same sense as the original sequence.

gdsCAD.utils.relayer(cell, old_layers, new_layer)[source]

Move any elements in old_layers to new_layer

Parameters:
  • cell – The Cell to process
  • old_layers – A list of layers to be relayed
  • new_layer – The layer that old_layers will be moved to
Returns:

A copy of the relayered Cell

TODO: use same labelling scheme found in GdsImport

gdsCAD.utils.rotate(obj, theta, center=(0, 0))[source]

Rotate an object by given angle

Parameters:
  • obj – an object, a 2D vector, or a sequence of 2D vectors
  • theta – angle by which to rotate points in deg
  • center – optional, pt about which to perform the rotation
Returns:

A rotated copy of obj

gdsCAD.utils.scale(obj, k, origin=(0, 0), reverse_seq=True)[source]

Scale the pt or sequence of pts by the factor k

Parameters:
  • obj – a geometric object, 2D vector, or a sequence of 2D vectors.
  • k – factor by which to scale obj
  • origin – pt which remains invariant under scale
  • reverse_seq – if True reverses the order of a sequence.
Returns:

a scaled copy of obj

The factor k can be a scalar or 2D vector allowing non-uniform scaling Optional origin can be a 2D vector or ‘COM’ indicating that scaling should be made about the pts centre of mass. The center of mass is calculated only for the points, not by the area of the polygon they define.

Sequences of points are reversed if necessary to maintain the same sense as the original sequence.

gdsCAD.utils.slice(layer, objects, position, axis, datatype=0)[source]

BROKEN Slice polygons and polygon sets at given positions along an axis.

Parameters

layer : integer, list
The GDSII layer numbers for the elements between each division. If the number of layers in the list is less than the number of divided regions, the list is repeated.
objects : Polygon, PolygonSet, or list
Operand of the slice operation. If this is a list, each element must be a Polygon, PolygonSet, CellReference, CellArray, or an array-like[N][2] of vertices of a polygon.
position : number or list of numbers
Positions to perform the slicing operation along the specified axis.
axis : 0 or 1
Axis along which the polygon will be sliced.
datatype : integer
The GDSII datatype for the resulting element (between 0 and 255).

Returns

out : list[N] of PolygonSet
Result of the slicing operation, with N = len(positions) + 1. Each PolygonSet comprises all polygons between 2 adjacent slicing positions, in crescent order.

Examples

>>> ring = gdspy.Round(1, (0, 0), 10, inner_radius = 5)
>>> result = gdspy.slice(1, ring, [-7, 7], 0)
>>> cell.add(result[1])
gdsCAD.utils.split_layers(cell, old_layers)[source]

Split the artwork in a cell between two copies according by layer.

Parameters:
  • cells – The Cell to split
  • old_layers – A list of layers whose artwork will be moved to the second cell
Returns:

A tuple of two cells

TODO: use same labelling scheme found in GdsImport

split_layers() provides a convenient method of separating layers in a Cell into different Cells. It creates two copies of cell based on the list of layers in old_layers. Any artwork found on the layers of old_layers is moved to the first cell, and any artwork not found on the layers of old_layers is moved to the second layer. The existing heirarchy is maintained, however any empty Cells or references are removed.

gdsCAD.utils.translate(obj, displacement)[source]

Translate an object, 2D vector, or a sequence of 2D vectors by the given vector

Parameters:
  • obj – an object, a 2D vector, or a sequence of 2D vectors
  • displacment – the vector by which to move obj
Returns:

A moved copy of the obj