Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
out : `PolygonSet`
This object.
"""
origin = numpy.array(p1)
vec = numpy.array(p2) - origin
vec_r = vec * (2 / numpy.inner(vec, vec))
self.polygons = [
numpy.outer(numpy.inner(points - origin, vec_r), vec) - points + 2 * origin
for points in self.polygons
]
return self
class Polygon(PolygonSet):
"""
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).
Notes
-----
The last point should not be equal to the first (polygons are
automatically closed).
"""
Create a `PolygonSet` representation of this object.
The resulting object will be fractured according to the
parameter `max_points` used when instantiating this object.
Returns
-------
out : `PolygonSet` or None
A `PolygonSet` that contains all boundaries for this path.
If the path is empty, returns None.
"""
if len(self.paths[0]) == 0:
return None
polygons = self.get_polygons(True)
pol = PolygonSet([])
for k, v in polygons.items():
pol.layers.extend([k[0]] * len(v))
pol.datatypes.extend([k[1]] * len(v))
pol.polygons.extend(v)
return pol.fracture(self.max_points, self.precision)
self.polygons[ii][:n1, 0] = numpy.cos(t) * orx + center[0]
self.polygons[ii][:n1, 1] = numpy.sin(t) * ory + center[1]
t = numpy.linspace(iang[ii + 1], iang[ii], n2)
self.polygons[ii][n1:, 0] = numpy.cos(t) * irx + center[0]
self.polygons[ii][n1:, 1] = numpy.sin(t) * iry + center[1]
def __str__(self):
return ("Round ({} polygons, {} vertices, layers {}, datatypes {})").format(
len(self.polygons),
sum([len(p) for p in self.polygons]),
list(set(self.layers)),
list(set(self.datatypes)),
)
class Text(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
Height of the character. The width of a character and the
distance between characters are this value multiplied by 5 / 9
and 8 / 9, respectively. For vertical text, the distance is
multiplied by 11 / 9.
position : array-like[2]
Text position (lower left corner).
Returns
-------
out : `PolygonSet` or None
Return the offset shape as a set of polygons.
"""
result = clipper.offset(
_gather_polys(polygons),
distance,
join,
tolerance,
1 / precision,
1 if join_first else 0,
)
if len(result) == 0:
return None
return PolygonSet(result, layer, datatype).fracture(max_points, precision)
ca = numpy.cos(angle)
sa = numpy.sin(angle) * _mpone
c0 = numpy.array(center)
if isinstance(self.direction, basestring):
self.direction = _directions_dict[self.direction] * numpy.pi
self.direction += angle
cur = numpy.array((self.x, self.y)) - c0
self.x, self.y = cur * ca + cur[::-1] * sa + c0
self.polygons = [
(points - c0) * ca + (points - c0)[:, ::-1] * sa + c0
for points in self.polygons
]
return self
class PolyPath(PolygonSet):
"""
Series of geometric objects that form a polygonal path or a
collection of parallel polygonal paths.
.. deprecated:: 1.4
`PolyPath` is deprecated in favor of FlexPath and will be removed
in a future version of Gdspy.
Parameters
----------
points : array-like[N][2]
Points along the center of the path.
width : number or array-like[N]
Width of the path. If an array is given, width at each
endpoint.
number_of_paths : positive integer
Returns
-------
out : `Cell`
This cell.
"""
if isinstance(element, PolygonSet):
self.polygons.append(element)
elif isinstance(element, RobustPath) or isinstance(element, FlexPath):
self.paths.append(element)
elif isinstance(element, Label):
self.labels.append(element)
elif isinstance(element, CellReference) or isinstance(element, CellArray):
self.references.append(element)
else:
for e in element:
if isinstance(e, PolygonSet):
self.polygons.append(e)
elif isinstance(e, RobustPath) or isinstance(e, FlexPath):
self.paths.append(e)
elif isinstance(e, Label):
self.labels.append(e)
elif isinstance(e, CellReference) or isinstance(e, CellArray):
self.references.append(e)
else:
raise ValueError(
"[GDSPY] Only instances of `PolygonSet`, `FlexPath`, "
"`RobustPath`, `Label`, `CellReference`, and "
"`CellArray` can be added to `Cell`."
)
self._bb_valid = False
return self
if not isinstance(datatype, list):
datatype = [datatype]
if not isinstance(position, list):
pos = [position]
else:
pos = sorted(position)
result = [[] for _ in range(len(pos) + 1)]
scaling = 1 / precision
for pol in polys:
for r, p in zip(result, clipper._chop(pol, pos, axis, scaling)):
r.extend(p)
for i in range(len(result)):
if len(result[i]) == 0:
result[i] = None
else:
result[i] = PolygonSet(
result[i], layer[i % len(layer)], datatype[i % len(datatype)]
)
return result
-------
out : PolygonSet or None
Result of the boolean operation.
"""
poly1 = _gather_polys(operand1)
poly2 = _gather_polys(operand2)
if len(poly2) == 0:
if operation in ["not", "xor"]:
if len(poly1) == 0:
return None
return PolygonSet(poly1, layer, datatype).fracture(max_points, precision)
poly2.append(poly1.pop())
result = clipper.clip(poly1, poly2, operation, 1 / precision)
if len(result) == 0:
return None
return PolygonSet(result, layer, datatype).fracture(max_points, precision)
"""
__slots__ = "layers", "datatypes", "polygons"
def __init__(self, points, layer=0, datatype=0):
self.layers = [layer]
self.datatypes = [datatype]
self.polygons = [numpy.array(points)]
def __str__(self):
return "Polygon ({} vertices, layer {}, datatype {})".format(
len(self.polygons[0]), self.layers[0], self.datatypes[0]
)
class Rectangle(PolygonSet):
"""
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
--------
posX += 8
else:
posY -= 11
self.layers = [layer] * len(self.polygons)
self.datatypes = [datatype] * len(self.polygons)
def __str__(self):
return ("Text ({} polygons, {} vertices, layers {}, datatypes {})").format(
len(self.polygons),
sum([len(p) for p in self.polygons]),
list(set(self.layers)),
list(set(self.datatypes)),
)
class Path(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