Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8345261: Refactor the Dimension2D classes #1653

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nlisker
Copy link
Collaborator

@nlisker nlisker commented Nov 29, 2024

A small refactoring of the Dimension classes.

  • com.sun.javafx.geom.Dimension was removed and its uses were replaced by com.sun.javafx.geom.Dimension2D.
  • com.sun.javafx.geom.Dimension2D became a record.
  • javafx.geometry.Dimension2D: fields became final.

I'm not sure we need the implementation class at all considering we are free to use the public one.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8345261: Refactor the Dimension2D classes (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1653/head:pull/1653
$ git checkout pull/1653

Update a local copy of the PR:
$ git checkout pull/1653
$ git pull https://git.openjdk.org/jfx.git pull/1653/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1653

View PR using the GUI difftool:
$ git pr show -t 1653

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1653.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 29, 2024

👋 Welcome back nlisker! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 29, 2024

@nlisker This change is no longer ready for integration - check the PR body for details.

@nlisker nlisker marked this pull request as ready for review November 29, 2024 17:06
@openjdk openjdk bot added the rfr Ready for review label Nov 29, 2024
@mlbridge
Copy link

mlbridge bot commented Nov 29, 2024

Webrevs

Copy link
Collaborator

@hjohn hjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@openjdk openjdk bot added the ready Ready to be integrated label Nov 30, 2024
@nlisker
Copy link
Collaborator Author

nlisker commented Nov 30, 2024

Thanks John. Because it's the weekend I'll wait until Monday evening with this.

@kevinrushforth
Copy link
Member

@azvegint Can you take a quick look at this since you added the Dimension class as part of your initial Wayland Robot fix?

@azvegint
Copy link
Member

azvegint commented Dec 2, 2024

These 3 classes are all different from each other. They use different types of variables to store data (double, float, int).

We have com.sun.javafx.geom.Rectangle which uses int, and the com.sun.javafx.geom.Dimension was specifically introduced as its pair which also uses int.
(just as we have a pair of javafx.geometry.Rectangle2D and javafx.geometry.Dimension2D.java).

Switching from int to float may have some side effects on stream processing due to the imprecise comparison.

So I would prefer to keep the com.sun.javafx.geom.Dimension.

@nlisker
Copy link
Collaborator Author

nlisker commented Dec 2, 2024

Thanks @azvegint. If the int-based dimensions are coupled with com.sun.javafx.geom.Rectangle (and from the code, that's the only place they are used at), would you object to making Dimension an inner class of Rectangle? The float-based dimensions are used in other 2D shapes, so are more general purpose.

@nlisker
Copy link
Collaborator Author

nlisker commented Dec 2, 2024

I also looked at the uses of com.sun.javafx.geom.Rectangle and in almost all cases I've looked at, its values are widened to floats later on. I'm not going to change anything there, but there is an indication that it's not the right tool for the job.

@Maran23
Copy link
Member

Maran23 commented Dec 2, 2024

Not sure if it helps, but when working on #1462, I also found that inconsistencies.
Sometimes double is used and later 'degraded' to a float, sometimes a float is promoted to a double. And as we found here, int is used but later changed to float.

I'm not sure why this happens, but maybe worth to take a deeper look.

@azvegint
Copy link
Member

azvegint commented Dec 2, 2024

would you object to making Dimension an inner class of Rectangle?

I am fine with it.

@kevinrushforth
Copy link
Member

/reviewers 2

@openjdk
Copy link

openjdk bot commented Dec 2, 2024

@kevinrushforth
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@openjdk openjdk bot removed the ready Ready to be integrated label Dec 2, 2024
* The <code>Dimension2D</code> class is to encapsulate a width
* and a height dimension.
* <p>
* A 2D dimension object that contains a width and a height.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mention that this class uses floats?

rectangle.width,
rectangle.height
))
.map(rectangle -> new Dimension2D(rectangle.width, rectangle.height))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the largest positive integer that can be stored in a float exactly is ~16M. we are fine here.

height = h;
}
}
public record Dimension2D(float width, float height) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish this class was named differently to signify it's based on float...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the classes in this package are based on floats. As this is an internal class, adding a comment seems sufficient.

@nlisker
Copy link
Collaborator Author

nlisker commented Dec 2, 2024

You reviewed the PR before the requested changes were made :)
I'm going to move the int one into an inner class anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rfr Ready for review
Development

Successfully merging this pull request may close these issues.

6 participants