// Represent the scale factors as Rational numbers.
// Since a value of 1.2 is represented as 1.200001 which
// throws the forward/backward mapping in certain situations.
// Convert the scale and translation factors to Rational numbers
Rational scaleXRational =
Rational.approximate(scaleX, rationalTolerance);
Rational scaleYRational =
Rational.approximate(scaleY, rationalTolerance);
long scaleXRationalNum = (long)scaleXRational.num;
long scaleXRationalDenom = (long)scaleXRational.denom;
long scaleYRationalNum = (long)scaleYRational.num;
long scaleYRationalDenom = (long)scaleYRational.denom;
Rational transXRational =
Rational.approximate(transX, rationalTolerance);
Rational transYRational =
Rational.approximate(transY, rationalTolerance);
long transXRationalNum = (long)transXRational.num;
long transXRationalDenom = (long)transXRational.denom;
long transYRationalNum = (long)transYRational.num;