How to use the gdspy.PolygonSet function in gdspy

To help you get started, we’ve selected a few gdspy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heitzmann / gdspy / tests / functions.py View on Github external
def test_copy():
    p = gdspy.Rectangle((0, 0), (1, 1))
    q = gdspy.copy(p, 1, -1)
    assert set(p.polygons[0][:, 0]) == {0, 1}
    assert set(p.polygons[0][:, 1]) == {0, 1}
    assert set(q.polygons[0][:, 0]) == {1, 2}
    assert set(q.polygons[0][:, 1]) == {-1, 0}
    p = gdspy.PolygonSet([[(0, 0), (1, 0), (0, 1)], [(2, 2), (3, 2), (2, 3)]])
    q = gdspy.copy(p, 1, -1)
    assert set(p.polygons[0][:, 0]) == {0, 1}
    assert set(p.polygons[0][:, 1]) == {0, 1}
    assert set(q.polygons[0][:, 0]) == {1, 2}
    assert set(q.polygons[0][:, 1]) == {-1, 0}
    assert set(p.polygons[1][:, 0]) == {2, 3}
    assert set(p.polygons[1][:, 1]) == {2, 3}
    assert set(q.polygons[1][:, 0]) == {3, 4}
    assert set(q.polygons[1][:, 1]) == {1, 2}
    l = gdspy.Label("text", (0, 1))
    m = gdspy.copy(l, -1, 1)
    assert l.position[0] == 0 and l.position[1] == 1
    assert m.position[0] == -1 and m.position[1] == 2
    c = gdspy.CellReference("empty", (0, 1), ignore_missing=True)
    d = gdspy.copy(c, -1, 1)
    assert c.origin == (0, 1)
github heitzmann / gdspy / tests / polygonset.py View on Github external
def test_rotation():
    ps = gdspy.PolygonSet([[(0, 0), (1, 0), (1, 2), (0, 2)]])
    ps.rotate(-numpy.pi / 6, center=(1, 0))
    x = 3 ** 0.5 / 2
    a = numpy.arctan(2) + numpy.pi / 6
    l = 5 ** 0.5
    tgt = gdspy.PolygonSet(
        [[(1 - x, 0.5), (1, 0), (2, 2 * x), (1 - l * numpy.cos(a), l * numpy.sin(a))]]
    )
    assertsame(gdspy.Cell("test", True).add(ps), gdspy.Cell("TGT", True).add(tgt))
github heitzmann / gdspy / tools / maketestgds.py View on Github external
cell = lib.new_cell("PolygonSet")

p = gdspy.PolygonSet(
    [
        [(10, 0), (11, 0), (10, 1)],
        [(11, 0), (10, 1), (11, 1)],
        [(11, 1), (12, 1), (11, 2)],
    ],
    1,
    2,
)
cell.add(p)

cell = lib.new_cell("PolygonSet_fillet")

orig = gdspy.PolygonSet(
    [
        [
            (0, 0),
            (-1, 0),
            (0, -1),
            (0.5, -0.5),
            (1, 0),
            (1, 1),
            (4, -1),
            (1, 3),
            (1, 2),
            (0, 1),
        ],
        [(2, -1), (3, -1), (2.5, -2)],
    ]
)
github hohlraum / gdsCAD / gdspy.py View on Github external
>>> myCell.add(rectangle)
	"""
	
	def __init__(self, layer, point1, point2, datatype=0):
		self.layer = layer
		self.points = numpy.array([[point1[0], point1[1]], [point1[0], point2[1]], [point2[0], point2[1]], [point2[0], point1[1]]])
		self.datatype = datatype

	def __str__(self):
		return "Rectangle (({0[0]}, {0[1]}) to ({1[0]}, {1[1]}), layer {2}, datatype {3})".format(self.points[0], self.points[2], self.layer, self.datatype)

	def __repr__(self):
		return "Rectangle({2}, ({0[0]}, {0[1]}), ({1[0]}, {1[1]}), {3})".format(self.points[0], self.points[2], self.layer, self.datatype)


class Round(PolygonSet):
	"""
	Circular geometric object.
	Represent a circle, a circular section, a ring or a ring section.

	Parameters
	----------
	layer : integer
		The GDSII layer number for this element.
	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*).
github stanfordnqp / spins-b / examples / grating_coupler / grating.py View on Github external
if plan.transformations[-1].parametrization.inverted:
            coords = np.insert(coords, 0, 0, axis=0)
            coords = np.insert(coords, -1, grating_len, axis=0)

    # `coords` now contains the location of the grating edges. Now draw a
    # series of rectangles to represent the grating.
    grating_poly = []
    for i in range(0, len(coords), 2):
        grating_poly.append(
            ((coords[i], -wg_width / 2), (coords[i], wg_width / 2),
             (coords[i + 1], wg_width / 2), (coords[i + 1], -wg_width / 2)))

    # Save the grating to `grating.gds`.
    grating = gdspy.Cell("GRATING", exclude_from_current=True)
    grating.add(gdspy.PolygonSet(grating_poly, 100))
    gdspy.write_gds(os.path.join(save_folder, "grating.gds"), [grating],
                    unit=1.0e-9,
                    precision=1.0e-9)
github BerkeleyPhotonicsGenerator / BPG / BPG / compiler / dataprep_gdspy.py View on Github external
The Manhattanization grid size
        do_manh : bool
            True to perform Manhattanization

        Returns
        -------
        polygon_out : Union[gdspy.Polygon, gdspy.PolygonSet]
            The gdpsy.Polygon formatted polygons
        """
        pos_coord_list_list = pos_neg_list_list[0]
        neg_coord_list_list = pos_neg_list_list[1]

        polygon_out = self.dataprep_cleanup_gdspy(gdspy.PolygonSet(pos_coord_list_list),
                                                  do_cleanup=self.do_cleanup)
        if len(neg_coord_list_list):
            polygon_neg = self.dataprep_cleanup_gdspy(gdspy.PolygonSet(neg_coord_list_list),
                                                      do_cleanup=self.do_cleanup)
            polygon_out = self.dataprep_cleanup_gdspy(
                gdspy.fast_boolean(polygon_out, polygon_neg, 'not',
                                   precision=self.global_operation_precision,
                                   max_points=MAX_SIZE),
                do_cleanup=self.do_cleanup
            )

        polygon_out = self.gdspy_manh(polygon_out, manh_grid_size=manh_grid_size, do_manh=do_manh)

        # TODO: is the cleanup necessary
        # Offset by 0 to clean up shape
        polygon_out = self.dataprep_cleanup_gdspy(
            polygon_out,
            do_cleanup=self.do_cleanup
        )
github hohlraum / gdsCAD / gdspy.py View on Github external
indicated by this number.

		Returns
		-------
		out : ``Cell``
			This cell.
		"""
		if single_layer is None:
			poly_dic = self.get_polygons(True)
			self.elements = []
			for layer in poly_dic.iterkeys():
				self.add(PolygonSet(layer, poly_dic[layer]))
		else:
			polygons = self.get_polygons()
			self.elements = []
			self.add(PolygonSet(single_layer, polygons))
		return self
github hohlraum / gdsCAD / gdspy.py View on Github external
elif isinstance(obj, PolygonSet):
			polygons += obj.polygons
		elif isinstance(obj, CellReference) or isinstance(obj, CellArray):
			polygons += obj.get_polygons()
		else:
			polygons.append(obj)
	for i, p in enumerate(position):
		nxt_polygons = []
		for pol in polygons:
			(pol1, pol2) = chop(pol, p, axis)
			result[i] += pol1
			nxt_polygons += pol2
		polygons = nxt_polygons
	result[-1] = polygons
	for i in range(len(result)):
		result[i] = PolygonSet(layer[i % len(layer)], result[i], datatype)
	return result