Skip to content

Commit 01ec845

Browse files
Merge pull request #105 from NatLabRockies/rjf/expected-maxspeed
Rjf/expected maxspeed
2 parents b495a41 + 6729aad commit 01ec845

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

rust/bambam-omf/src/collection/record/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use transportation_segment::{
1919
SegmentAccessType, SegmentClass, SegmentDestination, SegmentFullType, SegmentHeading,
2020
SegmentLengthUnit, SegmentMode, SegmentRecognized, SegmentSpeedLimit, SegmentSpeedUnit,
2121
SegmentSubclass, SegmentSubtype, SegmentUnit, SegmentUsing, SegmentVehicleComparator,
22-
SegmentVehicleDimension, TransportationSegmentRecord,
22+
SegmentVehicleDimension, SpeedLimitWithUnit, TransportationSegmentRecord,
2323
};
2424

2525
// Common structs and functions for many record types

rust/bambam-omf/src/collection/record/transportation_segment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@ impl SegmentSpeedLimit {
921921

922922
#[derive(Debug, Serialize, Deserialize, Clone)]
923923
pub struct SpeedLimitWithUnit {
924-
value: i32,
925-
unit: SegmentSpeedUnit,
924+
pub value: i32,
925+
pub unit: SegmentSpeedUnit,
926926
}
927927

928928
impl SpeedLimitWithUnit {

rust/bambam-omf/src/graph/segment_split.rs

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use routee_compass_core::model::network::{Edge, EdgeId, EdgeListId, Vertex, Vert
66

77
use 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

Comments
 (0)