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?

TaW
  • 53,122
  • 8
  • 69
  • 111
Romy
  • 407
  • 6
  • 25
  • 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 09 '16 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 '16 at 01:11
  • Hm, can you try to use a smalle scaling factor like 5000 or 1000? – TaW Jun 10 '16 at 03: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 '16 at 08: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 '16 at 09:09
  • They should connect end to end. I checked and for the most, the ending coordinates are the same as the next one's starting ones. All of the connections imply a street crossing. – Romy Jun 10 '16 at 09:24

0 Answers0