Skip to content

Commit

Permalink
Allow all modes for oneway streets with cycleway=opposite
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed May 9, 2024
1 parent 13c4717 commit 47a00c1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,7 @@ public void populateProperties(WayPropertySet props) {
);

/* cycleway=opposite */
props.setProperties(
"highway=*;cycleway=opposite",
withModes(PEDESTRIAN_AND_BICYCLE).bicycleSafety(1, 1.4)
);
props.setProperties("highway=*;cycleway=opposite", withModes(ALL).bicycleSafety(1, 1.4));
props.setProperties("highway=service;cycleway=opposite", withModes(ALL).bicycleSafety(1.1));
props.setProperties(
"highway=residential;cycleway=opposite",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DefaultMapperTest {

private WayPropertySet wps;
private OsmTagMapper mapper;
float epsilon = 0.01f;
private final float DELTA = 0.01f;

@BeforeEach
public void setup() {
Expand All @@ -38,33 +38,33 @@ public void testCarSpeeds() {

way = new OSMWithTags();
way.addTag("maxspeed", "60");
assertTrue(within(kmhAsMs(60), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(60), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(60), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(60), wps.getCarSpeedForWay(way, true), DELTA));

way = new OSMWithTags();
way.addTag("maxspeed:forward", "80");
way.addTag("maxspeed:backward", "20");
way.addTag("maxspeed", "40");
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(20), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(20), wps.getCarSpeedForWay(way, true), DELTA));

way = new OSMWithTags();
way.addTag("maxspeed", "40");
way.addTag("maxspeed:lanes", "60|80|40");
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, true), DELTA));

way = new OSMWithTags();
way.addTag("maxspeed", "20");
way.addTag("maxspeed:motorcar", "80");
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, true), DELTA));

// test with english units
way = new OSMWithTags();
way.addTag("maxspeed", "35 mph");
assertTrue(within(kmhAsMs(35 * 1.609f), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(35 * 1.609f), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(35 * 1.609f), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(35 * 1.609f), wps.getCarSpeedForWay(way, true), DELTA));

// test with no maxspeed tags
wps = new WayPropertySet();
Expand All @@ -76,28 +76,28 @@ public void testCarSpeeds() {
way = new OSMWithTags();

// test default speeds
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, true), DELTA));

way.addTag("highway", "tertiary");
assertTrue(within(kmhAsMs(35), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(35), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(35), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(35), wps.getCarSpeedForWay(way, true), DELTA));

way = new OSMWithTags();
way.addTag("surface", "gravel");
assertTrue(within(kmhAsMs(10), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(10), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(10), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(10), wps.getCarSpeedForWay(way, true), DELTA));

way = new OSMWithTags();
way.addTag("highway", "motorway");
assertTrue(within(kmhAsMs(100), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(100), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(100), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(100), wps.getCarSpeedForWay(way, true), DELTA));

// make sure that 0-speed ways can't exist
way = new OSMWithTags();
way.addTag("maxspeed", "0");
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, true), epsilon));
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, false), DELTA));
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, true), DELTA));

assertSpeed(1.3889, "5");
assertSpeed(1.3889, "5 kmh");
Expand Down Expand Up @@ -144,7 +144,7 @@ void bicycleDiscouraged() {
var discouraged = WayTestData.southeastLaBonitaWay().addTag("bicycle", "discouraged");
var discouragedProps = wps.getDataForWay(discouraged);
assertEquals(ALL, discouragedProps.getPermission());
assertEquals(2.94, discouragedProps.bicycleSafety().forward(), epsilon);
assertEquals(2.94, discouragedProps.bicycleSafety().forward(), DELTA);
}

@Test
Expand All @@ -170,30 +170,36 @@ void bicycleUseSidepath() {
var useSidepath = WayTestData.southeastLaBonitaWay().addTag("bicycle", "use_sidepath");
var useSidepathProps = wps.getDataForWay(useSidepath);
assertEquals(ALL, useSidepathProps.getPermission());
assertEquals(4.9, useSidepathProps.bicycleSafety().forward(), epsilon);
assertEquals(4.9, useSidepathProps.bicycleSafety().forward(), DELTA);

var useSidepathForward = WayTestData
.southeastLaBonitaWay()
.addTag("bicycle:forward", "use_sidepath");
var useSidepathForwardProps = wps.getDataForWay(useSidepathForward);
assertEquals(ALL, useSidepathForwardProps.getPermission());
assertEquals(4.9, useSidepathForwardProps.bicycleSafety().forward(), epsilon);
assertEquals(0.98, useSidepathForwardProps.bicycleSafety().back(), epsilon);
assertEquals(4.9, useSidepathForwardProps.bicycleSafety().forward(), DELTA);
assertEquals(0.98, useSidepathForwardProps.bicycleSafety().back(), DELTA);

var useSidepathBackward = WayTestData
.southeastLaBonitaWay()
.addTag("bicycle:backward", "use_sidepath");
var useSidepathBackwardProps = wps.getDataForWay(useSidepathBackward);
assertEquals(ALL, useSidepathBackwardProps.getPermission());
assertEquals(0.98, useSidepathBackwardProps.bicycleSafety().forward(), epsilon);
assertEquals(4.9, useSidepathBackwardProps.bicycleSafety().back(), epsilon);
assertEquals(0.98, useSidepathBackwardProps.bicycleSafety().forward(), DELTA);
assertEquals(4.9, useSidepathBackwardProps.bicycleSafety().back(), DELTA);
}

@Test
void cyclewayOpposite() {
var street = WayTestData.oneWayLivingStreet();
assertEquals(wps.getDataForWay(street).getPermission(), ALL);
}

/**
* Test that two values are within epsilon of each other.
*/
private boolean within(float val1, float val2, float epsilon) {
return (Math.abs(val1 - val2) < epsilon);
private boolean within(float val1, float val2, float delta) {
return (Math.abs(val1 - val2) < delta);
}

/**
Expand All @@ -217,6 +223,6 @@ private SpeedPicker getSpeedPicker(String specifier, float speed) {
}

private void assertSpeed(double v, String s) {
assertEquals(v, wps.getMetersSecondFromSpeed(s), epsilon);
assertEquals(v, wps.getMetersSecondFromSpeed(s), DELTA);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,13 @@ public static OSMWithTags zooPlatform() {
way.addTag("usage", "tourism");
return way;
}

public static OSMWithTags oneWayLivingStreet() {
// https://www.openstreetmap.org/way/89300522
var way = new OSMWithTags();
way.addTag("highway", "living_street");
way.addTag("cycleway", "opposite");
way.addTag("oneway", "yes");
return way;
}
}

0 comments on commit 47a00c1

Please sign in to comment.