fn way_blob( state: &mut WayPass, block: &pbf::PrimitiveBlock, index: &NodeIndex, coords: &[geom::Pt], filter: RegionFilter, ) -> Result { let mut kinds = 0u8; visit_block(block, KIND_WAYS, &mut kinds, &mut |el: Element| { let Element::Way(w) = el else { return Ok(()); }; let type_ = tags::get_hw_id(w.tags.get_str("highway")); if type_ == 0 { return Ok(()); } // Region filter: keep the way when ANY node touches the box (the // `complete_ways` rule — truncating at the boundary would invent a // vertex). Coordinates are resolved by now, so this is a direct test. if let Some(b) = filter.as_ref() { let mut touches = false; for r in w.refs { if let Some(d) = index.dense(*r) { let (lat_e7, lon_e7) = coords[d as usize]; if b.contains_e7(lat_e7, lon_e7) { touches = true; break; } } } if !touches { return Ok(()); } } let attrs = way_attrs(&w, type_, &mut state.lanes, &mut state.names); for pair in w.refs.windows(2) { // The same predicate the within-way path uses, so the two collapse // paths agree on what a segment is. Asking a different question here // would make the reference path emit a zero-length self-loop for a // repeated ref, and the byte-identity comparison between the two would // stop meaning anything. let Some((u, v)) = chains::segment(index, pair[0], pair[1]) else { continue; }; let (a, b) = (coords[u as usize], coords[v as usize]); state.segs.push(Seg { u, v, dist_mm: accurate_dist_mm(a.0, a.1, b.0, b.1), name_offset: attrs.name, type_: attrs.type_, speed_limit: attrs.speed_limit, oneway: attrs.oneway, fwd_lane_off: attrs.fwd_lane_off, fwd_lane_count: attrs.fwd_lane_count, bwd_lane_off: attrs.bwd_lane_off, bwd_lane_count: attrs.bwd_lane_count, }); } Ok(()) })?; Ok(kinds) } /// Lane masks are pushed into `lanes` and the name interned into `names`, both /// chunk-local: the sink rebases the offsets when it folds the chunk in. pub(crate) fn way_attrs( w: &crate::osm::WayView, type_: u8, lanes: &mut Vec, names: &mut LocalNames, ) -> WayAttrs { let name = match w.tags.get("name") { Some(n) => names.id(n), None => u32::MAX, }; let speed_limit = tags::parse_maxspeed(w.tags.get_str("maxspeed")); let oneway = w.tags.get_str("oneway") == Some("yes"); // Forward lanes come from turn:lanes:forward, or from plain turn:lanes on a // oneway; backward from turn:lanes:backward. Plain `lanes*` only refine the // count. No turn:lanes at all means no lane data, and the router infers lanes // from junction topology instead. let tl = w.tags.get_str("turn:lanes"); let tlf = w.tags.get_str("turn:lanes:forward"); let tlb = w.tags.get_str("turn:lanes:backward"); let count_all = tags::parse_int_tag(w.tags.get_str("lanes")); let count_fwd = tags::parse_int_tag(w.tags.get_str("lanes:forward")); let count_bwd = tags::parse_int_tag(w.tags.get_str("lanes:backward")); let fwd_spec = tlf.or(if oneway { tl } else { None }); let fwd_hint = if count_fwd > 0 { count_fwd } else if oneway { count_all } else { 0 }; let bwd_spec = if oneway { None } else { tlb }; let fwd = tags::build_dir_lanes(fwd_spec, fwd_hint); let bwd = tags::build_dir_lanes(bwd_spec, count_bwd); let mut push_lanes = |masks: &[u16]| -> (u32, u16) { if masks.is_empty() { return (NO_LANES, 0); } let off = lanes.len() as u32; lanes.extend_from_slice(masks); (off, masks.len() as u16) }; let (fwd_lane_off, fwd_lane_count) = push_lanes(&fwd); let (bwd_lane_off, bwd_lane_count) = push_lanes(&bwd); WayAttrs { name, type_, speed_limit, oneway, fwd_lane_off, fwd_lane_count, bwd_lane_off, bwd_lane_count, } } fn pass2_blob(state: &mut Pass2, block: &pbf::PrimitiveBlock, mask: &Bitset) -> Result { let mut kinds = 0u8; visit_block(block, KIND_NODES, &mut kinds, &mut |el: Element| { if let Element::Node(n) = el { if n.id < 0 || n.id as u64 >= BITSET_SIZE || !mask.get(n.id as u64) { return Ok(()); } let dense = mask.dense(n.id as u64); // A `gtfs:stop_code:` tag means this node is a matched GTFS // stop; its `name` (or the code itself) becomes the stop label the // transit planner shows. Otherwise fall back to the plain OSM stop // tags. let gtfs_code = n .tags .iter() .find(|(k, _)| k.starts_with(b"gtfs:stop_code:")) .map(|(_, v)| n.tags.get("name").unwrap_or(v)); let stop_code = match gtfs_code { Some(code) => Some(code), None => tags::is_stop_node( n.tags.get_str("highway"), n.tags.get_str("railway"), n.tags.get_str("public_transport"), ) .then(|| n.tags.get("name").unwrap_or(UNNAMED_STOP)), }; state.locs.push((dense, n.lat_e7, n.lon_e7)); if let Some(code) = stop_code { state.stops.push((dense, code.to_vec())); } } Ok(()) })?; Ok(kinds) } /// What one stop-reconnection pass did, for [`Stats`] and for the log line that /// makes [`MIN_ROUTABLE_COMPONENT`] auditable. struct Reconnected { lcc_size: u64, /// Bidirectional connectors, sorted by `(source, target)`. synth: Vec, already_connected: usize, unreachable: usize, }