Why does GraphicsContext use double parameter methods?

I am going from swing to jawafx. I was wondering why GraphicsContext uses double parameter methods. For example fillRect(double x, double y, double w, double h)

, unlike swing, it has methods drawRect(int x, int y, int width, int height)

.

Should I do all my calculations in double?

+3


source to share


1 answer


drawRect

in inherited from Graphics

, which is used int

to specify coordinates and size.

An object Graphics2D

, on the other hand, is capable of handling graphics values ​​that lie "between whole pixels". To compensate for this, there will usually be a fading pixel (partly between the drawing and BG color) in the parts of the render where it has to deal with pixel fractions.



Should I do all my calculations in double?

Yes! Double values ​​that are exactly an integer will display exactly as you would expect from a method Graphics

- with crisp, clean lines. But if the shape's border ever falls between whole pixels, the color will fade out.

+4


source







All Articles