[mkgmap-dev] [PATCH v1] Better rounding in mkgmap
From Elrond elrond+openstreetmap.org at samba-tng.org on Tue Aug 11 14:50:30 BST 2009
Hi everyone, As rounding seems a current topic, I'm throwing in a patch that is sitting in my tree for a while now: We used to round coords to the shifted values in a subdiv by just using the ">>" shift operator. This works. But it's not the mathematical way of rounding, and the later is better IMHO. Let me explain this with an example: Let's assume the center-Lat of a subdiv is exactly at 0. Let's assume the shift-value is 4. So we divide by 16, or truncate to it, however you like to think about it. So if we have a point at lat=31, it will have the shifted value of (31-0) >> 4 = _1_. This will be displayed at 0 + (_1_ << 4) = 16. While _2_ would give us 0 + (_2_ << 4) = 32. 32 is much closer to the real value. Another more intuitive way of looking at the whole thing is with classic rounding: Just assume, that the current shift value is choosen so that we round exactly to "degrees" (some special sort of degrees). So, 3.9 will currently be rounded to just 3, not 4. The solution is add half the rounding distance and truncate: truncate(3.9 + 0.5) = 4. PENDING ISSUES: I am not sure, that I have catched all cases in mkgmap. Any feedback on this is highly welcome. Of course, general testing and feedback is also welcome! Elrond p.s.: This is also related to the overview map issue I was talking about a while back and wanting to post patches for. This one can be counted as the next one. -------------- next part -------------- A non-text attachment was scrubbed... Name: rounding-2.diff Type: text/x-diff Size: 2880 bytes Desc: not available Url : http://lists.mkgmap.org.uk/pipermail/mkgmap-dev/attachments/20090811/33b6bfa7/attachment.bin
- Previous message: [mkgmap-dev] Routing with the default style
- Next message: [mkgmap-dev] [PATCH v1] Better rounding in mkgmap
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the mkgmap-dev mailing list