Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
main ▾

Modern-Apps.git / scripts / maps / mamaps_build / src / tiler_part8.rs

tiler_part8.rs209 lines · 9.5 KiBRaw
1#[cfg(test)]
2mod tests_part8 {
3 use super::*;
4 use super::tests::*;
5 use crate::schema::Class;
6 use tilecodec::mamaps::dict;
7 /// **The road/river name path, end to end.** A street's name survives the spill, the merge and
8 /// coalescing, and comes back interned in the tile's name table on the line feature — which is
9 #[test]
10 fn a_road_name_reaches_the_archive() {
11 let road = Feature {
12 class: Class::line(dict::LAYER_ROADS, crate::schema::kind("major_road"), 12),
13 geometry: Geometry::Lines(vec![vec![(-120.0, 35.0), (-119.98, 35.002)]]),
14 name: Some("Market Street".to_string()),
15 id: tilecodec::mamaps::body::ID_NONE,
16 transit_color: 0,
17 transit_ordinal: 0,
18 transit_lanes: 0,
19 transit_taper: 0,
20 lane_count: 0,
21 turn_fwd: Vec::new(),
22 turn_bwd: Vec::new(),
23 building: None,
24 carriageway: tilecodec::mamaps::body::Carriageway::default(),
25 };
26 let river = Feature {
27 class: Class::line(dict::LAYER_LANDTYPE, crate::schema::kind("river"), 12),
28 geometry: Geometry::Lines(vec![vec![(-120.0, 35.0), (-119.97, 35.004)]]),
29 name: Some("Los Gatos Creek".to_string()),
30 id: tilecodec::mamaps::body::ID_NONE,
31 transit_color: 0,
32 transit_ordinal: 0,
33 transit_lanes: 0,
34 transit_taper: 0,
35 lane_count: 0,
36 turn_fwd: Vec::new(),
37 turn_bwd: Vec::new(),
38 building: None,
39 carriageway: tilecodec::mamaps::body::Carriageway::default(),
40 };
41 let (bytes, _) = build(&spilled(&[road, river]), &settings(14, 14)).expect("build");
42 let entries = tilecodec::mamaps::read::read_all(&bytes).expect("read");
43 let (mut saw_road, mut saw_river) = (false, false);
44 for (_, _, body) in &entries {
45 let body = Body::parse(body).expect("parse");
46 if let Some(layer) = body.layer(dict::LAYER_ROADS) {
47 for f in &layer.features {
48 if f.name(&body) == Some("Market Street") {
49 saw_road = true;
50 }
51 }
52 }
53 if let Some(layer) = body.layer(dict::LAYER_LANDTYPE) {
54 for f in &layer.features {
55 if f.name(&body) == Some("Los Gatos Creek") {
56 saw_river = true;
57 }
58 }
59 }
60 }
61 assert!(saw_road, "the road's name should reach the archive");
62 assert!(saw_river, "the river's name should reach the archive");
63 }
64
65 #[test]
66 fn a_roads_turn_masks_reach_the_archive() {
67 use osm_ingest::tags::{LANE_LEFT, LANE_RIGHT, LANE_THROUGH};
68 let (fwd, _) = crate::schema::roads::turn_masks(
69 &[("highway", "primary"), ("oneway", "yes"), ("lanes", "3"),
70 ("turn:lanes", "left|through|through;right")][..],
71 );
72 let road = Feature {
73 class: Class::line(dict::LAYER_ROADS, crate::schema::kind("major_road"), 12),
74 geometry: Geometry::Lines(vec![vec![(-120.0, 35.0), (-119.99, 35.001)]]),
75 name: None,
76 id: tilecodec::mamaps::body::ID_NONE,
77 transit_color: 0,
78 transit_ordinal: 0,
79 transit_lanes: 0,
80 transit_taper: 0,
81 lane_count: 3,
82 turn_fwd: fwd,
83 turn_bwd: Vec::new(),
84 building: None,
85 carriageway: tilecodec::mamaps::body::Carriageway::default(),
86 };
87 let (bytes, _) = build(&spilled(&[road]), &settings(14, 14)).expect("build");
88 let entries = tilecodec::mamaps::read::read_all(&bytes).expect("read");
89 let mut seen = false;
90 for (_, _, body) in &entries {
91 let body = Body::parse(body).expect("parse");
92 let Some(layer) = body.layer(dict::LAYER_ROADS) else { continue };
93 for index in 0..layer.features.len() {
94 let Some(turns) = body.feature_turns(dict::LAYER_ROADS, index) else { continue };
95 if turns.is_empty() {
96 continue;
97 }
98 assert_eq!(
99 turns.forward,
100 vec![LANE_LEFT, LANE_THROUGH, LANE_THROUGH | LANE_RIGHT],
101 "the road's forward turn masks survive the archive",
102 );
103 assert!(turns.backward.is_empty(), "a oneway carries no backward masks");
104 seen = true;
105 }
106 }
107 assert!(seen, "at least one archived road tile carries the turn masks");
108 }
109
110 /// **The junction layer's coalesce opt-out, through the full tiler.** Every
111 /// connector shares one class (no kind, no detail), so coalescing would
112 /// chain unrelated movements — a left turn and the through beside it — into
113 /// one polyline and draw a ribbon between them. This pushes two touching
114 /// connectors and asserts each survives as its own feature, mirroring
115 /// `a_traffic_layer_keeps_one_id_per_segment_through_the_tiler` for the
116 /// traffic layer's neighbouring opt-out.
117 #[test]
118 fn a_junction_layer_keeps_one_connector_per_feature_through_the_tiler() {
119 use crate::schema::junction::junction_class;
120 // Two connectors meeting end to start at the junction mouth: exactly
121 // the shape a join would splice, and the shape a left turn beside a
122 // through movement takes.
123 let connector = |x0: f64, x1: f64| Feature {
124 class: junction_class(),
125 geometry: Geometry::Lines(vec![vec![(x0, 35.0), (x1, 35.0004)]]),
126 name: None,
127 id: tilecodec::mamaps::body::ID_NONE,
128 transit_color: 0,
129 transit_ordinal: 0,
130 transit_lanes: 0,
131 transit_taper: 0,
132 lane_count: 0,
133 turn_fwd: Vec::new(),
134 turn_bwd: Vec::new(),
135 building: None,
136 carriageway: tilecodec::mamaps::body::Carriageway::default(),
137 };
138 let features =
139 vec![connector(-120.0, -119.9996), connector(-119.9996, -119.9992)];
140 let (bytes, _) = build(&spilled(&features), &settings(14, 14)).expect("build");
141 let entries = tilecodec::mamaps::read::read_all(&bytes).expect("read");
142 let mut total = 0usize;
143 for (_, _, body) in &entries {
144 let body = Body::parse(body).expect("parse");
145 let Some(layer) = body.layer(dict::LAYER_JUNCTION) else { continue };
146 for feature in &layer.features {
147 assert_eq!(feature.geom_type, GEOM_LINE);
148 total += 1;
149 }
150 }
151 assert_eq!(
152 total, 2,
153 "coalescing chained the two connectors into one feature: \
154 delete the LAYER_JUNCTION opt-out in encode_batch and this fails",
155 );
156 }
157
158 /// **The traffic layer's one-id-per-segment invariant, through the full tiler.** Traffic
159 /// features share a class (no kind, no detail), so if the layer were coalesced like every
160 /// other line layer they would collapse into one feature and every segment's `component_id`
161 /// but the first would be lost. This pushes several distinct segments of one edge and asserts
162 /// each survives as its own feature with its own id, decoded back out of the archive.
163 #[test]
164 fn a_traffic_layer_keeps_one_id_per_segment_through_the_tiler() {
165 use crate::schema::traffic::{pack_component_id, traffic_class, unpack_component_id};
166 let mut features = Vec::new();
167 for seg in 0..8u32 {
168 // Spaced tightly so they land in the same z14 tile(s); each its own 2-point line.
169 let x = -120.0 + seg as f64 * 0.0005;
170 features.push(Feature {
171 class: traffic_class(),
172 geometry: Geometry::Lines(vec![vec![(x, 35.0), (x + 0.0004, 35.0004)]]),
173 name: None,
174 id: pack_component_id(7, seg),
175 transit_color: 0,
176 transit_ordinal: 0,
177 transit_lanes: 0,
178 transit_taper: 0,
179 lane_count: 0,
180 turn_fwd: Vec::new(),
181 turn_bwd: Vec::new(),
182 building: None,
183 carriageway: tilecodec::mamaps::body::Carriageway::default(),
184 });
185 }
186 let (bytes, _) = build(&spilled(&features), &settings(14, 14)).expect("build");
187 let entries = tilecodec::mamaps::read::read_all(&bytes).expect("read");
188 let mut seen: std::collections::BTreeSet<u32> = std::collections::BTreeSet::new();
189 let mut total = 0usize;
190 for (_, _, body) in &entries {
191 let body = Body::parse(body).expect("parse");
192 let Some(layer) = body.layer(dict::LAYER_TRAFFIC) else { continue };
193 for index in 0..layer.features.len() {
194 assert_eq!(layer.features[index].geom_type, GEOM_LINE);
195 let id = body
196 .feature_id(dict::LAYER_TRAFFIC, index)
197 .expect("the traffic layer must carry an id table");
198 let (edge, seg) = unpack_component_id(id);
199 assert_eq!(edge, 7, "a component_id must unpack to its source edge");
200 assert!(seg < 8, "seg_index {seg} is past what was pushed");
201 seen.insert(seg);
202 total += 1;
203 }
204 }
205 assert_eq!(seen.len(), 8, "coalescing collapsed the per-segment ids");
206 assert!(total >= 8, "feature count {total} is short of the segments pushed");
207 }
208
209}