java.awt.Point uses floor + 0.5 #692
nightm4re94
started this conversation in
Old Forum
Replies: 1 comment
-
|
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This post has been migrated automatically from the old LITIENGINE forum (2018 - 2022).
Posted: 2019-12-03 09:50:22
User: KvaGram [] (age: 1068 days 🔥; posts: 52)
So... I was digging a bit in the source codes for the awt package when I foud this gem
public void setLocation(double x, double y) { this.x = (int) Math.floor(x+0.5); this.y = (int) Math.floor(y+0.5); }So.. they want the function to round up. To do that, the awt devs decided to call Math.floor?
I can forgive them if they wrote this before Math.ceil were added, but if not, dang.
Checking where the calls go, I realize floor and ceil both end up in the same function.
That means you'd save on two float operations per call, if they dropped the +0.5, and used Math.ceil instead. For something that could be called hundreds of times per frame, that is a lot :D
I had to laugh. Even in professional code, stupid code can show itself.
Beta Was this translation helpful? Give feedback.
All reactions