[OpenJDK 2D-Dev] RFR: 8166038 BufferedImage methods getTileGridXOffset() and getTileGridYOffset() return a non 0 value for sub images
Martin Desruisseaux
martin.desruisseaux at geomatys.com
Fri Apr 17 13:28:25 UTC 2020
Hello Jay
Le 17/04/2020 à 12:58, Jayathirth D v a écrit :
> I have a question regarding test case. Why test has to check whether
> we are getting negative value or not and then calculate whether the
> tileGridOffset is 0. From different function's specification in
> BufferedImage I see that there are no multiple tiles support. I went
> through mail thread related to how we are comparing it to JAI’s
> implementation. But I think we can still keep the test case to be
> minimal and just check for 0 grid offset values.
>
It is true that just testing that grid offset values are 0 would be
sufficient. But doing so does not explain why it needs to be zero
(except because the specification said so). The purpose of the first
part of the test, which is computing tileX and tileY, is to illustrate
why grid offsets need to be zero. The idea is to said "Suppose that we
don't know that this image has only one tile. Let's calculate tile
indices the way we would do for an arbitrary RenderedImage. Do we get
consistent results?".
In other words the two tests are redundant. But the first test requiring
(tileX == 0 && tileY == 0) takes the perspective of checking if the
values are mathematically consistent, while the other tests requiring
(tileGridXOffset == 0 && tileGridXOffset == 0) are basically the same
tests but from the perspective of checking compliance with
specification. The first test about mathematical consistency is a kind
of documentation, but addresses the problem which was the reason for
this patch request.
The comment about negative value is because the formulas used in the
test — tileX = (x - tileGridXOffset) / image.getTileWidth() — is not
quite exact. The division should be replaced by a call to
Math.floorDiv(int, int). I though that it was not necessary for this
test since the two formulas will differ only if (x - tileGridXOffset) is
negative, which is not the case in this test, and that a comment would
be simpler. But maybe it would be less confusing to remove the comment
and use Math.floorDiv(int, int) instead.
Regards,
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/2d-dev/attachments/20200417/0c0cc42c/attachment.htm>
More information about the 2d-dev
mailing list