• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

Using float or int for coordinates for graphic operations

I'm developing a graphic editor which should not be limited too much in virtual space and precision. Before .net I used Int32 for the coordinates since the calculations are fast and I can address a huge virtual canvas with a good precision. Now .net comes up with float for most graphic operations. First tests showed that it's an advantage for text draw operations with small fonts. How will it affect my project if I use everywhere float for coordinates? What are the pros and cons?
0
ptmcomp
Asked:
ptmcomp
1 Solution
 
caner_elciCommented:
Well, the main need for floating numbers for coordinates is of course the need of high precision while calculating coordinates. If you are developing an engineering application, such as a CAD software, I strongly suggest you to use floats instead of integers. That just because you will possibly need an X coordinate like 15.374 there. As far as I know, GDI+ uses the same implementation for both floats and integers. Because GDI+ has its built-in transformation methods, Scale, Translate, Rotate etc, it has to do its operations in float mode. That's you'll not notice any performance issues while using floats. The only difference between floats and integers is that integer classes (Point, Size etc.) have some additional methods than floats (PointF, SizeF etc). As an example, you'll not see Offset method in PointF, altough it exists in Point class. Only reason to use integers might be laziness, because if you are working with exact coordinates, it will be hard to round the float variables.

From some real time experiences:
I've used floats in a GIS (Geographical Information Systems) application and some image processing applications. In all other designers, viewers and graphical applications, I used integers and they were enough for me.

Caner ELCI
0
 
ptmcompAuthor Commented:
I decided to use floats everywhere. I use matrix transformations string draw and zooming and you convinced me to use floats.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now