Hello list,


I am experiencing a somewhat peculiar behavior when inverting Matrix
objects. Specifically, the rectStaysRect property is not always
preserved correctly, even in trivial cases.

If I compile and run the following code in debug mode:

Matrix foo = new Matrix(); // Creates the identity matrix
Log.d("TEST", "foo = " + foo.toString());
Log.d("TEST", "rectStaysRect: " + foo.rectStaysRect());
foo.invert(foo); // Still the identity matrix
Log.d("TEST", "foo = " + foo.toString());
Log.d("TEST", "rectStaysRect: " + foo.rectStaysRect());

I expectedly get the following output:

D/TEST    (  353): foo = Matrix{[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
D/TEST    (  353): rectStaysRect: true
D/TEST    (  353): foo = Matrix{[1.0, -0.0, 0.0][-0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
D/TEST    (  353): rectStaysRect: true

However, if the same code is compiled and run in release mode, I
instead get the following:

D/TEST    ( 3277): foo = Matrix{[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
D/TEST    ( 3277): rectStaysRect: true
D/TEST    ( 3277): foo = Matrix{[1.0, -0.0, 0.0][-0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
D/TEST    ( 3277): rectStaysRect: false

Notice how the matrix values are the same (at least to the precision
printed by the logger), but the rectStaysRect property has changed
after the invert operation. Even more interestingly, if I add a
completely unrelated matrix creation, the behavior is reverted back to
the original one, regardless of whether I run in release or debug. The
following code:

Matrix foo = new Matrix(); // Creates the identity matrix
Matrix notUsed = new Matrix(); // Unrelated matrix created here
Log.d("TEST", "foo = " + foo.toString());
Log.d("TEST", "rectStaysRect: " + foo.rectStaysRect());
foo.invert(foo); // Still the identity matrix
Log.d("TEST", "foo = " + foo.toString());
Log.d("TEST", "rectStaysRect: " + foo.rectStaysRect());

again prints the expected:

D/TEST    ( 3361): foo = Matrix{[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
D/TEST    ( 3361): rectStaysRect: true
D/TEST    ( 3361): foo = Matrix{[1.0, -0.0, 0.0][-0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
D/TEST    ( 3361): rectStaysRect: true

I can reproduce this with a 100% success rate on a Nexus One running
2.3.3. I have not been able to reproduce it reliably on the emulator
(I believe I saw it happen at least once, but currently it always
gives me the correct output, so I will not swear on it).

I am guessing one difference between the three cases could be that the
JIT is stepping in in the second one, but not the first or third. How
can I check this?

And what exactly is the semantics of rectStaysRect()? Does "false" as
return value only mean we do not know whether the matrix maps a
rectangle to a rectangle? If not, what happens in the second case
above ought to be a bug.



Best regards,

Josef

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to