2

I'm loading coordinate values with GraphichsPath.AddLine command, then drawing them and I've noticed my map is not quite accurate.

The code in question is as follows. I'm casting start and end coordinates from double to float since the command takes only float values, then multiplying them so they scale better:

 GraphicsPath gp = new GraphicsPath();
 gp.AddLine((float)(line.startX*10000), (float)(line.startY * 10000), 
            (float)(line.endX * 10000), (float)(line.endY * 10000));

For example, startX value is 15.742560625076294 but when i check the gp path data in debugger, I see it as 157425.609. The last 7 digits are shortened. And they are crucial because the difference in meters is important in this case.

Is this the limitation of a float value as opposed to double? How can I load the full values in said command?

6
  • Yes. Float only can hold 7 digits. Which should be enouh for anything you draw. (All GDI+ drawing is limited to 32kx32k pixels anyway)) But if you want to do any calculations you may want to hold the full(er) precision of doubles in your data.. (((you did exchange width.. for clientsize.width??)))
    – TaW
    Jun 9, 2016 at 23:55
  • Yes, I've changed to clientize.width right away. When zoomed in, some lines look a little "off", but if there's nothing that can be done, it's good enough. Shame there isnt .AddLine that accepts double or decimal.
    – Romy
    Jun 10, 2016 at 1:11
  • Hm, can you try to use a smalle scaling factor like 5000 or 1000?
    – TaW
    Jun 10, 2016 at 3:59
  • I'm getting the same result, tried 1000 for the scale, only the decimal dot changed to the left, and the lines are much thicker, have to stick with 10k
    – Romy
    Jun 10, 2016 at 8:52
  • Hm, still wondering. Just to be sure: You did check that the numbers you use are correct? Those errors: Should they connect end to end (Z) or should a line/street touch another one (T)?
    – TaW
    Jun 10, 2016 at 9:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.