From 2b75aa77864cb89b643ec27326ee6249ad22f02e Mon Sep 17 00:00:00 2001 From: ratrun Date: Sat, 7 Sep 2024 17:07:53 +0200 Subject: [PATCH] Add support for bike mtb:scale accessability --- .../util/parsers/BikeCommonAccessParser.java | 11 +++++++++++ .../util/parsers/MountainBikeAccessParser.java | 6 ++++++ .../parsers/AbstractBikeTagParserTester.java | 18 +++++++++++------- .../util/parsers/BikeTagParserTest.java | 2 +- .../parsers/MountainBikeTagParserTest.java | 15 ++++++++++++++- .../util/parsers/RacingBikeTagParserTest.java | 10 +++++++++- 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonAccessParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonAccessParser.java index c2be9126993..12a6f24875c 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonAccessParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonAccessParser.java @@ -71,6 +71,12 @@ public WayAccess getAccess(ReaderWay way) { return WayAccess.CAN_SKIP; } + String mtbScale = way.getTag("mtb:scale"); + if (mtbScale != null) { + if (!isMtbScaleAllowed(mtbScale)) + return WayAccess.CAN_SKIP; + } + // use the way for pushing if (way.hasTag("bicycle", "dismount")) return WayAccess.WAY; @@ -105,6 +111,11 @@ boolean isSacScaleAllowed(String sacScale) { return "hiking".equals(sacScale); } + boolean isMtbScaleAllowed(String mtbScale) { + // keep even more difficult accessible as one may push, see https://wiki.openstreetmap.org/wiki/Key:mtb:scale + return "0".equals(mtbScale) || "1".equals(mtbScale) || "2".equals(mtbScale); + } + @Override public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way) { WayAccess access = getAccess(way); diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAccessParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAccessParser.java index 64e855ec308..87de9a011b0 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAccessParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikeAccessParser.java @@ -25,4 +25,10 @@ boolean isSacScaleAllowed(String sacScale) { return "hiking".equals(sacScale) || "mountain_hiking".equals(sacScale) || "demanding_mountain_hiking".equals(sacScale) || "alpine_hiking".equals(sacScale); } + + @Override + boolean isMtbScaleAllowed(String mtbScale) { + return !"6".equals(mtbScale); + } + } diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/AbstractBikeTagParserTester.java b/core/src/test/java/com/graphhopper/routing/util/parsers/AbstractBikeTagParserTester.java index 7f415ddc62a..6e2ef175d59 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/AbstractBikeTagParserTester.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/AbstractBikeTagParserTester.java @@ -25,14 +25,10 @@ import com.graphhopper.routing.util.OSMParsers; import com.graphhopper.routing.util.PriorityCode; import com.graphhopper.storage.IntsRef; -import com.graphhopper.util.Helper; import com.graphhopper.util.PMap; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.text.DateFormat; -import java.util.Date; - import static com.graphhopper.routing.util.PriorityCode.*; import static org.junit.jupiter.api.Assertions.*; @@ -373,17 +369,25 @@ public void testSteps() { } @Test - public void testSacScale() { + public void testSacScaleAccess() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "service"); way.setTag("sac_scale", "hiking"); - // allow assertTrue(accessParser.getAccess(way).isWay()); - way.setTag("sac_scale", "alpine_hiking"); assertTrue(accessParser.getAccess(way).canSkip()); } + @Test + public void testMtbScaleAccess() { + ReaderWay way = new ReaderWay(1); + way.setTag("highway", "path"); + way.setTag("mtb:scale", "0"); + assertTrue(accessParser.getAccess(way).isWay()); + way.setTag("mtb:scale", "3"); + assertTrue(accessParser.getAccess(way).canSkip()); + } + @Test public void testReduceToMaxSpeed() { ReaderWay way = new ReaderWay(12); diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/BikeTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/BikeTagParserTest.java index e0e1435c978..9dede166839 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/BikeTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/BikeTagParserTest.java @@ -528,7 +528,7 @@ public void testUnchangedRelationShouldNotInfluencePriority() { @Test @Override - public void testSacScale() { + public void testSacScaleAccess() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "path"); way.setTag("sac_scale", "hiking"); diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/MountainBikeTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/MountainBikeTagParserTest.java index 246444384f7..7e627382bb9 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/MountainBikeTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/MountainBikeTagParserTest.java @@ -135,7 +135,7 @@ public void testSmoothness() { @Test @Override - public void testSacScale() { + public void testSacScaleAccess() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "service"); way.setTag("sac_scale", "hiking"); @@ -152,6 +152,19 @@ public void testSacScale() { assertTrue(accessParser.getAccess(way).canSkip()); } + @Test + @Override + public void testMtbScaleAccess() { + ReaderWay way = new ReaderWay(1); + way.setTag("highway", "path"); + way.setTag("mtb:scale", "0"); + assertTrue(accessParser.getAccess(way).isWay()); + way.setTag("mtb:scale", "5"); + assertTrue(accessParser.getAccess(way).isWay()); + way.setTag("mtb:scale", "6"); + assertTrue(accessParser.getAccess(way).canSkip()); + } + @Test public void testHandleWayTagsInfluencedByBikeAndMtbRelation() { ReaderWay osmWay = new ReaderWay(1); diff --git a/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java b/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java index fe83bc27499..ac7b952380a 100644 --- a/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java +++ b/core/src/test/java/com/graphhopper/routing/util/parsers/RacingBikeTagParserTest.java @@ -111,7 +111,7 @@ public void testTrack() { @Test @Override - public void testSacScale() { + public void testSacScaleAccess() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "service"); way.setTag("sac_scale", "mountain_hiking"); @@ -128,6 +128,14 @@ public void testSacScale() { assertTrue(accessParser.getAccess(way).canSkip()); } + @Test + @Override + public void testMtbScaleAccess() { + // Intentionally use the same accessibility as ordinary bikes as pushing a racebike is easier + // compared to an ordinary bike. The problem is more the shoes, which makes the situation comparable + super.testMtbScaleAccess(); + } + @Test public void testGetSpeed() { EdgeIntAccess edgeIntAccess = ArrayEdgeIntAccess.createFromBytes(encodingManager.getBytesForFlags());