[mkgmap-dev] [PATCH v1] fix for weird turn directions regression

2010-02-26 Thread Mark Burton

Hopefully fixes the recent regression which caused incorrect turn
directions to be issued (most likely to occur when entering roundabouts
that have flares).

Actually, the bug was there before but it was being masked by some other
code that recently got removed so the bug then popped to the surface!

Please test.

Mark
diff --git a/src/uk/me/parabola/imgfmt/app/net/RouteNode.java b/src/uk/me/parabola/imgfmt/app/net/RouteNode.java
index 2b8ca79..5a55740 100644
--- a/src/uk/me/parabola/imgfmt/app/net/RouteNode.java
+++ b/src/uk/me/parabola/imgfmt/app/net/RouteNode.java
@@ -339,6 +339,24 @@ public class RouteNode implements ComparableRouteNode {
 		return false;
 	}
 
+	private static boolean rightTurnRequired(int inHeading, int outHeading, int sideHeading) {
+		// decide whether a side road is to the left of the right
+		// given the headings of the incoming, outgoing and side roads
+		int a = sideHeading - (inHeading + 180);
+		while(a  -180)
+			a += 360;
+		while(a  180)
+			a -= 360;
+		if(a  0)
+			return false;
+		a = sideHeading - outHeading;
+		while(a  -180)
+			a += 360;
+		while(a  180)
+			a -= 360;
+		return a  0;
+	}
+
 	private static int ATH_OUTGOING = 1;
 	private static int ATH_INCOMING = 2;
 
@@ -520,13 +538,13 @@ public class RouteNode implements ComparableRouteNode {
 		inToOtherDelta += 360;
 
 	int newHeading = otherHeading;
-	if(outToOtherDelta  0) {
+	if(rightTurnRequired(inHeading, outHeading, otherHeading)) {
 		// side road to the right
 		if((mask  ATH_OUTGOING) != 0 
-		   outToOtherDelta  minDiffBetweenOutgoingAndOtherArcs)
+		   Math.abs(outToOtherDelta)  minDiffBetweenOutgoingAndOtherArcs)
 			newHeading = outHeading + minDiffBetweenOutgoingAndOtherArcs;
 		if((mask  ATH_INCOMING) != 0 
-		   inToOtherDelta  minDiffBetweenIncomingAndOtherArcs) {
+		   Math.abs(inToOtherDelta)  minDiffBetweenIncomingAndOtherArcs) {
 			int nh = inHeading + minDiffBetweenIncomingAndOtherArcs;
 			if(nh  newHeading)
 newHeading = nh;
@@ -535,13 +553,13 @@ public class RouteNode implements ComparableRouteNode {
 		if(newHeading  180)
 			newHeading -= 360;
 	}
-	else if(outToOtherDelta  0) {
+	else {
 		// side road to the left
 		if((mask  ATH_OUTGOING) != 0 
-		   outToOtherDelta  -minDiffBetweenOutgoingAndOtherArcs)
+		   Math.abs(outToOtherDelta)  minDiffBetweenOutgoingAndOtherArcs)
 			newHeading = outHeading - minDiffBetweenOutgoingAndOtherArcs;
 		if((mask  ATH_INCOMING) != 0 
-		   inToOtherDelta  -minDiffBetweenIncomingAndOtherArcs) {
+		   Math.abs(inToOtherDelta)  minDiffBetweenIncomingAndOtherArcs) {
 			int nh = inHeading - minDiffBetweenIncomingAndOtherArcs;
 			if(nh  newHeading)
 newHeading = nh;
___
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Re: [mkgmap-dev] [PATCH v1] fix for weird turn directions regression

2010-02-26 Thread Carlos Dávila
Mark Burton escribió:
 Hopefully fixes the recent regression which caused incorrect turn
 directions to be issued (most likely to occur when entering roundabouts
 that have flares).

 Actually, the bug was there before but it was being masked by some other
 code that recently got removed so the bug then popped to the surface!

 Please test.
I'm afraid I don't see any change with your patch applied
___
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev


Re: [mkgmap-dev] [PATCH v1] fix for weird turn directions regression

2010-02-26 Thread Carlos Dávila
Mark Burton escribió:
 Hopefully fixes the recent regression which caused incorrect turn
 directions to be issued (most likely to occur when entering roundabouts
 that have flares).

 Actually, the bug was there before but it was being masked by some other
 code that recently got removed so the bug then popped to the surface!

 Please test.

 Mark
I'm sorry, I tested the wrong map (too much things at the same time). I
have seen some improvements, but not all weird instructions have
disappeared. I'll report more details after testing some more.
___
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev


Re: [mkgmap-dev] [PATCH v1] fix for weird turn directions regression

2010-02-26 Thread Mark Burton

Hi Carlos,

 I'm sorry, I tested the wrong map (too much things at the same time). I
 have seen some improvements, but not all weird instructions have
 disappeared. I'll report more details after testing some more.

OK - I will work on it again this evening.

Mark
___
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev