Using float or int for coordinates for graphic operations

Posted on 2005-04-12
Last Modified: 2010-04-16
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?
Question by:ptmcomp
    LVL 4

    Accepted Solution

    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
    LVL 10

    Author Comment

    I decided to use floats everywhere. I use matrix transformations string draw and zooming and you convinced me to use floats.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now