Ejemplo n.º 1
0
 def snap_to_grid(self, grids_per_unit=None):
     """ Snaps all shape points to grid. """
     from spira.settings import get_grids_per_unit
     if grids_per_unit is None:
         grids_per_unit = get_grids_per_unit()
     self.points = (np.floor(self.points * grids_per_unit + 0.5)) / grids_per_unit 
     return self
Ejemplo n.º 2
0
 def snap_to_grid(self, grids_per_unit=None):
     """ Snap the coordinate to the given or current grid. """
     from spira import settings
     if grids_per_unit is None:
         grids_per_unit = settings.get_grids_per_unit()
     self.x = math.floor(self.x * grids_per_unit + 0.5) / grids_per_unit
     self.y = math.floor(self.y * grids_per_unit + 0.5) / grids_per_unit
     return self
Ejemplo n.º 3
0
 def remove_identicals(self):
     """ Removes consecutive identical points """
     from spira import settings
     pts = self.points
     if len(pts) > 1:
         identicals = np.prod(abs(pts - np.roll(self.points, -1, 0)) < 0.5 / settings.get_grids_per_unit(), 1)
         if not self.is_closed:
             identicals[-1] = False
         self.points = np.delete(pts, identicals.nonzero()[0], 0)
     return self
Ejemplo n.º 4
0
 def snap_to_grid(self, grids_per_unit=None):
     """ Snaps the boundary box to a given grid or the current grid. """
     from spira import settings
     if not self.__is_initialized__(): return self
     if grids_per_unit is None:
         grids_per_unit = settings.get_grids_per_unit()
     self.__west = settings.snap_value(self.__west, grids_per_unit)
     self.__east = settings.snap_value(self.__east, grids_per_unit)
     self.__north = settings.snap_value(self.__north, grids_per_unit)
     self.__south = settings.snap_value(self.__south, grids_per_unit)
     return self
Ejemplo n.º 5
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]
Ejemplo n.º 6
0
 def remove_identicals(self):
     """ Removes consecutive identical points """
     # FIXME: in some cases a series of many points close together
     # is removed, even if they form together a valid shape.
     from spira import settings
     pts = self.points
     if len(pts) > 1:
         identicals = np.prod(
             abs(pts - np.roll(self.points, -1, 0)) <
             0.5 / settings.get_grids_per_unit(), 1)
         if not self.is_closed:
             identicals[-1] = False
         self.points = np.delete(pts, identicals.nonzero()[0], 0)
     return self
Ejemplo n.º 7
0
def c2d(coord):
    """ Convert coordinate to 2D. """
    from spira import settings
    grids_per_unit = settings.get_grids_per_unit()
    pp = [coord[i] * grids_per_unit for i in range(len(list(coord)) - 1)]
    return pp