# Geometry Construction

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

### 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.
  Variables: | points (numpy array[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).

  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)

  `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 – Area of this object.
    Return type: | number, dictionary

  `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 – If no fracturing occurs, return this object; otherwise return a `PolygonSet` with the fractured result (this object will have more than `max_points` vertices).
    Return type: | `Polygon` or `PolygonSet`

  `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 – Resulting polygons from the fracture operation.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `Polygon`

  `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 – The GDSII binary string that represents this object.
    Return type: | string

  `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 – This object.
    Return type: | `Polygon`

    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)

  `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 – Area of this object.
    Return type: | number, dictionary

  `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 – If no fracturing occurs, return this object; otherwise return a `PolygonSet` with the fractured result (this object will have more than `max_points` vertices).
    Return type: | `Polygon` or `PolygonSet`

  `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 – Resulting polygons from the fracture operation.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `Polygon`

  `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 – The GDSII binary string that represents this object.
    Return type: | string

  `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 – This object.
    Return type: | `Polygon`

    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)

  `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 – Area of this object.
    Return type: | number, dictionary

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – The GDSII binary string that represents this object.
    Return type: | string

  `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 – This object.
    Return type: | `PolygonSet`

### 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 polygon will be suppressed.
  Variables: | polygons (list of numpy array[N][2]) – Coordinates of the vertices of each polygon. layers (list of integer) – The GDSII layer number for each element. datatypes (list of integer) – The GDSII datatype for each element (between 0 and 255).

  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.

  `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 – Area of this object.
    Return type: | number, dictionary

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – The GDSII binary string that represents this object.
    Return type: | string

  `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 – This object.
    Return type: | `PolygonSet`

### 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.
  Variables: | 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.

  `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 – This object.
    Return type: | `Path`

    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 – Area of this object.
    Return type: | number, dictionary

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `Path`

    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 – This object.
    Return type: | `Path`

  `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 – This object.
    Return type: | `Path`

  `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 – The GDSII binary string that represents this object.
    Return type: | string

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `Path`

    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 – This object.
  Return type: | `PolyPath`

  Notes

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

  `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 – Area of this object.
    Return type: | number, dictionary

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – The GDSII binary string that represents this object.
    Return type: | string

  `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 – This object.
    Return type: | `PolygonSet`

### 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 – This object.
  Return type: | `L1Path`
  Variables: | 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.

  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)

  `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 – Area of this object.
    Return type: | number, dictionary

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `L1Path`

  `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 – The GDSII binary string that represents this object.
    Return type: | string

  `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 – This object.
    Return type: | `PolygonSet`

### 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)

  `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 – Area of this object.
    Return type: | number, dictionary

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – This object.
    Return type: | `PolygonSet`

  `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 – The GDSII binary string that represents this object.
    Return type: | string

  `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 – This object.
    Return type: | `PolygonSet`

### Label

class `gdspy.``Label`(text, position, anchor='o', rotation=None, magnification=None, x_reflection=False, layer=0, texttype=0)

  Bases: `object`

  Text that can be used to label parts of the geometry or display messages. The text does not create additional geometry, it’s meant for display and labeling purposes only.

  Parameters: | text (string) – The text of this label. position (array-like[2]) – Text anchor position. anchor ('n', 's', 'e', 'w', 'o', 'ne', 'nw'...) – Position of the anchor relative to the text. rotation (number) – Angle of rotation of the label (in degrees). magnification (number) – Magnification factor for the label. x_reflection (bool) – If `True`, the label is reflected parallel to the x direction before being rotated (not supported by LayoutViewer). layer (integer) – The GDSII layer number for these elements. texttype (integer) – The GDSII text type for the label (between 0 and 63).
  Variables: | text (string) – The text of this label. position (array-like[2]) – Text anchor position. anchor (int) – Position of the anchor relative to the text. rotation (number) – Angle of rotation of the label (in degrees). magnification (number) – Magnification factor for the label. x_reflection (bool) – If `True`, the label is reflected parallel to the x direction before being rotated (not supported by LayoutViewer). layer (integer) – The GDSII layer number for these elements. texttype (integer) – The GDSII text type for the label (between 0 and 63).

  Examples

      >>> label = gdspy.Label('Sample label', (10, 0), 'sw')
      >>> myCell.add(label)

  `to_gds`(multiplier)

    Convert this label to a GDSII structure.

    Parameters: | multiplier (number) – A number that multiplies all dimensions written in the GDSII structure.
    Returns: | out – The GDSII binary string that represents this label.
    Return type: | string

  `translate`(dx, dy)

    Move the text 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 – This object.
    Return type: | `Label`

    Examples

        >>> text = gdspy.Label((0, 0), (10, 20))
        >>> text = text.translate(2, 0)
        >>> myCell.add(text)

## 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 – Result of the boolean operation.
  Return type: | PolygonSet or `None`

### 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 – Result of the boolean operation.
  Return type: | PolygonSet or `None`

  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 – Return the offset shape as a set of polygons.
  Return type: | `PolygonSet` or `None`

### 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 – Result of the slicing operation, with N = len(positions) + 1. Each PolygonSet comprises all polygons between 2 adjacent slicing positions, in crescent order.
  Return type: | list[N] of PolygonSet

  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 – Tuple of booleans indicating if each of the points or point groups is inside the set of polygons.
  Return type: | tuple

### 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 – Translated copy of original `obj`
  Return type: | `obj`

  Examples

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