1- package org .heigit .ors .routing .graphhopper .extensions .storages . builders ;
1+ package org .heigit .ors .routing .graphhopper .extensions .util . parsers ;
22
33import com .graphhopper .reader .ReaderWay ;
4+ import com .graphhopper .routing .util .EncodingManager ;
5+ import com .graphhopper .storage .IntsRef ;
46import org .heigit .ors .routing .graphhopper .extensions .WheelchairAttributes ;
7+ import org .heigit .ors .routing .graphhopper .extensions .util .WheelchairAttributesEncodedValues ;
8+ import org .heigit .ors .routing .graphhopper .extensions .util .parsers .wheelchair .*;
59import org .junit .jupiter .api .BeforeEach ;
610import org .junit .jupiter .api .Test ;
7- import org .locationtech .jts .geom .Coordinate ;
8-
9- import java .util .HashMap ;
10- import java .util .Map ;
1111
1212import static org .junit .jupiter .api .Assertions .*;
1313
14- class WheelchairGraphStorageBuilderTest {
15- private WheelchairGraphStorageBuilder builder ;
16-
17- public WheelchairGraphStorageBuilderTest () {
18- builder = new WheelchairGraphStorageBuilder ();
14+ class WheelchairParserTest {
15+ private EncodingManager em ;
16+ private IntsRef intsRef , relFlags ;
17+
18+ private WheelchairSurfaceParser parserSurface ;
19+ private WheelchairSmoothnessParser parserSmoothness ;
20+ private WheelchairTrackTypeParser parserTrackType ;
21+ private WheelchairInclineParser parserIncline ;
22+ private WheelchairKerbHeightParser parserKerbHeight ;
23+ private WheelchairWidthParser parserWidth ;
24+ private WheelchairSuitableParser parserSuitable ;
25+ private WheelchairSurfaceQualityKnownParser parserSurfaceQualityKnown ;
26+ private WheelchairSideParser parserSide ;
27+
28+ public WheelchairParserTest () {
29+ setUp ();
1930 }
2031
2132 @ BeforeEach
22- void reset () {
23- builder = new WheelchairGraphStorageBuilder ();
33+ void setUp () {
34+ parserSurface = new WheelchairSurfaceParser ();
35+ parserSmoothness = new WheelchairSmoothnessParser ();
36+ parserTrackType = new WheelchairTrackTypeParser ();
37+ parserIncline = new WheelchairInclineParser ();
38+ parserKerbHeight = new WheelchairKerbHeightParser ();
39+ parserWidth = new WheelchairWidthParser ();
40+ parserSuitable = new WheelchairSuitableParser ();
41+ parserSurfaceQualityKnown = new WheelchairSurfaceQualityKnownParser ();
42+ parserSide = new WheelchairSideParser ();
43+
44+ em = new EncodingManager .Builder ()
45+ .add (parserSurface )
46+ .add (parserSmoothness )
47+ .add (parserTrackType )
48+ .add (parserIncline )
49+ .add (parserKerbHeight )
50+ .add (parserWidth )
51+ .add (parserSuitable )
52+ .add (parserSurfaceQualityKnown )
53+ .add (parserSide ).build ();
54+
55+ relFlags = em .createRelationFlags ();
56+ intsRef = em .createEdgeFlags ();
57+ }
58+
59+ void executeParsers (ReaderWay way ) {
60+ parserSurface .handleWayTags (intsRef , way , false , relFlags );
61+ parserSmoothness .handleWayTags (intsRef , way , false , relFlags );
62+ parserTrackType .handleWayTags (intsRef , way , false , relFlags );
63+ parserIncline .handleWayTags (intsRef , way , false , relFlags );
64+ parserKerbHeight .handleWayTags (intsRef , way , false , relFlags );
65+ parserWidth .handleWayTags (intsRef , way , false , relFlags );
66+ parserSuitable .handleWayTags (intsRef , way , false , relFlags );
67+ parserSurfaceQualityKnown .handleWayTags (intsRef , way , false , relFlags );
68+ parserSide .handleWayTags (intsRef , way , false , relFlags );
2469 }
2570
2671 @ Test
@@ -33,10 +78,11 @@ void TestProcessSeparateWay() {
3378 way .setTag ("smoothness" , "good" );
3479 way .setTag ("surface" , "asphalt" );
3580
81+ executeParsers (way );
3682
37- builder .processWay (way );
83+ WheelchairAttributesEncodedValues encValues = new WheelchairAttributesEncodedValues (em );
84+ WheelchairAttributes attrs = encValues .getAttributes (intsRef );
3885
39- WheelchairAttributes attrs = builder .getStoredAttributes (WheelchairGraphStorageBuilder .Side .NONE );
4086 assertEquals (50 , attrs .getWidth ());
4187 assertEquals (2 , attrs .getIncline ());
4288 assertEquals (3 , attrs .getSlopedKerbHeight ());
@@ -56,10 +102,11 @@ void TestPedestrianisedWay() {
56102 way .setTag ("tracktype" , "grade1" );
57103 way .setTag ("surface" , "asphalt" );
58104
105+ executeParsers (way );
59106
60- builder .processWay (way );
107+ WheelchairAttributesEncodedValues encValues = new WheelchairAttributesEncodedValues (em );
108+ WheelchairAttributes attrs = encValues .getAttributes (intsRef );
61109
62- WheelchairAttributes attrs = builder .getStoredAttributes (WheelchairGraphStorageBuilder .Side .NONE );
63110 assertEquals (50 , attrs .getWidth ());
64111 assertEquals (2 , attrs .getIncline ());
65112 assertEquals (2 , attrs .getSurfaceType ());
@@ -71,26 +118,28 @@ void TestPedestrianisedWay() {
71118 @ Test
72119 void TestProcessWayWithLeftSidewalkAttached () {
73120 ReaderWay way = constructSidedWay ("left" );
74- builder .processWay (way );
75- WheelchairAttributes attrs = builder .getStoredAttributes (WheelchairGraphStorageBuilder .Side .LEFT );
121+ executeParsers (way );
122+ WheelchairAttributesEncodedValues encValues = new WheelchairAttributesEncodedValues (em );
123+ WheelchairAttributes attrs = encValues .getAttributes (intsRef );
76124 assertAttributeValues (attrs );
77125 }
78126
79127 @ Test
80128 void TestProcessWayWithRightSidewalkAttached () {
81129 ReaderWay way = constructSidedWay ("right" );
82- builder .processWay (way );
83- WheelchairAttributes attrs = builder .getStoredAttributes (WheelchairGraphStorageBuilder .Side .RIGHT );
130+ executeParsers (way );
131+ WheelchairAttributesEncodedValues encValues = new WheelchairAttributesEncodedValues (em );
132+ WheelchairAttributes attrs = encValues .getAttributes (intsRef );
84133 assertAttributeValues (attrs );
85134 }
86135
87136 @ Test
88137 void TestProcessWayWithBothSidewalksAttached () {
89138 ReaderWay way = constructSidedWay ("both" );
90- builder .processWay (way );
91- WheelchairAttributes attrs = builder .getStoredAttributes (WheelchairGraphStorageBuilder .Side .RIGHT );
139+ WheelchairAttributes attrs = parseForSide (way , "right" );
92140 assertAttributeValues (attrs );
93- attrs = builder .getStoredAttributes (WheelchairGraphStorageBuilder .Side .LEFT );
141+
142+ attrs = parseForSide (way , "left" );
94143 assertAttributeValues (attrs );
95144 }
96145
@@ -121,62 +170,35 @@ void TestProcessWayWithMultipleValues() {
121170 assertFalse (correctWheelchairAttributes .isSurfaceQualityKnown ());
122171 assertFalse (correctWheelchairAttributes .isSuitable ());
123172
124- builder .processWay (way );
125- WheelchairAttributes left_attrs = builder .getStoredAttributes (WheelchairGraphStorageBuilder .Side .LEFT );
173+ WheelchairAttributes left_attrs = parseForSide (way , "left" );
126174 assertTrue (left_attrs .isSurfaceQualityKnown ());
127175 assertTrue (left_attrs .isSuitable ());
176+ assertEquals (60 , left_attrs .getWidth ());
177+ assertEquals (5 , left_attrs .getIncline ());
178+ assertEquals (1 , left_attrs .getSlopedKerbHeight ());
128179
129- WheelchairAttributes right_attrs = builder . getStoredAttributes ( WheelchairGraphStorageBuilder . Side . RIGHT );
180+ WheelchairAttributes right_attrs = parseForSide ( way , "right" );
130181 assertTrue (right_attrs .isSurfaceQualityKnown ());
131182 assertTrue (right_attrs .isSuitable ());
183+ assertEquals (50 , right_attrs .getWidth ());
184+ assertEquals (2 , right_attrs .getIncline ());
185+ assertEquals (3 , right_attrs .getSlopedKerbHeight ());
132186
133- WheelchairAttributes attrs = builder .combineAttributesOfWayWhenBothSidesPresent (new WheelchairAttributes ());
134- assertFalse (attrs .isSurfaceQualityKnown ());
135- assertFalse (attrs .isSuitable ());
136-
187+ WheelchairAttributes attrs = parseForSide (way , "both" );
137188 assertEquals (wheelchairAttributesAsString (correctWheelchairAttributes ), wheelchairAttributesAsString (attrs ));
138189 }
139190
140- @ Test
141- void TestKerbHeightFromNode () {
142- ReaderWay way = new ReaderWay (1 );
143-
144- way .setTag ("highway" , "crossing" );
145-
146- Map <Integer , Map <String , String >> nodeTags = new HashMap <>();
147- Map <String , String > tags = new HashMap <>();
148- tags .put ("kerb:height" , "0.03" );
149- nodeTags .put (1 , tags );
150-
151- builder .processWay (way , new Coordinate [0 ], nodeTags );
152-
153- assertEquals (3 , builder .getKerbHeightFromNodeTags ());
154- }
155-
156- @ Test
157- void TestAttachKerbHeightToCrossing () {
158- builder = new WheelchairGraphStorageBuilder (true );
159-
160- ReaderWay way = new ReaderWay (1 );
161-
162- way .setTag ("footway" , "crossing" );
163-
164- Map <Integer , Map <String , String >> nodeTags = new HashMap <>();
165- Map <String , String > tags = new HashMap <>();
166- tags .put ("kerb:height" , "0.03" );
167- nodeTags .put (1 , tags );
168-
169- builder .processWay (way , new Coordinate [0 ], nodeTags );
170-
171- assertEquals (3 , builder .getKerbHeightForEdge (way ));
172-
173- way = new ReaderWay (2 );
174-
175- way .setTag ("highway" , "footway" );
176-
177- builder .processWay (way , new Coordinate [0 ], nodeTags );
178-
179- assertEquals (-1 , builder .getKerbHeightForEdge (way ));
191+ private WheelchairAttributes parseForSide (ReaderWay way , String side ){
192+ assert (side .equals ("left" ) || side .equals ("right" ) || side .equals ("both" ));
193+ if (side .equals ("both" )) {
194+ way .removeTag ("ors-sidewalk-side" );
195+ } else {
196+ way .setTag ("ors-sidewalk-side" , side );
197+ }
198+
199+ executeParsers (way );
200+ WheelchairAttributesEncodedValues encValues = new WheelchairAttributesEncodedValues (em );
201+ return encValues .getAttributes (intsRef );
180202 }
181203
182204 private ReaderWay constructSidedWay (String side ) {
@@ -189,6 +211,7 @@ private ReaderWay constructSidedWay(String side) {
189211 way .setTag ("sidewalk:" + side + ":smoothness" , "good" );
190212 way .setTag ("sidewalk:" + side + ":surface" , "asphalt" );
191213 way .setTag ("sidewalk:" + side + ":tracktype" , "grade4" );
214+ way .setTag ("ors-sidewalk-side" , side );
192215
193216 return way ;
194217 }
0 commit comments