def scale_transform(sx, sy): """ Return a pure scale transformation as an Affine instance; sx and sy are LazyValue instances (Values or binary opertations on values) """ return Affine(sx, zero(), zero(), sy, zero(), zero())
def scale_translation_transform(tx, ty, sx, sy): """ Return a pure scale and translation transformation; tx, ty, sx and sy are LazyValue instances (Values or binary opertations on values) """ affine = Affine(sx, zero(), zero(), sy, tx, ty) func = identity_funcxy() return Transformation(affine, func)
def multiply_affines(v1, v2): """ v1 and v2 are Affine instances """ a1, b1, c1, d1, tx1, ty1 = v1.as_vec6() a2, b2, c2, d2, tx2, ty2 = v2.as_vec6() a = a1 * a2 + c1 * b2 b = b1 * a2 + d1 * b2 c = a1 * c2 + c1 * d2 d = b1 * c2 + d1 * d2 tx = a1 * tx2 + c1 * ty2 + tx1 ty = b1 * tx2 + d1 * ty2 + ty1 return Affine(a, b, c, d, tx, ty)
def translation_transform(tx, ty): """ return a pure tranlational transformation tx and ty are LazyValue instances (Values or binary opertations on values) """ return Affine(zero(), zero(), zero(), zero(), tx, ty)
def identity_affine(): """ Get an affine transformation that maps x,y -> x,y """ return Affine(one(), zero(), zero(), one(), zero(), zero())