@@ -6,7 +6,7 @@ use routee_compass_core::model::network::{Edge, EdgeId, EdgeListId, Vertex, Vert
66
77use crate :: {
88 collection:: {
9- record:: SegmentHeading , OvertureMapsCollectionError , SegmentFullType ,
9+ record:: SegmentHeading , OvertureMapsCollectionError , SegmentFullType , SegmentSpeedLimit ,
1010 TransportationSegmentRecord ,
1111 } ,
1212 graph:: connector_in_segment:: ConnectorInSegment ,
@@ -216,14 +216,7 @@ impl SegmentSplit {
216216 // retain speed limits with no heading or with a matching heading
217217 let speed_limits_with_heading = speed_limits
218218 . iter ( )
219- . filter ( |s| match s. when . as_ref ( ) {
220- Some ( access) => match access. heading . as_ref ( ) {
221- None => true ,
222- Some ( h) if h == heading => true ,
223- _ => false ,
224- } ,
225- None => true ,
226- } )
219+ . filter ( |s| has_max_speed_for_heading ( s, heading) )
227220 . collect_vec ( ) ;
228221
229222 // Compute the intersecting portion of each limit
@@ -350,3 +343,55 @@ impl SegmentSplit {
350343 }
351344 }
352345}
346+
347+ /// helper function which confirms that speed data exists and that it matches the current heading
348+ fn has_max_speed_for_heading ( s : & SegmentSpeedLimit , heading : & SegmentHeading ) -> bool {
349+ // no max speed? return early
350+ if s. max_speed . as_ref ( ) . is_none ( ) {
351+ return false ;
352+ }
353+
354+ let when = match s. when . as_ref ( ) {
355+ Some ( w) => w,
356+ None => return true , // no access restrictions to apply
357+ } ;
358+
359+ match when. heading . as_ref ( ) {
360+ None => true , // no heading restrictions to apply
361+ Some ( h) if h == heading => true ,
362+ _ => false ,
363+ }
364+ }
365+
366+ #[ cfg( test) ]
367+ mod test {
368+ use crate :: collection:: {
369+ record:: { SegmentHeading , SpeedLimitWithUnit } ,
370+ SegmentAccessRestrictionWhen , SegmentSpeedLimit , SegmentSpeedUnit ,
371+ } ;
372+
373+ #[ test]
374+ fn no_maxspeed_entry ( ) {
375+ // unexpected case where the record has a min speed but no max speed
376+ let record = SegmentSpeedLimit {
377+ min_speed : Some ( SpeedLimitWithUnit {
378+ value : 35 ,
379+ unit : SegmentSpeedUnit :: Mph ,
380+ } ) ,
381+ max_speed : None ,
382+ is_max_speed_variable : None ,
383+ when : Some ( SegmentAccessRestrictionWhen {
384+ during : None ,
385+ heading : Some ( SegmentHeading :: Backward ) ,
386+ using : None ,
387+ recognized : None ,
388+ mode : None ,
389+ vehicle : None ,
390+ } ) ,
391+ between : Some ( vec ! [ 0.0 , 0.418244116 ] ) ,
392+ } ;
393+ let heading = SegmentHeading :: Forward ;
394+ let result = super :: has_max_speed_for_heading ( & record, & heading) ;
395+ assert ! ( !result)
396+ }
397+ }
0 commit comments