def __init__(self, points, data, vt=(0, 0, 1, 1), clean_nan=False): if clean_nan: mask = ~np.isnan(points).any(axis=1) points = points[mask] data = data[mask] self._points = points self._data = data self.vt = vt self.shaper = glyphset.ToPoint(glyphset.idx(0), glyphset.idx(1)) if not is_identity_transform(vt): self.projected = np.empty_like(points, dtype=np.int32) _projectRects(vt, points, self.projected) # points must be at least 1 wide for general compatability self.projected[:, 2] = self.projected[:, 0] + 1 self.projected[:, 3] = self.projected[:, 1] + 1 else: self.projected = points
def __init__(self, points, data, vt=(0, 0, 1, 1), clean_nan=False): if clean_nan: mask = ~np.isnan(points).any(axis=1) points = points[mask] data = data[mask] self._points = points self._data = data self.vt = vt self.shaper = glyphset.ToPoint(glyphset.idx(0), glyphset.idx(1)) if not is_identity_transform(vt): self.projected = np.empty_like(points, dtype=np.int32) _projectRects(vt, points, self.projected) # points must be at least 1 wide for general compatability self.projected[:, 2] = self.projected[:, 0]+1 self.projected[:, 3] = self.projected[:, 1]+1 else: self.projected = points
def project(self, viewxform): """Project the points found in the glyphset according to the view transform. viewxform -- convert canvas space to pixel space [tx,ty,sx,sy] returns a new glyphset with projected points and associated info values """ points = self.points() out = np.empty_like(points, dtype=np.int32) _projectRects(viewxform, points, out) # Ensure visilibity, make sure w/h are always at least one # TODO: There is probably a more numpy-ish way to do this... for i in xrange(0, out.shape[0]): if out[i, 0] == out[i, 2]: out[i, 2] += 1 if out[i, 1] == out[i, 3]: out[i, 3] += 1 return Glyphset(out, self.data(), Literals(self.shaper.code))