Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use floats?

I mean, for pixel position, sizes, etc. It's not like I'll be making a rectangle that's 100 and a half pixels high. These might as well be integers.

like image 596
Igor Avatar asked Dec 07 '22 03:12

Igor


2 Answers

If you draw anti-aliased geometry, you need fractional coordinates.

If your geometry might be rescaled by the underlying API to display on a variety of screens you need fractional coordinates.

If you want to be able to tell the API to rotate, scale or shear your geometry you need fractional coordinates.

If you want to be able to break a line from A to C into a piece from A to B and a piece from B to C, and have them join up to look just like the original line, then you need fractional coordinates.

If you want to have a high precision internal representation of your geometry that's independent of the low precision details of the underlying display hardware, you need fractional coordinates.

If your API doesn't do these things now, but you need it to support these things in the next version without breaking compatibility, then you need fractional coordinates.

like image 192
sigfpe Avatar answered Dec 18 '22 18:12

sigfpe


Not yet you won't, perhaps. But as more resolutions are added, the fact that Apple measure screens in their own units rather than pixels could become more useful in time.

like image 41
h4xxr Avatar answered Dec 18 '22 18:12

h4xxr