def blend_xy_sep_transform(trans1, trans2): """ If trans1 and trans2 are SeparableTransformation instances, you can build a new SeparableTransformation from them by extracting the x and y bounding points and functions and recomposing a new SeparableTransformation This function extracts all the relevant bits from trans1 and trans2 and returns the new Transformation instance. This is useful, for example, if you want to specify x in data coordinates and y in axes coordinates. """ inboxx = trans1.get_bbox1() inboxy = trans2.get_bbox1() outboxx = trans1.get_bbox2() outboxy = trans2.get_bbox2() xminIn = inboxx.ll().x() xmaxIn = inboxx.ur().x() xminOut = outboxx.ll().x() xmaxOut = outboxx.ur().x() yminIn = inboxy.ll().y() ymaxIn = inboxy.ur().y() yminOut = outboxy.ll().y() ymaxOut = outboxy.ur().y() funcx = trans1.get_funcx() funcy = trans2.get_funcy() boxin = Bbox(Point(xminIn, yminIn), Point(xmaxIn, ymaxIn)) boxout = Bbox(Point(xminOut, yminOut), Point(xmaxOut, ymaxOut)) return SeparableTransformation(boxin, boxout, funcx, funcy)
def get_bbox_transform(boxin, boxout): """ return the transform that maps transform one bounding box to another """ return SeparableTransformation(boxin, boxout, Func(IDENTITY), Func(IDENTITY))
def identity_transform(): """ Get an affine transformation that maps x,y -> x,y """ return SeparableTransformation(unit_bbox(), unit_bbox(), Func(IDENTITY), Func(IDENTITY))
def scale_sep_transform(sx, sy): """ Return a pure scale transformation as a SeparableTransformation; sx and sy are LazyValue instances (Values or binary opertations on values) """ bboxin = unit_bbox() bboxout = Bbox(Point(zero(), zero()), Point(sx, sy)) return SeparableTransformation(bboxin, bboxout, Func(IDENTITY), Func(IDENTITY))