I always feel suspicious when I see rounding done with `(int)`. Often, this rounding towards zero (2.0, 2.2 and 2.9 will give 2, while -2.0, -2.2 and -2.9 will give -2) is bogus, and `Math.round()` which rounds to the nearest integer is more appropriate. Sometimes, the rounding towards 0 is right, but that is not so common.

Have you had a chance to check that this is intended?