pub fn vehicle_cost(
    dr: DirectedRoadID,
    mvmnt: MovementID,
    constraints: PathConstraints,
    params: &RoutingParams,
    map: &Map,
) -> Duration {
    // TODO Creating the consolidated polyline sometimes fails. It's rare, so just workaround
    // temporarily by pretending the turn is 1m long.
    let (mvmnt_length, mvmnt_turn_type) = mvmnt
        .get(map)
        .map(|m| (m.geom.length(), m.turn_type))
        .unwrap_or((Distance::meters(1.0), TurnType::Straight));
    let max_speed = match constraints {
        PathConstraints::Car | PathConstraints::Bus | PathConstraints::Train => None,
        PathConstraints::Bike => Some(crate::MAX_BIKE_SPEED),
        PathConstraints::Pedestrian => unreachable!(),
    };
    let t1 = map.get_r(dr.id).center_pts.length()
        / Traversable::max_speed_along_road(dr, max_speed, constraints, map).0;
    let t2 =
        mvmnt_length / Traversable::max_speed_along_movement(mvmnt, max_speed, constraints, map);

    let base = match constraints {
        PathConstraints::Car | PathConstraints::Train => t1 + t2,
        PathConstraints::Bike => {
            // TODO If we're on a driving lane, higher speed limit is worse.
            // TODO Bike lanes next to parking is dangerous.

            // TODO Prefer bike lanes, then bus lanes, then driving lanes. For now, express that by
            // multiplying the base cost.
            let lt_penalty = if dr.has_lanes(LaneType::Biking, map) {
                params.bike_lane_penalty
            } else if dr.has_lanes(LaneType::Bus, map) {
                params.bus_lane_penalty
            } else {
                params.driving_lane_penalty
            };

            lt_penalty * (t1 + t2)
        }
        PathConstraints::Bus => {
            // Like Car, but prefer bus lanes.
            let lt_penalty = if dr.has_lanes(LaneType::Bus, map) {
                1.0
            } else {
                1.1
            };
            lt_penalty * (t1 + t2)
        }
        PathConstraints::Pedestrian => unreachable!(),
    };

    // Penalize unprotected turns at a stop sign from smaller to larger roads.
    let unprotected_turn_type = if map.get_config().driving_side == DrivingSide::Right {
        TurnType::Left
    } else {
        TurnType::Right
    };
    let rank_from = map.get_r(dr.id).get_detailed_rank();
    let rank_to = map.get_r(mvmnt.to.id).get_detailed_rank();
    if mvmnt_turn_type == unprotected_turn_type
        && rank_from < rank_to
        && map.get_i(mvmnt.parent).is_stop_sign()
    {
        base + params.unprotected_turn_penalty
    } else {
        base
    }
}
/// This returns the pathfinding cost of crossing one road and turn. This is also expressed in
/// units of time. It factors in the ideal time to cross the space, along with penalties for
/// entering an access-restricted zone, taking an unprotected turn, and so on.
This returns the pathfinding cost of crossing one road and turn. This is also expressed in
units of time. It factors in the ideal time to cross the space, along with penalties for
entering an access-restricted zone, taking an unprotected turn, and so on.
This returns the pathfinding cost of crossing one road and turn . This is also expressed in units of time . It factors in the ideal time to cross the space along with penalties for entering an access - restricted zone taking an unprotected turn and so on .
pub fn vehicle_cost(
    dr: DirectedRoadID,
    mvmnt: MovementID,
    constraints: PathConstraints,
    params: &RoutingParams,
    map: &Map,
) -> Duration {
    // TODO Creating the consolidated polyline sometimes fails. It's rare, so just workaround
    // temporarily by pretending the turn is 1m long.
    let (mvmnt_length, mvmnt_turn_type) = mvmnt
        .get(map)
        .map(|m| (m.geom.length(), m.turn_type))
        .unwrap_or((Distance::meters(1.0), TurnType::Straight));
    let max_speed = match constraints {
        PathConstraints::Car | PathConstraints::Bus | PathConstraints::Train => None,
        PathConstraints::Bike => Some(crate::MAX_BIKE_SPEED),
        PathConstraints::Pedestrian => unreachable!(),
    };
    let t1 = map.get_r(dr.id).center_pts.length()
        / Traversable::max_speed_along_road(dr, max_speed, constraints, map).0;
    let t2 =
        mvmnt_length / Traversable::max_speed_along_movement(mvmnt, max_speed, constraints, map);
    let base = match constraints {
        PathConstraints::Car | PathConstraints::Train => t1 + t2,
        PathConstraints::Bike => {
            // TODO If we're on a driving lane, higher speed limit is worse.
            // TODO Bike lanes next to parking is dangerous.
            // TODO Prefer bike lanes, then bus lanes, then driving lanes. For now, express that by
            // multiplying the base cost.
            let lt_penalty = if dr.has_lanes(LaneType::Biking, map) {
                params.bike_lane_penalty
            } else if dr.has_lanes(LaneType::Bus, map) {
                params.bus_lane_penalty
            } else {
                params.driving_lane_penalty
            };
            lt_penalty * (t1 + t2)
        }
        PathConstraints::Bus => {
            // Like Car, but prefer bus lanes.
            let lt_penalty = if dr.has_lanes(LaneType::Bus, map) {
                1.0
            } else {
                1.1
            };
            lt_penalty * (t1 + t2)
        }
        PathConstraints::Pedestrian => unreachable!(),
    };
    // Penalize unprotected turns at a stop sign from smaller to larger roads.
    let unprotected_turn_type = if map.get_config().driving_side == DrivingSide::Right {
        TurnType::Left
    } else {
        TurnType::Right
    };
    let rank_from = map.get_r(dr.id).get_detailed_rank();
    let rank_to = map.get_r(mvmnt.to.id).get_detailed_rank();
    if mvmnt_turn_type == unprotected_turn_type
        && rank_from < rank_to
        && map.get_i(mvmnt.parent).is_stop_sign()
    {
        base + params.unprotected_turn_penalty
    } else {
        base
    }
}
pub fn vehicle_cost ( dr : DirectedRoadID , mvmnt : MovementID , constraints : PathConstraints , params : & RoutingParams , map : & Map , ) -> Duration { // TODO Creating the consolidated polyline sometimes fails. It's rare, so just workaround // temporarily by pretending the turn is 1m long. let ( mvmnt_length , mvmnt_turn_type ) = mvmnt . get ( map ) . map ( | m | ( m . geom . length ( ) , m . turn_type ) ) . unwrap_or ( ( Distance :: meters ( 1.0 ) , TurnType :: Straight ) ) ; let max_speed = match constraints { PathConstraints :: Car | PathConstraints :: Bus | PathConstraints :: Train => None , PathConstraints :: Bike => Some ( crate :: MAX_BIKE_SPEED ) , PathConstraints :: Pedestrian => unreachable ! ( ) , } ; let t1 = map . get_r ( dr . id ) . center_pts . length ( ) / Traversable :: max_speed_along_road ( dr , max_speed , constraints , map ) . 0 ; let t2 = mvmnt_length / Traversable :: max_speed_along_movement ( mvmnt , max_speed , constraints , map ) ; let base = match constraints { PathConstraints :: Car | PathConstraints :: Train => t1 + t2 , PathConstraints :: Bike => { // TODO If we're on a driving lane, higher speed limit is worse. // TODO Bike lanes next to parking is dangerous. // TODO Prefer bike lanes, then bus lanes, then driving lanes. For now, express that by // multiplying the base cost. let lt_penalty = if dr . has_lanes ( LaneType :: Biking , map ) { params . bike_lane_penalty } else if dr . has_lanes ( LaneType :: Bus , map ) { params . bus_lane_penalty } else { params . driving_lane_penalty } ; lt_penalty * ( t1 + t2 ) } PathConstraints :: Bus => { // Like Car, but prefer bus lanes. let lt_penalty = if dr . has_lanes ( LaneType :: Bus , map ) { 1.0 } else { 1.1 } ; lt_penalty * ( t1 + t2 ) } PathConstraints :: Pedestrian => unreachable ! ( ) , } ; // Penalize unprotected turns at a stop sign from smaller to larger roads. let unprotected_turn_type = if map . get_config ( ) . driving_side == DrivingSide :: Right { TurnType :: Left } else { TurnType :: Right } ; let rank_from = map . get_r ( dr . id ) . get_detailed_rank ( ) ; let rank_to = map . get_r ( mvmnt . to . id ) . get_detailed_rank ( ) ; if mvmnt_turn_type == unprotected_turn_type && rank_from < rank_to && map . get_i ( mvmnt . parent ) . is_stop_sign ( ) { base + params . unprotected_turn_penalty } else { base } }
This returns the pathfinding cost of crossing one road and turn.
This returns the pathfinding cost of crossing one road and turn .
dr
DirectedRoadID
mvmnt
MovementID
constraints
PathConstraints
params
&RoutingParams
map
&Map