I'm moving from swing to javafx. I wondered why GraphicsContext uses methods with double params. For example fillRect(double x, double y, double w, double h) unlike swing has methods drawRect(int x, int y, int width, int height).
Should I do all my calculations in double?
drawRect in inherited from Graphics which uses int to specify the co-ords & size.
The Graphics2D object on the other hand, is capable of dealing with graphics values that lie 'between whole pixels'. To compensate it will typically render a dithered pixel (part way between the drawing and BG color) at parts of the rendering where it has to deal with fractions of a pixel.
Should I do all my calculations in double?
Yes! Double values that are exactly equal to an integer will be rendered as you might expect from the Graphics method - with sharp, clean lines. But if the boundary of the shape ever falls between whole pixels, the color will be dithered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With