added 2D affine transformation and implemented inversion of affine matrix