RFR: JDK-8306990: The guarantees given by Region's floor and ceiling functions should work for larger values
John Hendrikx
jhendrikx at openjdk.org
Thu Apr 27 10:26:29 UTC 2023
Region has floor and ceiling functions that ensure that calling them twice in a row will yield the same result:
ceil(x) = ceil(ceil(x))
However, due to use of a constant `EPSILON` which is added/subtracted before doing the rounding, this only works for small numbers (in the range of 0-50 approximately). For larger values and scales, rounding errors can easily occur. This is visible as artifacts on screen where controls are a pixel wider than they should be.
The use of the `EPSILON` constant is incorrect, as its value depends on the magnitude of the value in question (as magnitude increases, the fractional precision decreases).
The Math class offers the function `ulp` that should be used here. It represents the smallest possible change in value for a given double.
Extending the existing test case `snappingASnappedValueGivesTheSameValueTest` to use larger magnitude numbers exposes the problems.
-------------
Commit messages:
- Fix Region ceil/floor function guarantees to be more accurate
Changes: https://git.openjdk.org/jfx/pull/1118/files
Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=1118&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8306990
Stats: 59 lines in 2 files changed: 23 ins; 12 del; 24 mod
Patch: https://git.openjdk.org/jfx/pull/1118.diff
Fetch: git fetch https://git.openjdk.org/jfx.git pull/1118/head:pull/1118
PR: https://git.openjdk.org/jfx/pull/1118
More information about the openjfx-dev
mailing list