Skip to content

Commit

Permalink
Add support for bike mtb:scale accessability
Browse files Browse the repository at this point in the history
  • Loading branch information
ratrun committed Sep 7, 2024
1 parent 3610786 commit 2b75aa7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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());
Expand Down

0 comments on commit 2b75aa7

Please sign in to comment.