[squeak-dev] Rounding in MatrixTransform2x3

Stephan Lutz dev at stlutz.net
Tue Jul 28 11:33:54 UTC 2020


While transforming points using MatrixTransform2x3 we noticed some 
strange rounding behavior:

    "with plugin"
    (MatrixTransform2x3 withOffset: 5 @ 10) localPointToGlobal: 0 at 0. "5 at 10"
    (MatrixTransform2x3 withOffset: -5 @ -10) localPointToGlobal: 0 at 0.
    "-4@ -9"

    "without plugin"
    ((MatrixTransform2x3 withOffset: 5 @ 10) transformPoint: 0 at 0)
    rounded. "5 at 10"
    ((MatrixTransform2x3 withOffset: -5 @ -10) transformPoint: 0 at 0)
    rounded. "-5@ -10"

It appears the code used to round in the plugin simply adds 0.5 and 
truncates the result, which does not work correctly for negative numbers.
This code can be found in Matrix2x3Plugin >> #roundAndStoreResultPoint: 
and Matrix2x3Plugin >> #roundAndStoreResultRect:x0:y0:x1:y1: .

----

On a kind of related note: Is there even a reason to round the resulting 
floats?

While the class comment of MatrixTransform2x3 notes that this behavior 
is intentional, glancing quickly over its uses we could not find 
anything taking advantage or benefiting from it. It's also not a 
limitation of the DisplayTransform interface, since MorphicTransform 
does produce floating point values. Wouldn't it be much more versatile 
and easier to leave rounding to users if they actually need it?


Stephan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200728/361c51e1/attachment-0001.html>


More information about the Squeak-dev mailing list