-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from NREL/ndr/turn-access-cost
Turn Access Cost
- Loading branch information
Showing
16 changed files
with
422 additions
and
188 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# exit on failure | ||
set -e | ||
|
||
cd rust/ | ||
|
||
cargo publish -p routee-compass-core --dry-run | ||
cargo publish -p routee-compass-core | ||
|
||
cargo publish -p routee-compass-powertrain --dry-run | ||
cargo publish -p routee-compass-powertrain | ||
|
||
cargo publish -p routee-compass --dry-run | ||
cargo publish -p routee-compass | ||
|
||
cargo publish -p routee-compass-py --dry-run | ||
cargo publish -p routee-compass-py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
rust/routee-compass-core/src/model/road_network/edge_heading.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Copy, Clone, Deserialize)] | ||
pub struct EdgeHeading { | ||
start_heading: i16, | ||
end_heading: Option<i16>, | ||
} | ||
|
||
impl EdgeHeading { | ||
pub fn with_start_and_end(start_heading: i16, end_heading: i16) -> Self { | ||
Self { | ||
start_heading, | ||
end_heading: Some(end_heading), | ||
} | ||
} | ||
|
||
pub fn with_start(start_heading: i16) -> Self { | ||
Self { | ||
start_heading, | ||
end_heading: None, | ||
} | ||
} | ||
|
||
pub fn start_heading(&self) -> i16 { | ||
self.start_heading | ||
} | ||
/// If the end heading is not specified, it is assumed to be the same as the start heading | ||
pub fn end_heading(&self) -> i16 { | ||
match self.end_heading { | ||
Some(end_heading) => end_heading, | ||
None => self.start_heading, | ||
} | ||
} | ||
/// Compute the angle between this edge and the next edge | ||
pub fn next_edge_angle(&self, next_edge_heading: &EdgeHeading) -> i16 { | ||
let angle = next_edge_heading.start_heading() - self.end_heading(); | ||
if angle > 180 { | ||
angle - 360 | ||
} else if angle < -180 { | ||
angle + 360 | ||
} else { | ||
angle | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_next_edge_angle() { | ||
let edge_heading = EdgeHeading::with_start_and_end(45, 90); | ||
let next_edge_heading = EdgeHeading::with_start_and_end(90, 135); | ||
assert_eq!(edge_heading.next_edge_angle(&next_edge_heading), 0); | ||
} | ||
|
||
#[test] | ||
fn test_next_edge_angle_wrap() { | ||
let edge_heading = EdgeHeading::with_start_and_end(10, 10); | ||
let next_edge_heading = EdgeHeading::with_start_and_end(350, 350); | ||
assert_eq!(edge_heading.next_edge_angle(&next_edge_heading), -20); | ||
|
||
let edge_heading = EdgeHeading::with_start_and_end(350, 350); | ||
let next_edge_heading = EdgeHeading::with_start_and_end(10, 10); | ||
assert_eq!(edge_heading.next_edge_angle(&next_edge_heading), 20); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub mod edge_heading; | ||
pub mod edge_id; | ||
pub mod edge_loader; | ||
pub mod graph; | ||
pub mod graph_error; | ||
pub mod graph_loader; | ||
pub mod turn; | ||
pub mod vertex_id; | ||
pub mod vertex_loader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use super::graph_error::GraphError; | ||
|
||
pub enum Turn { | ||
NoTurn, | ||
SlightRight, | ||
SlightLeft, | ||
Right, | ||
Left, | ||
SharpRight, | ||
SharpLeft, | ||
UTurn, | ||
} | ||
|
||
impl Turn { | ||
pub fn from_angle(angle: i16) -> Result<Self, GraphError> { | ||
match angle { | ||
-180..=-160 => Ok(Turn::UTurn), | ||
-159..=-135 => Ok(Turn::SharpLeft), | ||
-134..=-45 => Ok(Turn::Left), | ||
-44..=-20 => Ok(Turn::SlightLeft), | ||
-19..=19 => Ok(Turn::NoTurn), | ||
20..=44 => Ok(Turn::SlightRight), | ||
45..=134 => Ok(Turn::Right), | ||
135..=159 => Ok(Turn::SharpRight), | ||
160..=180 => Ok(Turn::UTurn), | ||
_ => Err(GraphError::AttributeError( | ||
"Turn".to_string(), | ||
format!("Angle {} out of range of -180 to 180", angle), | ||
)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.