On Sun, 29 Jun 2025 06:54:06 GMT, Sergey Bylokhov <s...@openjdk.org> wrote:
>>> Please double-check whether you need to use Region.clipScale() instead. >> >> @mrserb We use `Region.clipRound` for converting coordinates in >> `SwingUtilities3.paintBorder`: >> >> https://github.com/openjdk/jdk/blob/a23de2ec090628b52532ee5d9bd4364a97499f5b/src/java.desktop/share/classes/com/sun/java/swing/SwingUtilities3.java#L231-L236 >> >> These formulas were introduced in #10681 >> ([JDK-8282958](https://bugs.openjdk.org/browse/JDK-8282958)); and after >> refactoring #11571 >> ([JDK-8294680](https://bugs.openjdk.org/browse/JDK-8294680)), the new >> formulas resolved [JDK-8294921](https://bugs.openjdk.org/browse/JDK-8294921) >> after #7449 ([JDK-8279614](https://bugs.openjdk.org/browse/JDK-8279614)) >> where there was a gap between the component edge and its border. These >> formulas specifically addressed the situation with gaps and were developed >> while we worked on making `LineBorder` and `EtchedBorder` render better at >> fractional scales. >> >> So, using `clipRound` seems good enough. Initially, [I >> suggested](https://bugs.openjdk.org/browse/JDK-8349188?focusedId=14758933&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14758933) >> using `(int) (this.thickness * scaleFactor)`, but `clipRound` gives better >> results. >> >>> I actually do not remember when to use one over the other. Maybe if you >>> find a review request for the patch where these methods were added, you can >>> confirm which one should be used. >> >> I couldn't find anything explaining where `clipScale` is better than >> `clipRound`. The discussion for >> [JDK-8000629](https://bugs.openjdk.org/browse/JDK-8000629) started in [March >> 2013](https://mail.openjdk.org/pipermail/awt-dev/2013-March/004486.html) and >> continued in [April >> 2013](https://mail.openjdk.org/pipermail/awt-dev/2013-April/004577.html). >> >>> I checked the current source, and it seems that we randomly use one or the >>> other, which seems incorrect. >> >> The javadoc for neither `clipScale` nor `clipRound` provides an example >> where each method is best suitable. So, it's not that surprising either is >> used randomly… >> >> It seems to me, that both >> [`clipScale`](https://github.com/openjdk/jdk/blob/a23de2ec090628b52532ee5d9bd4364a97499f5b/src/java.desktop/share/classes/sun/java2d/pipe/Region.java#L159) >> and >> [`clipRound`](https://github.com/openjdk/jdk/blob/a23de2ec090628b52532ee5d9bd4364a97499f5b/src/java.desktop/share/classes/sun/java2d/pipe/Region.java#L140) >> yield the same result. The former uses `Math.round`, whereas the latter >> uses `Math.ceil` aft... > > I am pretty sure these methods produce different results for negative > coordinates. probably these discussions may help https://mail.openjdk.org/pipermail/2d-dev/2016-July/007152.html https://mail.openjdk.org/pipermail/2d-dev/2016-October/007764.html ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/26025#discussion_r2173617586