Why should I use float?

I mean, for pixel position, sizes, etc. It doesn't look like I will make a rectangle 100 and a half pixels high. They can also be integers.

+4
source share
4 answers

If you are drawing smooth geometry, you need fractional coordinates.

If your geometry can be rescaled by the base API to display on different screens, you need fractional coordinates.

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

If you want to split the line from A to C into a piece from A to B and a piece from B to C, and also combine them to look the same as the original line, then you need fractional coordinates.

If you want to have a high-precision internal representation of your geometry, which does not depend on the low-precision parts of the main display equipment, you need fractional coordinates.

If your API does not do this now, but you need to support it in the next version without breaking compatibility, then you need fractional coordinates.

+11
source

Not yet. But as more resolutions are added, the fact that Apple measures screens in its own units rather than pixels can become more useful over time.

+2
source

For simple graphics, window positions, etc. you are right, you do not need them.

For more complex graphics, they are necessary because the screen resolution may not be enough to justify what you are trying to display. Turning an idealized fractional view of the world into something that can display a screen with a finite number of pixels is called rasterisation and this is a pretty big topic.

I always see this as an extreme example of a view-controller model: decouple what you are trying to extract from how it is drawn on the screen.

+2
source

Some coordinate systems interpret the float coordinates, approximating the location between two pixels with different shades to provide smoother animations and eliminate jagged edges.

0
source

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


All Articles