Main API — gdspy 1.0 documentation

# Main API

gdspy is a Python module that allows the creation of GDSII stream files.

Many features of the GDSII format are implemented, such as cell references and arrays, but the support for fonts is quite limited. Text is only available through polygonal objects.

If the Python Imaging Library is installed, it can be used to output the geometry created to an image file.

## Classes

### Cell

class `gdspy.` `Cell`(name, exclude_from_global=False)

  Bases: `object`

  Collection of elements, both geometric objects and references to other cells.

  Parameters: | name : string The name of the cell. exclude_from_global : bool If `True`, the cell will not be included in the global list of cells maintained by `gdspy`.

  Methods

  `add`(element)

    Add a new element or list of elements to this cell.

    Parameters: | element : object, list The element or list of elements to be inserted in this cell.
    Returns: | out : `Cell` This cell.

  `area`(by_spec=False)

    Calculate the total area of the elements on this cell, including cell references and arrays.

    Parameters: | by_spec : bool If `True`, the return value is a dictionary with the areas of each individual pair (layer, datatype).
    Returns: | out : number, dictionary Area of this cell.

  `cell_dict` = {}

    Dictionary containing all cells created, indexed by name. This dictionary is updated automatically whenever a new `Cell` object is created without the `exclude_from_global` flag.

  `copy`(name, exclude_from_global=False, deep_copy=False)

    Creates a copy of this cell.

    Parameters: | name : string The name of the cell. exclude_from_global : bool If `True`, the cell will not be included in the global list of cells maintained by `gdspy`. deep_copy : bool If `False`, the new cell will contain only references to the existing elements. If `True`, copies of all elements are also created.
    Returns: | out : `Cell` The new copy of this cell.

  `flatten`(single_layer=None, single_datatype=None, verbose=True)

    Flatten all `CellReference` and `CellArray` elements in this cell into real polygons, instead of references.

    Parameters: | single_layer : integer or None If not `None`, all polygons will be transfered to the layer indicated by this number. single_datatype : integer or None If not `None`, all polygons will be transfered to the datatype indicated by this number. verbose : bool If False, warnings about the number of vertices of the polygon will be suppressed.
    Returns: | out : `Cell` This cell.

  `get_bounding_box`()

    Returns the bounding box for this cell.

    Returns: | out : Numpy array[2,2] or `None` Bounding box of this cell [[x_min, y_min], [x_max, y_max]], or `None` if the cell is empty.

  `get_datatypes`()

    Returns a list of datatypes in this cell.

    Returns: | out : list List of the datatypes used in this cell.

  `get_dependencies`()

    Returns a list of the cells included in this cell as references.

    Returns: | out : list of `Cell` List of the cells referenced by this cell.

  `get_layers`()

    Returns a list of layers in this cell.

    Returns: | out : list List of the layers used in this cell.

  `get_polygons`(by_spec=False, depth=None)

    Returns a list of polygons in this cell.

    Parameters: | by_spec : bool If `True`, the return value is a dictionary with the polygons of each individual pair (layer, datatype). depth : integer or `None` If not `None`, defines from how many reference levels to retrieve polygons. References below this level will result in a bounding box. If `by_spec` is `True` the key wil be the name of this cell.
    Returns: | out : list of array-like[N][2] or dictionary List containing the coordinates of the vertices of each polygon, or dictionary with the list of polygons (if `by_spec` is `True`).

  `to_gds`(multiplier)

    Convert this cell to a GDSII structure.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII structure.
    Returns: | out : string The GDSII binary string that represents this cell.

### Polygon

class `gdspy.` `Polygon`(points, layer=0, datatype=0, verbose=True)

  Bases: `object`

  Polygonal geometric object.

  Parameters: | points : array-like[N][2] Coordinates of the vertices of the polygon. layer : integer The GDSII layer number for this element. datatype : integer The GDSII datatype for this element (between 0 and 255). verbose : bool If False, warnings about the number of vertices of the polygon will be suppressed.

  Notes

  The last point should not be equal to the first (polygons are automatically closed).

  The GDSII specification supports only a maximum of 199 vertices per polygon.

  Examples

      >>> triangle_pts = [(0, 40), (15, 40), (10, 50)]
      >>> triangle = gdspy.Polygon(triangle_pts)
      >>> myCell.add(triangle)

  Methods

  `area`(by_spec=False)

    Calculate the total area of this object.

    Parameters: | by_spec : bool If `True`, the return value is a dictionary `{(layer, datatype): area}`.
    Returns: | out : number, dictionary Area of this object.

  `fillet`(radius, points_per_2pi=128, max_points=199)

    Round the corners of this polygon and fractures it into polygons with less vertices if necessary.

    Parameters: | radius : number, list Radius of the corners. points_per_2pi : integer Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi. max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `Polygon` or `PolygonSet` If no fracturing occurs, return this object; otherwise return a `PolygonSet` with the fractured result (this object will have more than `max_points` vertices).

  `fracture`(max_points=199)

    Slice this polygon in the horizontal and vertical directions so that each resulting piece has at most `max_points`.

    Parameters: | max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` Resulting polygons from the fracture operation.

  `rotate`(angle, center=(0, 0))

    Rotate this object.

    Parameters: | angle : number The angle of rotation (in radians). center : array-like[2] Center point for the rotation.
    Returns: | out : `Polygon` This object.

  `to_gds`(multiplier)

    Convert this object to a GDSII element.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII element.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the polygon from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `Polygon` This object.

    Examples

        >>> polygon = gdspy.Polygon((0, 0), (10, 20))
        >>> polygon = polygon.translate(2,0)
        >>> myCell.add(polygon)

### Rectangle

class `gdspy.` `Rectangle`(point1, point2, layer=0, datatype=0)

  Bases: `gdspy.Polygon`

  Rectangular geometric object.

  Parameters: | point1 : array-like[2] Coordinates of a corner of the rectangle. point2 : array-like[2] Coordinates of the corner of the rectangle opposite to `point1`. layer : integer The GDSII layer number for this element. datatype : integer The GDSII datatype for this element (between 0 and 255).

  Examples

      >>> rectangle = gdspy.Rectangle((0, 0), (10, 20))
      >>> myCell.add(rectangle)

  Methods

  `area`(by_spec=False)

    Calculate the total area of this object.

    Parameters: | by_spec : bool If `True`, the return value is a dictionary `{(layer, datatype): area}`.
    Returns: | out : number, dictionary Area of this object.

  `fillet`(radius, points_per_2pi=128, max_points=199)

    Round the corners of this polygon and fractures it into polygons with less vertices if necessary.

    Parameters: | radius : number, list Radius of the corners. points_per_2pi : integer Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi. max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `Polygon` or `PolygonSet` If no fracturing occurs, return this object; otherwise return a `PolygonSet` with the fractured result (this object will have more than `max_points` vertices).

  `fracture`(max_points=199)

    Slice this polygon in the horizontal and vertical directions so that each resulting piece has at most `max_points`.

    Parameters: | max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` Resulting polygons from the fracture operation.

  `rotate`(angle, center=(0, 0))

    Rotate this object.

    Parameters: | angle : number The angle of rotation (in radians). center : array-like[2] Center point for the rotation.
    Returns: | out : `Polygon` This object.

  `to_gds`(multiplier)

    Convert this object to a GDSII element.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII element.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the polygon from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `Polygon` This object.

    Examples

        >>> polygon = gdspy.Polygon((0, 0), (10, 20))
        >>> polygon = polygon.translate(2,0)
        >>> myCell.add(polygon)

### Round

class `gdspy.` `Round`(center, radius, inner_radius=0, initial_angle=0, final_angle=0, number_of_points=0.01, max_points=199, layer=0, datatype=0)

  Bases: `gdspy.PolygonSet`

  Circular geometric object. Represent a circle, a circular section, a ring or a ring section.

  Parameters: | center : array-like[2] Coordinates of the center of the circle/ring. radius : number Radius of the circle/outer radius of the ring. inner_radius : number Inner radius of the ring. initial_angle : number Initial angle of the circular/ring section (in radians). final_angle : number Final angle of the circular/ring section (in radians). number_of_points : integer or float If integer: number of vertices that form the object (polygonal approximation). If float: approximate curvature resolution. The actual number of points is automatically calculated. max_points : integer if `number_of_points > max_points`, the element will be fractured in smaller polygons with at most `max_points` each. layer : integer The GDSII layer number for this element. datatype : integer The GDSII datatype for this element (between 0 and 255).

  Notes

  The GDSII specification supports only a maximum of 199 vertices per polygon.

  Examples

      >>> circle = gdspy.Round((30, 5), 8)
      >>> ring = gdspy.Round((50, 5), 8, inner_radius=5)
      >>> pie_slice = gdspy.Round((30, 25), 8, initial_angle=0,
      ...                             final_angle=-5.0*numpy.pi/6.0)
      >>> arc = gdspy.Round((50, 25), 8, inner_radius=5,
      ...                       initial_angle=-5.0*numpy.pi/6.0,
      ...                       final_angle=0)

  Methods

  `area`(by_spec=False)

    Calculate the total area of the path(s).

    Parameters: | by_spec : bool If `True`, the return value is a dictionary `{(layer, datatype): area}`.
    Returns: | out : number, dictionary Area of this object.

  `fillet`(radius, points_per_2pi=128, max_points=199)

    Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

    Parameters: | radius : number, list Radius of the corners. If number: All corners filleted by that amount If list: Specify fillet radii on a per-corner basis (list length must be equal to the number of points in the Polygon) points_per_2pi : integer Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi. max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `fracture`(max_points=199)

    Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most `max_points`. This operation occurs in place.

    Parameters: | max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `rotate`(angle, center=(0, 0))

    Rotate this object.

    Parameters: | angle : number The angle of rotation (in radians). center : array-like[2] Center point for the rotation.
    Returns: | out : `PolygonSet` This object.

  `to_gds`(multiplier)

    Convert this object to a series of GDSII elements.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII elements.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the polygons from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `PolygonSet` This object.

### PolygonSet

class `gdspy.` `PolygonSet`(polygons, layer=0, datatype=0, verbose=True)

  Bases: `object`

  Set of polygonal objects.

  Parameters: | polygons : list of array-like[N][2] List containing the coordinates of the vertices of each polygon. layer : integer The GDSII layer number for this element. datatype : integer The GDSII datatype for this element (between 0 and 255). verbose : bool If False, warnings about the number of vertices of the polygons will be suppressed.

  Notes

  The last point should not be equal to the first (polygons are automatically closed).

  The GDSII specification supports only a maximum of 199 vertices per polygon.

  Methods

  `area`(by_spec=False)

    Calculate the total area of the path(s).

    Parameters: | by_spec : bool If `True`, the return value is a dictionary `{(layer, datatype): area}`.
    Returns: | out : number, dictionary Area of this object.

  `fillet`(radius, points_per_2pi=128, max_points=199)

    Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

    Parameters: | radius : number, list Radius of the corners. If number: All corners filleted by that amount If list: Specify fillet radii on a per-corner basis (list length must be equal to the number of points in the Polygon) points_per_2pi : integer Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi. max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `fracture`(max_points=199)

    Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most `max_points`. This operation occurs in place.

    Parameters: | max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `rotate`(angle, center=(0, 0))

    Rotate this object.

    Parameters: | angle : number The angle of rotation (in radians). center : array-like[2] Center point for the rotation.
    Returns: | out : `PolygonSet` This object.

  `to_gds`(multiplier)

    Convert this object to a series of GDSII elements.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII elements.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the polygons from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `PolygonSet` This object.

### Path

class `gdspy.` `Path`(width, initial_point=(0, 0), number_of_paths=1, distance=0)

  Bases: `gdspy.PolygonSet`

  Series of geometric objects that form a path or a collection of parallel paths.

  Parameters: | width : number The width of each path. initial_point : array-like[2] Starting position of the path. number_of_paths : positive integer Number of parallel paths to create simultaneously. distance : number Distance between the centers of adjacent paths.

  Attributes

  x | (number) Current position of the path in the x direction.
  y | (number) Current position of the path in the y direction.
  w | (number) Half-width of each path.
  n | (integer) Number of parallel paths.
  direction | ({‘+x’, ‘-x’, ‘+y’, ‘-y’} or number) Direction or angle (in radians) the path points to.
  distance | (number) Distance between the centers of adjacent paths.
  length | (number) Length of the central path axis. If only one path is created, this is the real length of the path.

  Methods

  `arc`(radius, initial_angle, final_angle, number_of_points=0.01, max_points=199, final_width=None, final_distance=None, layer=0, datatype=0)

    Add a curved section to the path.

    Parameters: | radius : number Central radius of the section. initial_angle : number Initial angle of the curve (in radians). final_angle : number Final angle of the curve (in radians). number_of_points : integer or float If integer: number of vertices that form the object (polygonal approximation). If float: approximate curvature resolution. The actual number of points is automatically calculated. max_points : integer if `number_of_points > max_points`, the element will be fractured in smaller polygons with at most `max_points` each. final_width : number If set, the paths of this segment will have their widths linearly changed from their current value to this one. final_distance : number If set, the distance between paths is linearly change from its current value to this one along this segment. layer : integer, list The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated. datatype : integer, list The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.
    Returns: | out : `Path` This object.

    Notes

    The GDSII specification supports only a maximum of 199 vertices per polygon.

  `area`(by_spec=False)

    Calculate the total area of the path(s).

    Parameters: | by_spec : bool If `True`, the return value is a dictionary `{(layer, datatype): area}`.
    Returns: | out : number, dictionary Area of this object.

  `fillet`(radius, points_per_2pi=128, max_points=199)

    Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

    Parameters: | radius : number, list Radius of the corners. If number: All corners filleted by that amount If list: Specify fillet radii on a per-corner basis (list length must be equal to the number of points in the Polygon) points_per_2pi : integer Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi. max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `fracture`(max_points=199)

    Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most `max_points`. This operation occurs in place.

    Parameters: | max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `parametric`(curve_function, curve_derivative=None, number_of_evaluations=99, max_points=199, final_width=None, final_distance=None, layer=0, datatype=0)

    Add a parametric curve to the path.

    Parameters: | curve_function : function Function that defines the curve. Must be a function of one argument (that varies from 0 to 1) that returns a 2-element list, tuple or array (x, y). curve_derivative : function If set, it should be the derivative of the curve function. Must be a function of one argument (that varies from 0 to 1) that returns a 2-element list, tuple or array (x,y). If `None`, the derivative will be calculated numerically. number_of_evaluations : integer Number of points where the curve function will be evaluated. The final segment will have twice this number of points. max_points : integer If `2 * number_of_evaluations > max_points`, the element will be fractured in smaller polygons with at most `max_points` each. final_width : number or function If set to a number, the paths of this segment will have their widths linearly changed from their current value to this one. If set to a function, it must be a function of one argument (that varies from 0 to 1) and returns the width of the path. final_distance : number or function If set to ta number, the distance between paths is linearly change from its current value to this one. If set to a function, it must be a function of one argument (that varies from 0 to 1) and returns the width of the path. layer : integer, list The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated. datatype : integer, list The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.
    Returns: | out : `Path` This object.

    Notes

    The norm of the vector returned by `curve_derivative` is not important. Only the direction is used.

    The GDSII specification supports only a maximum of 199 vertices per polygon.

    Examples

        >>> def my_parametric_curve(t):
        ...         return (2**t, t**2)
        >>> def my_parametric_curve_derivative(t):
        ...         return (0.69315 * 2**t, 2 * t)
        >>> my_path.parametric(my_parametric_curve,
        ...                    my_parametric_curve_derivative)

  `rotate`(angle, center=(0, 0))

    Rotate this object.

    Parameters: | angle : number The angle of rotation (in radians). center : array-like[2] Center point for the rotation.
    Returns: | out : `Path` This object.

  `segment`(length, direction=None, final_width=None, final_distance=None, axis_offset=0, layer=0, datatype=0)

    Add a straight section to the path.

    Parameters: | length : number Length of the section to add. direction : {‘+x’, ‘-x’, ‘+y’, ‘-y’} or number Direction or angle (in radians) of rotation of the segment. final_width : number If set, the paths of this segment will have their widths linearly changed from their current value to this one. final_distance : number If set, the distance between paths is linearly change from its current value to this one along this segment. axis_offset : number If set, the paths will be offset from their direction by this amount. layer : integer, list The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated. datatype : integer, list The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.
    Returns: | out : `Path` This object.

  `to_gds`(multiplier)

    Convert this object to a series of GDSII elements.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII elements.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the polygons from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `PolygonSet` This object.

  `turn`(radius, angle, number_of_points=0.01, max_points=199, final_width=None, final_distance=None, layer=0, datatype=0)

    Add a curved section to the path.

    Parameters: | radius : number Central radius of the section. angle : {‘r’, ‘l’, ‘rr’, ‘ll’} or number Angle (in radians) of rotation of the path. The values ‘r’ and ‘l’ represent 90-degree turns cw and ccw, respectively; the values ‘rr’ and ‘ll’ represent analogous 180-degree turns. number_of_points : integer or float If integer: number of vertices that form the object (polygonal approximation). If float: approximate curvature resolution. The actual number of points is automatically calculated. max_points : integer if `number_of_points > max_points`, the element will be fractured in smaller polygons with at most `max_points` each. final_width : number If set, the paths of this segment will have their widths linearly changed from their current value to this one. final_distance : number If set, the distance between paths is linearly change from its current value to this one along this segment. layer : integer, list The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated. datatype : integer, list The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.
    Returns: | out : `Path` This object.

    Notes

    The GDSII specification supports only a maximum of 199 vertices per polygon.

### PolyPath

class `gdspy.` `PolyPath`(points, width, number_of_paths=1, distance=0, corners=0, ends=0, max_points=199, layer=0, datatype=0)

  Bases: `gdspy.PolygonSet`

  Series of geometric objects that form a polygonal path or a collection of parallel polygonal paths.

  Parameters: | points : array-like[N][2] Endpoints of each path segment. width : number or array-like[N] Width of the path. If an array is given, width at each endpoint. number_of_paths : positive integer Number of parallel paths to create simultaneously. distance : number or array-like[N] Distance between the centers of adjacent paths. If an array is given, distance at each endpoint. corners : positive integer Type of joins: 0 - miter join, 1 - bevel join ends : positive integer Type of path ends: 0 - no extension, 1 - rounded, 2 - extended by half width max_points : integer The paths will be fractured in polygons with at most `max_points`. layer : integer, list The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated. datatype : integer, list The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.
  Returns: | out : `PolyPath` This object.

  Notes

  The bevel join will give strange results if the number of paths is greater than 1.

  Methods

  `area`(by_spec=False)

    Calculate the total area of the path(s).

    Parameters: | by_spec : bool If `True`, the return value is a dictionary `{(layer, datatype): area}`.
    Returns: | out : number, dictionary Area of this object.

  `fillet`(radius, points_per_2pi=128, max_points=199)

    Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

    Parameters: | radius : number, list Radius of the corners. If number: All corners filleted by that amount If list: Specify fillet radii on a per-corner basis (list length must be equal to the number of points in the Polygon) points_per_2pi : integer Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi. max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `fracture`(max_points=199)

    Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most `max_points`. This operation occurs in place.

    Parameters: | max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `rotate`(angle, center=(0, 0))

    Rotate this object.

    Parameters: | angle : number The angle of rotation (in radians). center : array-like[2] Center point for the rotation.
    Returns: | out : `PolygonSet` This object.

  `to_gds`(multiplier)

    Convert this object to a series of GDSII elements.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII elements.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the polygons from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `PolygonSet` This object.

### L1Path

class `gdspy.` `L1Path`(initial_point, direction, width, length, turn, number_of_paths=1, distance=0, max_points=199, layer=0, datatype=0)

  Bases: `gdspy.PolygonSet`

  Series of geometric objects that form a path or a collection of parallel paths with Manhattan geometry.

  Parameters: | initial_point : array-like[2] Starting position of the path. direction : {‘+x’, ‘+y’, ‘-x’, ‘-y’} Starting direction of the path. width : number The initial width of each path. length : array-like Lengths of each section to add. turn : array-like Direction to turn before each section. The sign indicate the turn direction (ccw is positive), and the modulus is a multiplicative factor for the path width after each turn. Must have 1 element less then `length`. number_of_paths : positive integer Number of parallel paths to create simultaneously. distance : number Distance between the centers of adjacent paths. layer : integer, list The GDSII layer numbers for the elements of each path. If the number of layers in the list is less than the number of paths, the list is repeated. datatype : integer, list The GDSII datatype for the elements of each path (between 0 and 255). If the number of datatypes in the list is less than the number of paths, the list is repeated.
  Returns: | out : `L1Path` This object.

  Examples

      >>> length = [10, 30, 15, 15, 15, 15, 10]
      >>> turn = [1, -1, -1, 3, -1, 1]
      >>> l1path = gdspy.L1Path((0, 0), '+x', 2, length, turn)
      >>> myCell.add(l1path)

  Attributes

  x | (number) Final position of the path in the x direction.
  y | (number) Final position of the path in the y direction.
  direction | ({‘+x’, ‘-x’, ‘+y’, ‘-y’} or number) Direction or angle (in radians) the path points to. The numerical angle is returned only after a rotation of the object.

  Methods

  `area`(by_spec=False)

    Calculate the total area of the path(s).

    Parameters: | by_spec : bool If `True`, the return value is a dictionary `{(layer, datatype): area}`.
    Returns: | out : number, dictionary Area of this object.

  `fillet`(radius, points_per_2pi=128, max_points=199)

    Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

    Parameters: | radius : number, list Radius of the corners. If number: All corners filleted by that amount If list: Specify fillet radii on a per-corner basis (list length must be equal to the number of points in the Polygon) points_per_2pi : integer Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi. max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `fracture`(max_points=199)

    Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most `max_points`. This operation occurs in place.

    Parameters: | max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `rotate`(angle, center=(0, 0))

    Rotate this object.

    Parameters: | angle : number The angle of rotation (in radians). center : array-like[2] Center point for the rotation.
    Returns: | out : `L1Path` This object.

  `to_gds`(multiplier)

    Convert this object to a series of GDSII elements.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII elements.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the polygons from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `PolygonSet` This object.

### Text

class `gdspy.` `Text`(text, size, position=(0, 0), horizontal=True, angle=0, layer=0, datatype=0)

  Bases: `gdspy.PolygonSet`

  Polygonal text object.

  Each letter is formed by a series of polygons.

  Parameters: | text : string The text to be converted in geometric objects. size : number Base size of each character. position : array-like[2] Text position (lower left corner). horizontal : bool If `True`, the text is written from left to right; if `False`, from top to bottom. angle : number The angle of rotation of the text. layer : integer The GDSII layer number for these elements. datatype : integer The GDSII datatype for this element (between 0 and 255).

  Examples

      >>> text = gdspy.Text('Sample text', 20, (-10, -100))
      >>> myCell.add(text)

  Methods

  `area`(by_spec=False)

    Calculate the total area of the path(s).

    Parameters: | by_spec : bool If `True`, the return value is a dictionary `{(layer, datatype): area}`.
    Returns: | out : number, dictionary Area of this object.

  `fillet`(radius, points_per_2pi=128, max_points=199)

    Round the corners of these polygons and fractures them into polygons with less vertices if necessary.

    Parameters: | radius : number, list Radius of the corners. If number: All corners filleted by that amount If list: Specify fillet radii on a per-corner basis (list length must be equal to the number of points in the Polygon) points_per_2pi : integer Number of vertices used to approximate a full circle. The number of vertices in each corner of the polygon will be the fraction of this number corresponding to the angle encompassed by that corner with respect to 2 pi. max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `fracture`(max_points=199)

    Slice these polygons in the horizontal and vertical directions so that each resulting piece has at most `max_points`. This operation occurs in place.

    Parameters: | max_points : integer Maximal number of points in each resulting polygon (must be greater than 4).
    Returns: | out : `PolygonSet` This object.

  `rotate`(angle, center=(0, 0))

    Rotate this object.

    Parameters: | angle : number The angle of rotation (in radians). center : array-like[2] Center point for the rotation.
    Returns: | out : `PolygonSet` This object.

  `to_gds`(multiplier)

    Convert this object to a series of GDSII elements.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII elements.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the polygons from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `PolygonSet` This object.

### CellReference

class `gdspy.` `CellReference`(ref_cell, origin=(0, 0), rotation=None, magnification=None, x_reflection=False)

  Bases: `object`

  Simple reference to an existing cell.

  Parameters: | ref_cell : `Cell` or string The referenced cell or its name. origin : array-like[2] Position where the reference is inserted. rotation : number Angle of rotation of the reference (in degrees). magnification : number Magnification factor for the reference. x_reflection : bool If `True`, the reference is reflected parallel to the x direction before being rotated.

  Methods

  `area`(by_spec=False)

    Calculate the total area of the referenced cell with the magnification factor included.

    Parameters: | by_spec : bool If `True`, the return value is a dictionary with the areas of each individual pair (layer, datatype).
    Returns: | out : number, dictionary Area of this cell.

  `get_bounding_box`()

    Returns the bounding box for this reference.

    Returns: | out : Numpy array[2,2] or `None` Bounding box of this cell [[x_min, y_min], [x_max, y_max]], or `None` if the cell is empty.

  `get_polygons`(by_spec=False, depth=None)

    Returns a list of polygons created by this reference.

    Parameters: | by_spec : bool If `True`, the return value is a dictionary with the polygons of each individual pair (layer, datatype). depth : integer or `None` If not `None`, defines from how many reference levels to retrieve polygons. References below this level will result in a bounding box. If `by_spec` is `True` the key will be the name of the referenced cell.
    Returns: | out : list of array-like[N][2] or dictionary List containing the coordinates of the vertices of each polygon, or dictionary with the list of polygons (if `by_spec` is `True`).

  `to_gds`(multiplier)

    Convert this object to a GDSII element.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII element.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the reference from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `CellReference` This object.

### CellArray

class `gdspy.` `CellArray`(ref_cell, columns, rows, spacing, origin=(0, 0), rotation=None, magnification=None, x_reflection=False)

  Bases: `object`

  Multiple references to an existing cell in an array format.

  Parameters: | ref_cell : `Cell` or string The referenced cell or its name. columns : positive integer Number of columns in the array. rows : positive integer Number of columns in the array. spacing : array-like[2] distances between adjacent columns and adjacent rows. origin : array-like[2] Position where the cell is inserted. rotation : number Angle of rotation of the reference (in degrees). magnification : number Magnification factor for the reference. x_reflection : bool If `True`, the reference is reflected parallel to the x direction before being rotated.

  Methods

  `area`(by_spec=False)

    Calculate the total area of the cell array with the magnification factor included.

    Parameters: | by_spec : bool If `True`, the return value is a dictionary with the areas of each individual pair (layer, datatype).
    Returns: | out : number, dictionary Area of this cell.

  `get_bounding_box`()

    Returns the bounding box for this reference.

    Returns: | out : Numpy array[2,2] or `None` Bounding box of this cell [[x_min, y_min], [x_max, y_max]], or `None` if the cell is empty.

  `get_polygons`(by_spec=False, depth=None)

    Returns a list of polygons created by this reference.

    Parameters: | by_spec : bool If `True`, the return value is a dictionary with the polygons of each individual pair (layer, datatype). depth : integer or `None` If not `None`, defines from how many reference levels to retrieve polygons. References below this level will result in a bounding box. If `by_spec` is `True` the key will be name of the referenced cell.
    Returns: | out : list of array-like[N][2] or dictionary List containing the coordinates of the vertices of each polygon, or dictionary with the list of polygons (if `by_spec` is `True`).

  `to_gds`(multiplier)

    Convert this object to a GDSII element.

    Parameters: | multiplier : number A number that multiplies all dimensions written in the GDSII element.
    Returns: | out : string The GDSII binary string that represents this object.

  `translate`(dx, dy)

    Move the reference from one place to another

    Parameters: | dx : float distance to move in the x-direction dy : float distance to move in the y-direction
    Returns: | out : `CellArray` This object.

## Functions

### fast_boolean

`gdspy.` `fast_boolean`(operandA, operandB, operation, precision=0.001, max_points=199, layer=0, datatype=0)

  Execute any boolean operation between 2 polygons or polygon sets.

  Parameters: | operandA : polygon or array-like First operand. Must be a `Polygon`, `PolygonSet`, `CellReference`, `CellArray`, or an array. The array may contain any of the previous objects or an array-like[N][2] of vertices of a polygon. operandB : polygon, array-like or `None` Second operand. Must be `None`, a `Polygon`, `PolygonSet`, `CellReference`, `CellArray`, or an array. The array may contain any of the previous objects or an array-like[N][2] of vertices of a polygon. operation : {‘or’, ‘and’, ‘xor’, ‘not’} Boolean operation to be executed. The ‘not’ operation returns the difference `operandA - operandB`. precision : float Desired precision for rounding vertice coordinates. 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. layer : integer The GDSII layer number for the resulting element. datatype : integer The GDSII datatype for the resulting element (between 0 and 255).
  Returns: | out : PolygonSet or `None` Result of the boolean operation.

### boolean

`gdspy.` `boolean`(polygons, operation, max_points=199, layer=0, datatype=0, eps=1e-13)

  This function is deprecated in favor of ‘fast_boolean’.

  Execute any generalized boolean operation on polygons and polygon sets.

  Parameters: | polygons : 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(polygons)` integers. Each integer represents the incidence of the corresponding `polygon`. 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. layer : integer The GDSII layer number for the resulting element. 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 or `None` 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), 10)
      >>> triangle = gdspy.Round((0, 0), 12, number_of_points=3)
      >>> bad_poly = gdspy.L1Path((0, 0), '+y', 2,
              [6, 4, 4, 8, 4, 5, 10], [-1, -1, -1, 1, 1, 1])
      >>> union = gdspy.boolean([circle, triangle],
              lambda cir, tri: cir or tri)
      >>> intersection = gdspy.boolean([circle, triangle],
              lambda cir, tri: cir and tri)
      >>> subtraction = gdspy.boolean([circle, triangle],
              lambda cir, tri: cir and not tri)
      >>> multi_xor = gdspy.boolean([badPath], lambda p: p % 2)

### offset

`gdspy.` `offset`(polygons, distance, join='miter', tolerance=2, precision=0.001, join_first=False, max_points=199, layer=0, datatype=0)

  Shrink or expand a polygon or polygon set.

  Parameters: | polygons : polygon or array-like Polygons to be offset. Must be a `Polygon`, `PolygonSet`, `CellReference`, `CellArray`, or an array. The array may contain any of the previous objects or an array-like[N][2] of vertices of a polygon. distance : number Offset distance. Positive to expand, negative to shrink. join : {‘miter’, ‘bevel’, ‘round’} Type of join used to create the offset polygon. tolerance : integer or float For miter joints, this number must be at least 2 and it represents the maximun distance in multiples of offset betwen new vertices and their original position before beveling to avoid spikes at acute joints. For round joints, it indicates the curvature resolution in number of points per full circle. precision : float Desired precision for rounding vertice coordinates. join_first : bool Join all paths before offseting to avoid unecessary joins in adjacent polygon sides. 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. layer : integer The GDSII layer number for the resulting element. datatype : integer The GDSII datatype for the resulting element (between 0 and 255).
  Returns: | out : `PolygonSet` or `None` Return the offset shape as a set of polygons.

### slice

`gdspy.` `slice`(objects, position, axis, layer=0, datatype=0)

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

  Parameters: | 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. 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. 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((0, 0), 10, inner_radius = 5)
      >>> result = gdspy.slice(ring, [-7, 7], 0)
      >>> cell.add(result[1])

### inside

`gdspy.` `inside`(points, polygons, short_circuit='any', precision=0.001)

  Test whether each of the points is within the given set of polygons.

  Parameters: | points : array-like[N][2] or list of array-like[N][2] Coordinates of the points to be tested or groups of points to be tested together. polygons : polygon or array-like Polygons to be tested against. Must be a `Polygon`, `PolygonSet`, `CellReference`, `CellArray`, or an array. The array may contain any of the previous objects or an array-like[N][2] of vertices of a polygon. short_circuit : {‘any’, ‘all’} If points is a list of point groups, testing within each group will be short-circuited if any of the points in the group is inside (‘any’) or outside (‘all’) the polygons. If points is simply a list of points, this parameter has no effect. precision : float Desired precision for rounding vertice coordinates.
  Returns: | out : list List of booleans indicating if each of the points or point groups is inside the set of polygons.

### copy

`gdspy.` `copy`(obj, dx, dy)

  Creates a copy of `obj` and translates the new object to a new location.

  Parameters: | obj : `obj` any translatable geometery object. dx : float distance to move in the x-direction dy : float distance to move in the y-direction
  Returns: | out : `obj` Translated copy of original `obj`

  Examples

      >>> rectangle = gdspy.Rectangle((0, 0), (10, 20))
      >>> rectangle2 = gdspy.copy(rectangle, 2,0)
      >>> myCell.add(rectangle)
      >>> myCell.add(rectangle2)