logo separator

[mkgmap-dev] [PATCH] make gps report correct exit when routing through roundabouts

From Toby Speight T.M.Speight.90 at cantab.net on Thu Feb 12 11:49:00 GMT 2009

0> In article <28313007-F338-4CF6-ACAD-FB46DC1DC800 at gmx.net>,
0> Robert Vollmert <URL:mailto:rvollmert-lists at gmx.net> ("Robert") wrote:

Robert> This compiles, at least, and probably does what I want:
Robert> +			// calculate normalized differences
Robert> +			int max = 1 << (24-shift);
Robert> +			int dx = (lon - lastLong) % (1 << (24-shift));
Robert> +			if (dx >= max/2) dx -= max/2;
Robert> +			int dy = (lat - lastLat) % (1 << (24-shift));
Robert> +			if (dy >= max/2) dy -= max/2;
Robert>
Robert>  			lastLong = lon;
Robert>  			lastLat = lat;

I'd suggest helping the compiler by putting that (1 << (24-shift))
into a (local) constant.

Actually, using the fact that a Java int is 32-bit and signed, you can
do something like (untested)

/--------
| final int offset = 8+shift;
| int dx = (lon - lastLong) << offset >> offset;
| ind dy = (lat - lastLat) << offset >> offset;
\--------

to truncate and sign-extend those values.  This approach will probably
run faster on most hardware, as I've eliminated those conditionals.

I've not read and understood enough of the code to work out whether
the sign extension is really required; if not, a simple AND mask may
be sufficient.



More information about the mkgmap-dev mailing list