Hi Gerd

Patch attached that, where possible, keeps ~straight roads unchanged and widens
the sharp angle on the other road.

This should fix the particular example and generally be better, although it is
difficult to test.

I try and note where I get incorrect turn instructions and later work out why
and, since the arcHeading_v2.patch in Oct 2020 I haven't found any that are
fixable; I couldn't find a solution where the major road continues at an angle
and the minor side road continues straight on.

Ticker

On Mon, 2024-08-05 at 19:14 +0100, Ticker Berkin wrote:
> Hi Gerd
> 
> I presume you are just changing SHARP_DEGREES, leaving COMPACT_DIR_DEGREES
> alone.
> 
> In this example the arcs on either side of the sharp angle have the same
> priority (class/speed) so there isn't an obvious one to adjust so the logic
> adjusts both.
> 
> Also in this example, and very common, is a side turn off a basically straight
> road and the proportions that each arc is adjusted isn't ideal in that the
> straight road is bent slightly more than the side turn is adjusted.
> 
> This could be spotted as a special case: when there are 3 arcs and the
> available
> angle on one side or the other (initial value of deltaPred or deltaNext) is
> close to 180 degrees then just the other side should be adjusted. Maybe the 3
> arcs doesn't really matter as long as there is sufficient space to adjust the
> other side.
> 
> I'll do some experiments.
> 
> Ticker
> 
> On Mon, 2024-08-05 at 08:55 +0000, Gerd Petermann wrote:
> > > > > Hi Ticker,
> > > > > 
> > > > > thanks, I didn't test much, but with a value of 22.5 (or 23) the
> > > > > problem
> > > > > disappeared. It also disappears with
> > > > > --x-ignore-sharp-angles. Downgrade is that the NOD size increases a
> > > > > bit,
> > > > > but
> > > > > I
> > > > > think that is better than wrong turn instructions.
> > > > > 
> > > > > Let me know if you cannot reproduce and I'll create a more complete
> > > > > description reg. the options in use.
> > > > > 
> > > > > ciao,
> > > > > Gerd
> > > > > 
> > > > > ________________________________________
> > > > > Von: mkgmap-dev <mkgmap-dev-boun...@lists.mkgmap.org.uk> im Auftrag
> > > > > von
> > > > > Ticker
> > > > > Berkin <rwb-mkg...@jagit.co.uk>
> > > > > Gesendet: Montag, 5. August 2024 10:42
> > > > > An: Development list for mkgmap
> > > > > Betreff: Re: [mkgmap-dev] Problem in AngleFixer?
> > > > > 
> > > > > Hi Gerd
> > > > > 
> > > > > I'll need to look carefully at this code again.
> > > > > 
> > > > > ISTR the 46 degrees was to stop arcs getting into the same compact
> > > > > segment
> > > > > when
> > > > > they shouldn't. My changes stopped a lot of incorrect turn
> > > > > instructions
> > > > > but
> > > > > maybe there is still scope for the algorithm to look for the same road
> > > > > entered
> > > > > and exiting in a straight line and try to preserve this by adjust
> > > > > other
> > > > > roads
> > > > > more.
> > > > > 
> > > > > Noticed that, in the example, these are bike routes and it looks like
> > > > > the
> > > > > algo
> > > > > ignores these.
> > > > > 
> > > > > Ticker
> > > > > 
> > > > > On Mon, 2024-08-05 at 06:37 +0000, Gerd Petermann wrote:
> > > > > > > > > Hi all,
> > > > > > > > > 
> > > > > > > > > in a private email Thorsten Kukuk contacted me about wrong
> > > > > > > > > turn
> > > > > > > > > instructions
> > > > > > > > > a
> > > > > > > > > sharp angles.
> > > > > > > > > An example is the node https://www.osm.org/node/27550903
> > > > > > > > > 
> > > > > > > > > A route coming from South that follows the way
> > > > > > > > > https://www.osm.org/way/36138336 at this junction should NOT
> > > > > > > > > produce a
> > > > > > > > > turn
> > > > > > > > > instruction.
> > > > > > > > > A route that turns left SHOULD produce a turn instruction.
> > > > > > > > > With current mkgmap it's vice versa and thus not OK.
> > > > > > > > > 
> > > > > > > > > I thnk the current code in AngleFixer.java is too agressive as
> > > > > > > > > it tries
> > > > > > > > > to
> > > > > > > > > enlarge the angles so that a compact format can be used to
> > > > > > > > > write
> > > > > > > > > the
> > > > > > > > > heading values of the arcs at the mentioned node. It does this
> > > > > > > > > by
> > > > > > > > > changing
> > > > > > > > > the
> > > > > > > > > heading values of both arcs with go to the north.
> > > > > > > > > 
> > > > > > > > > @Ticker: The code was introduced with your
> > > > > > > > > arcHeading_v2.patch,
> > > > > > > > > but
> > > > > > > > > maybe it
> > > > > > > > > existed before.
> > > > > > > > > Can you explain why the constant AngleChecker.SHARP_DEGREES is
> > > > > > > > > set to
> > > > > > > > > 46°
> > > > > > > > > instead of maybe 22.5° ?
> > > > > > > > > 
> > > > > > > > > Gerd
> > > > > > > > > _______________________________________________
> > > > > > > > > mkgmap-dev mailing list
> > > > > > > > > mkgmap-dev@lists.mkgmap.org.uk
> > > > > > > > > https://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > > 
> > > > > _______________________________________________
> > > > > mkgmap-dev mailing list
> > > > > mkgmap-dev@lists.mkgmap.org.uk
> > > > > https://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > > _______________________________________________
> > > > > mkgmap-dev mailing list
> > > > > mkgmap-dev@lists.mkgmap.org.uk
> > > > > https://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> 
> _______________________________________________
> mkgmap-dev mailing list
> mkgmap-dev@lists.mkgmap.org.uk
> https://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Index: src/uk/me/parabola/imgfmt/app/net/AngleChecker.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/net/AngleChecker.java	(revision 4921)
+++ src/uk/me/parabola/imgfmt/app/net/AngleChecker.java	(working copy)
@@ -69,7 +69,8 @@
 	private static final float SHARP_DEGREES = COMPACT_DIR_DEGREES;
 	// Experimentation found no benefit in increasing angle beyond 2 "sectors"
 	private static final float MIN_ANGLE = 11.25f; // don't reduce angles to less than this (arbitrary)
-	
+	private static final float STRAIGHT_EPSILON = 3f; // for straightAnough(angle)
+
 	// helper class to collect multiple arcs with (nearly) the same initial headings
 	private class ArcGroup {
 		float initialHeading;
@@ -337,10 +338,24 @@
 
 			if (deltaNext > 0 && deltaPred > 0) { // can take from both
 				if (ag1.maxRoadClass == ag2.maxRoadClass &&
-					ag1.maxRoadSpeed == ag2.maxRoadSpeed) { // take from both in ratio to available
-					deltaNext = Math.min(deltaNext, wantedIncrement * deltaNext / (deltaNext + deltaPred));
-					deltaPred = Math.min(deltaPred, wantedIncrement - deltaNext);
-			    } else if (ag1.maxRoadClass > ag2.maxRoadClass ||
+					ag1.maxRoadSpeed == ag2.maxRoadSpeed) { // both arcs similar
+					if (straightAnough(predAA.angle) && deltaNext >= wantedIncrement) {
+						// where there is a straight road with a sharp turn-off then just adjust
+						// the turn-off. This is treated as a special case because the general
+						// logic below will adjust the straight road slightly more than the
+						// turn-off and, in some cases, with compactDirs, turn-instructions
+						// will be given for the wrong road
+						deltaPred = 0;
+						deltaNext = wantedIncrement;
+					} else if (straightAnough(nextAA.angle) && deltaPred >= wantedIncrement) {
+						// like above
+						deltaNext = 0;
+						deltaPred = wantedIncrement;
+					} else { // take from both in ratio to available
+						deltaNext = Math.min(deltaNext, wantedIncrement * deltaNext / (deltaNext + deltaPred));
+						deltaPred = Math.min(deltaPred, wantedIncrement - deltaNext);
+					}
+				} else if (ag1.maxRoadClass > ag2.maxRoadClass ||
 						   (ag1.maxRoadClass == ag2.maxRoadClass &&
 							ag1.maxRoadSpeed > ag2.maxRoadSpeed)) { // take as much as poss from next
 					if (deltaNext >= wantedIncrement) {
@@ -435,6 +450,11 @@
 	}
 
 
+	private static boolean straightAnough(float angle) {
+		return angle > 180-STRAIGHT_EPSILON && angle < 180+STRAIGHT_EPSILON;
+	}
+
+
 	/**
 	 * for log messages
 	 */
_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
https://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to