Why draw an operation on an android canvas using float instead of int for (x, y)?

Why draw an operation on an android canvas using float instead of int for (x, y)? For example: http://developer.android.com/reference/android/graphics/Canvas.html#drawCircle(float , float, float, android.graphics.Paint)

http://developer.android.com/reference/android/graphics/Canvas.html#drawRect(float , float, float, float, android.graphics.Paint)

If I have many objects (say 200) for drawing in my application, and I have a class for each object, should I use 'int' or 'float' for the x, y attribute (the location of the object when drawn on the screen)? I think that "float" uses less memory than "int".

class MyObject { public int x; public int y; } 

Thanks.

+6
source share
1 answer

A float because anti-aliasing allows you to draw at a subpixel level. Also because a transformation matrix (e.g., scale) may be active.

The float and int are accepted as 32 bits (most likely)

+5
source

Source: https://habr.com/ru/post/888584/


All Articles