implementing support for tile rotation/flip.

this code can be very optimized through math.