Skip to content

Commit

Permalink
Split out an osm2lanes crate for #224
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Oct 3, 2023
1 parent c098792 commit ddc2675
Show file tree
Hide file tree
Showing 23 changed files with 103 additions and 71 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"experimental",
"osm2lanes",
"osm2streets",
"osm2streets-java",
"osm2streets-js",
Expand Down
11 changes: 11 additions & 0 deletions osm2lanes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "osm2lanes"
version = "0.1.0"
edition = "2021"

[dependencies]
abstutil = { git = "https://github.com/a-b-street/abstreet" }
anyhow = { workspace = true }
enumset = { version = "1.0.12", features=["serde"] }
geom = { git = "https://github.com/a-b-street/abstreet" }
serde = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::iter;
use abstutil::Tags;
use geom::Distance;

use crate::lanes::TurnDirection;
use crate::{osm, BufferType, Direction, DrivingSide, LaneSpec, LaneType, MapConfig};
use crate::{
osm, BufferType, Direction, DrivingSide, LaneSpec, LaneType, MapConfig, TurnDirection,
};

/// Purely from OSM tags, determine the lanes that a road segment has.
pub fn get_lane_specs_ltr(tags: &Tags, cfg: &MapConfig) -> Vec<LaneSpec> {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 55 additions & 1 deletion osm2streets/src/lanes/mod.rs → osm2lanes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#[macro_use]
extern crate anyhow;

mod algorithm;
mod edit;
pub mod osm;
mod placement;
#[cfg(test)]
mod tests;
Expand All @@ -11,7 +16,6 @@ use serde::{Deserialize, Serialize};

use geom::Distance;

use crate::DrivingSide;
pub use algorithm::get_lane_specs_ltr;

pub const NORMAL_LANE_THICKNESS: Distance = Distance::const_meters(3.0);
Expand Down Expand Up @@ -537,3 +541,53 @@ pub enum Placement {
/// Varying linearly from some unspecified position at the start, to a different one at the end.
Transition,
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
pub enum DrivingSide {
Right,
Left,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MapConfig {
/// If true, driving happens on the right side of the road (USA). If false, on the left
/// (Australia).
///
/// Note this is calculated by osm2streets! The value passed in is ignored; don't do any work
/// to set it.
pub driving_side: DrivingSide,
/// The [two-letter ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) where
/// this network exists. Note osm2streets doesn't support areas that cross country boundaries.
///
/// Note this is calculated by osm2streets! The value passed in is ignored; don't do any work
/// to set it.
pub country_code: String,
pub bikes_can_use_bus_lanes: bool,
/// If true, roads without explicitly tagged sidewalks may be assigned sidewalks or shoulders.
/// If false, no inference will occur and separate sidewalks and crossings will be included.
pub inferred_sidewalks: bool,
/// Street parking is divided into spots of this length. 8 meters is a reasonable default, but
/// people in some regions might be more accustomed to squeezing into smaller spaces. This
/// value can be smaller than the hardcoded maximum car length; cars may render on top of each
/// other, but otherwise the simulation doesn't care.
pub street_parking_spot_length: Distance,
/// If true, turns on red which do not conflict crossing traffic ('right on red') are allowed
pub turn_on_red: bool,
/// OSM railway=rail will be included as light rail if so. Cosmetic only.
pub include_railroads: bool,
}

impl MapConfig {
pub fn default() -> Self {
Self {
// Just a dummy value that'll be set later
driving_side: DrivingSide::Right,
country_code: String::new(),
bikes_can_use_bus_lanes: true,
inferred_sidewalks: false,
street_parking_spot_length: Distance::meters(8.0),
turn_on_red: true,
include_railroads: true,
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions osm2streets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ geojson = "0.24.1"
geom = { git = "https://github.com/a-b-street/abstreet" }
itertools = "0.10.5"
log = "0.4.14"
osm2lanes = { path = "../osm2lanes" }
petgraph = { version = "0.6.3" }
serde = { workspace = true }
serde_json = { workspace = true }
2 changes: 1 addition & 1 deletion osm2streets/src/geometry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl InputRoad {
layer: 0,
speed_limit: None,
reference_line: PolyLine::dummy(),
reference_line_placement: crate::lanes::Placement::Transition,
reference_line_placement: osm2lanes::Placement::Transition,
trim_start: Distance::ZERO,
trim_end: Distance::ZERO,
turn_restrictions: Vec::new(),
Expand Down
4 changes: 3 additions & 1 deletion osm2streets/src/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use abstutil::{deserialize_btreemap, serialize_btreemap};
use geom::{Circle, Distance, Polygon, Pt2D};
use serde::{Deserialize, Serialize};

use crate::{osm, DrivingSide, IntersectionID, RoadID, StreetNetwork};
use osm2lanes::osm;

use crate::{DrivingSide, IntersectionID, RoadID, StreetNetwork};
use TrafficConflict::*;

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
Expand Down
15 changes: 7 additions & 8 deletions osm2streets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@ pub use self::ids::{CommonEndpoint, IntersectionID, LaneID, RoadID};
pub use self::intersection::{
Intersection, IntersectionControl, IntersectionKind, Movement, TrafficConflict,
};
pub use self::lanes::{
get_lane_specs_ltr, BufferType, Direction, LaneSpec, LaneType, Placement,
NORMAL_LANE_THICKNESS, SIDEWALK_THICKNESS,
};
pub use self::operations::zip_sidepath::Sidepath;
pub use self::render::Filter;
pub use self::road::{Road, StopLine, TrafficInterruption};
pub use self::transform::Transformation;
pub use self::types::{DrivingSide, MapConfig, NamePerLanguage};
pub use self::types::NamePerLanguage;

// Re-export osm2lanes types for an easier refactor. TODO Stop doing this.
pub use osm2lanes::{
get_lane_specs_ltr, osm, BufferType, Direction, DrivingSide, LaneSpec, LaneType, MapConfig,
Placement, NORMAL_LANE_THICKNESS, SIDEWALK_THICKNESS,
};

mod edit;
mod geometry;
mod ids;
mod intersection;
mod lanes;
mod marking;
mod operations;
pub mod osm;
mod output;
mod paint;
mod pathfinding;
Expand Down
3 changes: 1 addition & 2 deletions osm2streets/src/marking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use enumset::EnumSet;
// We use geom and stay in map space. Output is done in latlon.
use geom::{Angle, Line, PolyLine, Polygon, Pt2D};

use crate::lanes::{TrafficClass, TurnDirection};
use crate::LaneType;
use osm2lanes::{LaneType, TrafficClass, TurnDirection};

/// A marking painted on the road surface to direct traffic.
pub enum RoadMarking {
Expand Down
3 changes: 2 additions & 1 deletion osm2streets/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::{BufferType, Direction, LaneType, Placement, StreetNetwork, TrafficIn
use geo::MapCoordsInPlace;
use geom::{Distance, Line, Pt2D};

use crate::lanes::{RoadPosition, TrafficClass};
use osm2lanes::{RoadPosition, TrafficClass};

use crate::marking::{LongitudinalLine, RoadMarking, Transverse};
use crate::paint::PaintArea;

Expand Down
2 changes: 1 addition & 1 deletion osm2streets/src/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{marking, marking::RoadMarking};
// We use geom and stay in map space. Output is done in latlon.
use geom::{Angle, Distance, Line, PolyLine, Polygon, Pt2D, Ring};

use crate::lanes::TrafficClass;
use osm2lanes::TrafficClass;

#[derive(Clone, Debug, PartialEq)]
pub struct PaintArea {
Expand Down
5 changes: 3 additions & 2 deletions osm2streets/src/road.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use serde::{Deserialize, Serialize};
use abstutil::Tags;
use geom::{Angle, Distance, PolyLine, Speed};

use crate::lanes::RoadPosition;
use osm2lanes::{osm, RoadPosition};

use crate::{
get_lane_specs_ltr, osm, CommonEndpoint, Direction, DrivingSide, InputRoad, IntersectionID,
get_lane_specs_ltr, CommonEndpoint, Direction, DrivingSide, InputRoad, IntersectionID,
LaneSpec, LaneType, MapConfig, Placement, RestrictionType, RoadID, RoadWithEndpoints,
StreetNetwork,
};
Expand Down
3 changes: 2 additions & 1 deletion osm2streets/src/transform/sausage_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::collections::BTreeSet;

use geom::PolyLine;

use crate::lanes::RoadPosition;
use osm2lanes::RoadPosition;

use crate::{
BufferType, Direction, DrivingSide, LaneSpec, LaneType, Placement, RoadID, StreetNetwork,
};
Expand Down
51 changes: 0 additions & 51 deletions osm2streets/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};

use abstutil::{deserialize_btreemap, serialize_btreemap, Tags};
use geom::Distance;

/// None corresponds to the native name
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
Expand Down Expand Up @@ -47,53 +46,3 @@ impl NamePerLanguage {
self.0.keys().flatten().collect()
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct MapConfig {
/// If true, driving happens on the right side of the road (USA). If false, on the left
/// (Australia).
///
/// Note this is calculated by osm2streets! The value passed in is ignored; don't do any work
/// to set it.
pub driving_side: DrivingSide,
/// The [two-letter ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) where
/// this network exists. Note osm2streets doesn't support areas that cross country boundaries.
///
/// Note this is calculated by osm2streets! The value passed in is ignored; don't do any work
/// to set it.
pub country_code: String,
pub bikes_can_use_bus_lanes: bool,
/// If true, roads without explicitly tagged sidewalks may be assigned sidewalks or shoulders.
/// If false, no inference will occur and separate sidewalks and crossings will be included.
pub inferred_sidewalks: bool,
/// Street parking is divided into spots of this length. 8 meters is a reasonable default, but
/// people in some regions might be more accustomed to squeezing into smaller spaces. This
/// value can be smaller than the hardcoded maximum car length; cars may render on top of each
/// other, but otherwise the simulation doesn't care.
pub street_parking_spot_length: Distance,
/// If true, turns on red which do not conflict crossing traffic ('right on red') are allowed
pub turn_on_red: bool,
/// OSM railway=rail will be included as light rail if so. Cosmetic only.
pub include_railroads: bool,
}

impl MapConfig {
pub fn default() -> Self {
Self {
// Just a dummy value that'll be set later
driving_side: DrivingSide::Right,
country_code: String::new(),
bikes_can_use_bus_lanes: true,
inferred_sidewalks: false,
street_parking_spot_length: Distance::meters(8.0),
turn_on_red: true,
include_railroads: true,
}
}
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
pub enum DrivingSide {
Right,
Left,
}

0 comments on commit ddc2675

Please sign in to comment.