Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

Why draw operation in android canvas are 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 a lot of objects (say 200) to draw 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 screen)? i think 'float' use less memory than 'int'.

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

Thank you.

like image 634
michael Avatar asked May 19 '11 20:05

michael


1 Answers

Float because anti-aliasing allows you to paint at sub-pixel level. Also because there can be a transformation matrix active (e.g. A scale).

A float and int take both 32 bit (most likely)

like image 109
Kris Van Bael Avatar answered Sep 18 '22 23:09

Kris Van Bael