def offset_copy(trans, fig=None, x=0, y=0, units='inches'): ''' Return a shallow copy of a transform with an added offset. args: trans is any transform kwargs: fig is the current figure; it can be None if units are 'dots' x, y give the offset units is 'inches', 'points' or 'dots' ''' newtrans = trans.shallowcopy() if units == 'dots': newtrans.set_offset((x, y), identity_transform()) return newtrans if fig is None: raise ValueError('For units of inches or points a fig kwarg is needed') if units == 'points': x /= 72.0 y /= 72.0 elif not units == 'inches': raise ValueError('units must be dots, points, or inches') tx = Value(x) * fig.dpi ty = Value(y) * fig.dpi newtrans.set_offset((0, 0), translation_transform(tx, ty)) return newtrans
def bbox_all(bboxes): """ Return the Bbox that bounds all bboxes """ # this is a good candidate to move to _transforms assert (len(bboxes)) if len(bboxes) == 1: return bboxes[0] bbox = bboxes[0] minx = bbox.xmin() miny = bbox.ymin() maxx = bbox.xmax() maxy = bbox.ymax() for bbox in bboxes[1:]: thisminx = bbox.xmin() thisminy = bbox.ymin() thismaxx = bbox.xmax() thismaxy = bbox.ymax() if thisminx < minx: minx = thisminx if thismaxx > maxx: maxx = thismaxx if thisminy < miny: miny = thisminy if thismaxy > maxy: maxy = thismaxy return Bbox(Point(Value(minx), Value(miny)), Point(Value(maxx), Value(maxy)))
def inverse_transform_bbox(trans, bbox): 'inverse transform the bbox' xmin, xmax = bbox.intervalx().get_bounds() ymin, ymax = bbox.intervaly().get_bounds() xmin, ymin = trans.inverse_xy_tup((xmin, ymin)) xmax, ymax = trans.inverse_xy_tup((xmax, ymax)) return Bbox(Point(Value(xmin), Value(ymin)), Point(Value(xmax), Value(ymax)))
def lbwh_to_bbox(l, b, w, h): return Bbox(Point(Value(l), Value(b)), Point(Value(l + w), Value(b + h)))
def one(): return Value(1)
def zero(): return Value(0)