Beispiel #1
0
    def move(self, midpoint=(0, 0), destination=None, axis=None):
        """ Moves the polygon from `midpoint` to a `destination`. """
        from spira.yevon.geometry.ports import Port

        if destination is None:
            destination = midpoint
            midpoint = Coord(0, 0)

        if isinstance(midpoint, Coord):
            m = midpoint
        elif np.array(midpoint).size == 2:
            m = Coord(midpoint)
        # elif issubclass(type(midpoint), __Port__):
        elif isinstance(midpoint, Port):
            m = midpoint.midpoint
        else:
            raise ValueError('Midpoint error')

        # if issubclass(type(destination), __Port__):
        if isinstance(destination, Port):
            d = destination.midpoint
        if isinstance(destination, Coord):
            d = destination
        elif np.array(destination).size == 2:
            d = Coord(destination)
        else:
            raise ValueError('Destination error')

        dxdy = d - m
        self.translate(dxdy)
        return self
Beispiel #2
0
 def __sub__(self, other):
     """
     >>> midpoint = self.jj1.ports['P2'] - [-5, 0]
     """
     if other is None: return self
     p1 = Coord(self.midpoint[0], self.midpoint[1]) - Coord(
         other[0], other[1])
     return p1
Beispiel #3
0
 def set_rotation_center(self, rotation_center):
     if not isinstance(rotation_center, Coord):
         rotation_center = Coord(rotation_center[0], rotation_center[1])
     self.__rotation_center__ = rotation_center
     if hasattr(self, '__ca__'):
         self.translation = Coord(
             rotation_center.x * (1 - self.__ca__) +
             rotation_center.y * self.__sa__,
             -rotation_center.x * self.__sa__ + rotation_center.y *
             (1 - self.__ca__))
Beispiel #4
0
 def create_t3(self):
     cell = spira.Cell()
     tf_1 = spira.Translation(Coord(12.5, 2.5)) + spira.Rotation(60)
     tf_2 = spira.Translation(Coord(
         12.5, 2.5)) + spira.Rotation(60) + spira.Reflection(True)
     cell += spira.Rectangle(p1=(0, 0),
                             p2=(10, 50),
                             layer=spira.Layer(number=4))
     S1 = spira.SRef(cell, transformation=tf_1)
     S2 = spira.SRef(cell, transformation=tf_2)
     return [S1, S2]
Beispiel #5
0
 def __eq__(self, other):
     if isinstance(other, str):
         return (self.name == other)
     else:
         if not isinstance(self.midpoint, Coord):
             self.midpoint = Coord(self.midpoint[0], self.midpoint[1])
         if not isinstance(other.midpoint, Coord):
             other.midpoint = Coord(other.midpoint[0], other.midpoint[1])
         return ((self.name == other.name)
                 and (self.midpoint == other.midpoint)
                 and (self.orientation == other.orientation))
Beispiel #6
0
    def move(self, midpoint=(0, 0), destination=None, axis=None):
        """  """
        from spira.yevon.geometry.ports.base import __Port__

        if destination is None:
            destination = midpoint
            midpoint = [0, 0]

        if issubclass(type(midpoint), __Port__):
            o = midpoint.midpoint
        elif isinstance(midpoint, Coord):
            o = midpoint
        elif np.array(midpoint).size == 2:
            o = midpoint
        elif midpoint in obj.ports:
            o = obj.ports[midpoint].midpoint
        else:
            raise ValueError("[PHIDL] [DeviceReference.move()] ``midpoint`` " +
                             "not array-like, a port, or port name")

        if issubclass(type(destination), __Port__):
            d = destination.midpoint
        elif isinstance(destination, Coord):
            d = destination
        elif np.array(destination).size == 2:
            d = destination
        elif destination in obj.ports:
            d = obj.ports[destination].midpoint
        else:
            raise ValueError(
                "[PHIDL] [DeviceReference.move()] ``destination`` " +
                "not array-like, a port, or port name")

        if axis == 'x':
            d = (d[0], o[1])
        if axis == 'y':
            d = (o[0], d[1])

        d = Coord(d[0], d[1])
        o = Coord(o[0], o[1])

        for e in self.elements:
            e.move(midpoint=o, destination=d)

        for p in self.ports:
            # mc = np.array(p.midpoint) + np.array(d) - np.array(o)
            mc = np.array([p.midpoint[0], p.midpoint[1]]) + np.array(
                [d[0], d[1]]) - np.array([o[0], o[1]])
            # p.move(midpoint=p.midpoint, destination=mc)
            # print(p)
            p.move(mc)

        return self
Beispiel #7
0
    def create_t1(self):
        cell = spira.Cell()
        cell += spira.Rectangle(p1=(0, 0),
                                p2=(10, 50),
                                layer=spira.Layer(number=2))

        S1 = spira.SRef(cell)
        S1.rotate(rotation=45)
        S1.translate(Coord(15, 15))

        S = spira.SRef(cell)
        S.rotate(rotation=45)
        S.translate(Coord(15, 15))
        S.reflect(True)

        return [S1, S]
Beispiel #8
0
    def create_points(self, points):

        if self.clip_shape.is_empty() is False:
            new_points = []
            for i, s in enumerate(self.original_shape.segments()):
                s1_inter = []
                new_points += [s[0]]
                for c in self.clip_shape.points:
                    if c not in self.original_shape:
                        segment_line = line_from_two_points(s[0], s[1])
                        if segment_line.is_on_line(coordinate=c):
                            s1_inter.append(c)

                if len(s1_inter) > 0:
                    line = np.concatenate((s, s1_inter))
                    pl = sort_points_on_line(line)
                    new_points += pl[0:-1]

            points = [Coord(p[0], p[1]) for p in new_points]
            points = points_unique(points)
            points = [c.to_list() for c in points]
        else:
            points = self.original_shape.points

        return points
Beispiel #9
0
 def set_rotation(self, value):
     self.__rotation__ = value % 360.0
     if value % 90.0 == 0.0:
         if self.__rotation__ == 0.0:
             self.__ca__ = 1.0
             self.__sa__ = 0.0
         elif self.__rotation__ == 90.0:
             self.__ca__ = 0.0
             self.__sa__ = 1.0
         elif self.__rotation__ == 180.0:
             self.__ca__ = -1.0
             self.__sa__ = 0.0
         elif self.__rotation__ == 270.0:
             self.__ca__ = 0.0
             self.__sa__ = -1.
     else:
         self.__ca__ = np.cos(value * constants.DEG2RAD)
         self.__sa__ = np.sin(value * constants.DEG2RAD)
     if hasattr(self, '__rotation_center__'):
         rotation_center = self.__rotation_center__
         self.translation = Coord(
             rotation_center.x * (1 - self.__ca__) +
             rotation_center.y * self.__sa__,
             rotation_center.y * (1 - self.__ca__) -
             rotation_center.x * self.__sa__)
Beispiel #10
0
 def create_t2(self):
     tf = spira.GenericTransform(translation=Coord(-22, 0))
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=3),
                           transformation=tf)
     return ply
Beispiel #11
0
    def create_points(self, points):

        if len(self.overlapping_shape) == 0:
            points = self.original_shape.points
        else:
            new_points = []
            for i, s in enumerate(self.original_shape.segments()):
                s1_inter = []
                new_points += [s[0]]
                for c in self.overlapping_shape.points:
                    if c not in self.original_shape:
                        # print(c)
                        segment_line = line_from_two_points(s[0], s[1])
                        if segment_line.is_on_line(coordinate=c):
                            # print('jkfbjwkebkwefb')
                            s1_inter.append(c)

                if len(s1_inter) > 0:
                    line = np.concatenate((s, s1_inter))
                    pl = sort_points_on_line(line)
                    new_points += pl[0:-1]
                # new_points += [s[1]]

            points = new_points
            points = [Coord(p[0], p[1]) for p in points]
            points = points_unique(points)
            points = [c.to_list() for c in points]

            # if len(points) > 0:
            #     print(points)
            #     print(len(self.overlapping_shape.points), len(points))
            #     print('')

        return points
Beispiel #12
0
 def create_t1(self):
     T = spira.Translation(Coord(-10, 0))
     ply = spira.Rectangle(p1=(0, 0),
                           p2=(10, 50),
                           layer=spira.Layer(number=2))
     ply.transform(T)
     return ply
Beispiel #13
0
 def create_t2(self):
     cell = spira.Cell()
     cell += spira.Rectangle(p1=(0, 0),
                             p2=(10, 50),
                             layer=spira.Layer(number=3))
     T = spira.GenericTransform(translation=Coord(22, 0))
     S = spira.SRef(cell, transformation=T)
     return S
Beispiel #14
0
def EdgeSymmetric(width=1, extend=1, process=None, transformation=None):
    """  """
    layer = PLayer(process=process,
                   purpose=RDD.PURPOSE.PORT.INSIDE_EDGE_DISABLED)
    shape = shapes.BoxShape(width=width,
                            height=2 * extend,
                            center=Coord(0, extend / 4))
    return Edge(shape=shape, layer=layer, transformation=transformation)
Beispiel #15
0
def snap_coordinate(coordinate, grids_per_unit=None):
    """ Round a coordinate to a grid value. """
    from spira.yevon.geometry.coord import Coord
    if grids_per_unit is None:
        grids_per_unit = get_grids_per_unit()
    x = floor(coordinate[0] * grids_per_unit + 0.5) / (grids_per_unit)
    y = floor(coordinate[1] * grids_per_unit + 0.5) / (grids_per_unit)
    return Coord(x, y)
Beispiel #16
0
def sort_points_on_line(point_list):
    """ Sorts points on a line, taking the two first points as the reference direction """
    point_list = [Coord(p[0], p[1]) for p in point_list]
    p0 = point_list[0]
    dx = point_list[1][0] - point_list[0][0]
    dy = point_list[1][1] - point_list[0][1]
    point_list.sort(key=lambda p: distance(p, p0))
    return point_list
Beispiel #17
0
 def create_t1(self):
     cell = spira.Cell()
     cell += spira.Rectangle(p1=(0, 0),
                             p2=(10, 50),
                             layer=spira.Layer(number=2))
     T = spira.Translation(Coord(10, 0))
     S = spira.SRef(cell, transformation=T)
     return S
Beispiel #18
0
 def intersection(self, line):
     """ gives intersection of line with other line """
     if (self.b * line.a - self.a * line.b) == 0.0: return None
     x = -(self.b * line.c - line.b * self.c) / (self.b * line.a -
                                                 self.a * line.b)
     y = (self.a * line.c - line.a * self.c) / (self.b * line.a -
                                                self.a * line.b)
     return Coord(x, y)
Beispiel #19
0
 def set_stretch_factor(self, value):
     if isinstance(value, Coord):
         self.__stretch_factor__ = value
     else:
         self.__stretch_factor__ = Coord(value[0], value[1])
     if self.__stretch_factor__[0] == 0.0 or self.__stretch_factor__[
             1] == 0.0:
         raise ValueError(
             "Error: Stretch factor cannot be zero in Stretch transform")
Beispiel #20
0
 def get_corner2(self):
     port_position = self.midpoint
     port_angle = (self.orientation - 90) * constants.DEG2RAD
     wg_width = self.width
     port_corner2_x = port_position[0] + (
         wg_width / 2.0) * np.cos(port_angle + np.pi / 2.0)
     port_corner2_y = port_position[1] + (
         wg_width / 2.0) * np.sin(port_angle + np.pi / 2.0)
     return Coord(port_corner2_x, port_corner2_y)
Beispiel #21
0
    def create_elements(self, elems):

        layer = PLayer(process=self.process,
                       purpose=RDD.PURPOSE.PORT.INSIDE_EDGE_DISABLED)
        elems += Box(alias='InsideEdge',
                     width=self.width,
                     height=self.inward_extend,
                     center=Coord(0, self.inward_extend / 2),
                     layer=layer)

        layer = PLayer(process=self.process,
                       purpose=RDD.PURPOSE.PORT.OUTSIDE_EDGE_DISABLED)
        elems += Box(alias='OutsideEdge',
                     width=self.width,
                     height=self.outward_extend,
                     center=Coord(0, -self.outward_extend / 2),
                     layer=layer)

        return elems
Beispiel #22
0
 def __add__(self, other):
     """ Returns the concatenation of this transform and other """
     if other is None:
         return deepcopy(self)
     if isinstance(other, Translation):
         x = self.translation.x + other.translation.x
         y = self.translation.y + other.translation.y
         return Translation(Coord(x, y))
     else:
         # return GenericTransform.__add__(self, other)
         return __ConvertableTransform__.__add__(self, other)
Beispiel #23
0
 def create_t2(self):
     cell = spira.Cell()
     tf_1 = spira.GenericTransform(translation=(10, 10), rotation=45)
     tf_2 = spira.GenericTransform(translation=Coord(10, 10),
                                   rotation=45,
                                   reflection=True)
     cell += spira.Rectangle(p1=(0, 0),
                             p2=(10, 50),
                             layer=spira.Layer(number=3))
     S1 = spira.SRef(cell, transformation=tf_1)
     S2 = spira.SRef(cell, transformation=tf_2)
     return [S1, S2]
Beispiel #24
0
 def __iadd__(self, other):
     """ Concatenates other to this transform. """
     if other is None:
         return self
     if isinstance(other, Translation):
         x = self.translation.x + other.translation.x
         y = self.translation.y + other.translation.y
         self.translation = Coord(x, y)
         return self
     else:
         # return GenericTransform.__iadd__(self, other)
         return __ConvertableTransform__.__iadd__(self, other)
Beispiel #25
0
 def _add_positions(self, n, triangle):
     from spira import settings
     pp = self.mesh_data.points
     grids_per_unit = settings.get_grids_per_unit()
     n1, n2, n3 = pp[triangle[0]], pp[triangle[1]], pp[triangle[2]]
     x = (n1[0] + n2[0] + n3[0]) / 3
     y = (n1[1] + n2[1] + n3[1]) / 3
     x = x * grids_per_unit
     y = y * grids_per_unit
     self.g.node[n]['vertex'] = triangle
     self.g.node[n]['position'] = Coord(x, y)
     self.g.node[n]['display'] = RDD.DISPLAY.STYLE_SET[RDD.PLAYER.METAL]
Beispiel #26
0
 def __get_2_points__(self):
     from spira.yevon.geometry import shapes
     if b == 0:
         return shapes.Shape([Coord(-self.c / self.a, 0.0), Coord(-self.c / self.a, 1.0)])
     elif a == 0: 
         return shapes.Shape([Coord(0.0, -self.c / self.b), Coord(1.0, -self.c / self.b)])
     else:
         return shapes.Shape([Coord(-self.c / self.a, 0.0), Coord(0.0, -self.c / self.b)])
Beispiel #27
0
def intersection(begin1, end1, begin2, end2):
    """ Gives the intersection between two lines (not sections). """
    A1 = end1[1] - begin1[1]
    B1 = -end1[0] + begin1[0]
    C1 = begin1[1] * B1 + begin1[0] * A1
    A2 = end2[1] - begin2[1]
    B2 = -end2[0] + begin2[0]
    C2 = begin2[1] * B2 + begin2[0] * A2
    if A1 * B2 == A2 * B1:
        LOG.error("Can't intersect parallel lines")
        raise ValueError('Cannot be parallel.')
    x = (C1 * B2 - C2 * B1) / (A1 * B2 - A2 * B1)
    y = (C1 * A2 - C2 * A1) / (B1 * A2 - B2 * A1)
    return Coord(x, y)
Beispiel #28
0
 def __reflect__(self, coords, p1=(0, 0), p2=(1, 0)):
     if self.reflection is True:
         points = np.array(coords.to_numpy_array())
         p1 = np.array(p1)
         p2 = np.array(p2)
         if np.asarray(points).ndim == 1:
             t = np.dot((p2 - p1), (points - p1)) / norm(p2 - p1)**2
             pts = 2 * (p1 + (p2 - p1) * t) - points
         if np.asarray(points).ndim == 2:
             raise ValueError('This is a array, not an coordinate.')
     else:
         pts = coords
     pts = Coord(pts[0], pts[1])
     return pts
Beispiel #29
0
    def move(self, midpoint=(0, 0), destination=None, axis=None):
        """ Move the reference internal port to the destination.

        Example:
        --------
        >>> S.move()
        """

        if destination is None:
            destination = midpoint
            midpoint = [0, 0]

        if isinstance(midpoint, Coord):
            o = midpoint
        elif np.array(midpoint).size == 2:
            o = midpoint
        elif midpoint in self.ports.get_names():
            o = self.ports[midpoint.name].midpoint
        elif issubclass(type(midpoint), __Port__):
            o = midpoint.midpoint
        else:
            raise ValueError("[PHIDL] [DeviceReference.move()] ``midpoint`` " +
                             "not array-like, a port, or port name")

        if issubclass(type(destination), __Port__):
            d = destination.midpoint
        elif isinstance(destination, Coord):
            d = destination
        elif np.array(destination).size == 2:
            d = destination
        elif destination in self.ports.get_names():
            d = self.ports[destination.name].midpoint
        else:
            raise ValueError(
                "[PHIDL] [DeviceReference.move()] ``destination`` " +
                "not array-like, a port, or port name")

        position = np.array([d[0], d[1]]) - np.array([o[0], o[1]])
        self.midpoint = Coord(self.midpoint[0] + position[0],
                              self.midpoint[1] + position[1])
        # dxdy = Coord(self.midpoint[0] + position[0], self.midpoint[1] + position[1])
        # self.translate(dxdy)
        return self
Beispiel #30
0
    def __iadd__(self, other):

        # return self.__add__(other)

        if other is None:
            return self

        # if issubclass(type(other), GenericTransform):
        if isinstance(other, GenericTransform):
            T = GenericTransform()

            if other.reflection is True: s_1 = -1
            else: s_1 = 1

            M1 = 1.0

            if not self.absolute_rotation:
                self.rotation = s_1 * self.rotation + other.rotation
                ca = other.__ca__
                sa = other.__sa__
            else:
                self.rotation = s_1 * self.rotation
                ca = 1
                sa = 0

            # Counterclockwise rotation
            # cx = self.translation.x + ca * other.translation.x * M1 - s_1 * sa * other.translation.y * M1
            # cy = self.translation.y + sa * other.translation.x * M1 + s_1 * ca * other.translation.y * M1
            cx = other.translation.x + ca * self.translation.x * M1 - s_1 * sa * self.translation.y * M1
            cy = other.translation.y + sa * self.translation.x * M1 + s_1 * ca * self.translation.y * M1
            # cx = other.translation.x + ca * self.translation.x * M1 + s_1 * sa * self.translation.y * M1
            # cy = -other.translation.y + sa * self.translation.x * M1 + s_1 * ca * self.translation.y * M1
            self.translation = Coord(cx, cy)

            self.absolute_rotation = self.absolute_rotation or other.absolute_rotation
            self.reflection = (not self.reflection == other.reflection)

        else:
            raise ValueError('Cannot add transforms')

        return self