/// **The v10 narrowed-record path, end to end.** Buildings (minimal /// records, no names/details/transit/lanes), roads (roads records) and /// landtype survive a v10 serialize/parse round trip with identical /// geometry, and the S3DB attrs survive the sparse table — through the /// same `Body` API the renderer reads. Bridge coverage until tilecodec's /// own test target builds again. #[test] fn a_v10_body_round_trips_narrowed_records_and_sparse_buildings() { use tilecodec::mamaps::body::{ serialize_into_v10, BuildingAttrs, Feature as BodyFeature, Layer as BodyLayer, Part, Scratch, GEOM_POLYGON, ROOF_GABLED, ROOF_ORIENT_ACROSS, WINDING_OUTER, }; let mut buildings = BodyLayer::new(dict::LAYER_BUILDINGS); buildings.features.push(BodyFeature { kind: 1, kind_detail: 0, geom_type: GEOM_POLYGON, flags: 0, name_idx: tilecodec::mamaps::body::NAME_NONE, parts_offset: 0, part_count: 1, transit_color: 0, transit_ordinal: 0, transit_lanes: 0, transit_taper: 0, lane_count: 0, }); buildings.parts.push(Part { coord_start: 0, point_count: 4, winding: WINDING_OUTER }); buildings.coords = vec![(0, 0), (100, 0), (100, 100), (0, 100)]; let attrs = BuildingAttrs { height: 420, min_height: 0, roof_height: 0, roof_shape: ROOF_GABLED, roof_direction: 64, roof_orientation: ROOF_ORIENT_ACROSS, building_colour: 0xFF_C8_A0_78, roof_colour: 0, }; let body = Body { extent: 4096, layers: vec![buildings], names: Vec::new(), ids: Vec::new(), turn_lanes: Vec::new(), buildings: vec![(dict::LAYER_BUILDINGS, vec![attrs])], heightmap: None, carriageways: Vec::new(), convention: None, region_links: Vec::new(), }; let mut scratch = Scratch::default(); let bytes = serialize_into_v10(&body, &mut scratch).expect("v10 serialize"); assert_eq!(bytes[3], tilecodec::mamaps::header::FORMAT_VERSION_V10); let back = Body::parse(bytes).expect("v10 parse"); let layer = back.layer(dict::LAYER_BUILDINGS).expect("buildings layer"); assert_eq!(layer.features.len(), 1); assert_eq!(layer.coords.len(), 4, "arena survives narrowing"); let got = back .building_attrs(dict::LAYER_BUILDINGS, 0) .expect("sparse table expands"); assert_eq!(got, attrs, "S3DB attrs survive sparse + narrowed"); } /// **v10 sparse lanes/carriageways, end to end.** One masked road among /// defaults (and one split carriageway among defaults) must survive the /// v10 serialize/parse trip exactly. Bridge coverage until tilecodec's own /// test target builds again. #[test] fn a_v10_body_round_trips_sparse_lanes_and_carriageways() { use tilecodec::mamaps::body::{ serialize_into_v10, Carriageway, Feature as BodyFeature, LaneTurns, Layer as BodyLayer, MarkingConvention, Part, Scratch, GEOM_LINE, WINDING_OUTER, }; let mut roads = BodyLayer::new(dict::LAYER_ROADS); for i in 0..3u32 { roads.features.push(BodyFeature { kind: 1, kind_detail: 0, geom_type: GEOM_LINE, flags: 0, name_idx: tilecodec::mamaps::body::NAME_NONE, parts_offset: i, part_count: 1, transit_color: 0, transit_ordinal: 0, transit_lanes: 0, transit_taper: 0, lane_count: 4, }); roads.parts.push(Part { coord_start: i * 2, point_count: 2, winding: WINDING_OUTER, }); let a = i as i16 * 10; roads.coords.extend_from_slice(&[(a, 0), (a, 100)]); } let turns = vec![ LaneTurns::default(), LaneTurns { forward: vec![1, 2, 6], backward: vec![4] }, LaneTurns::default(), ]; let rows = vec![ Carriageway { forward: 2, backward: 2, solid_dividers: 0b010 }, Carriageway::default(), Carriageway::default(), ]; let convention = MarkingConvention { left_hand: false, yellow_centre: true }; let body = Body { extent: 4096, layers: vec![roads], names: Vec::new(), ids: Vec::new(), turn_lanes: vec![(dict::LAYER_ROADS, turns.clone())], buildings: Vec::new(), heightmap: None, carriageways: vec![(dict::LAYER_ROADS, rows.clone())], convention: Some(convention), region_links: Vec::new(), }; let mut scratch = Scratch::default(); let bytes = serialize_into_v10(&body, &mut scratch).expect("v10 serialize"); assert_eq!(bytes[3], tilecodec::mamaps::header::FORMAT_VERSION_V10); let back = Body::parse(bytes).expect("v10 parse"); assert_eq!(back.feature_turns(dict::LAYER_ROADS, 1), Some(&turns[1])); assert_eq!(back.feature_turns(dict::LAYER_ROADS, 0), Some(&LaneTurns::default())); assert_eq!(back.feature_carriageway(dict::LAYER_ROADS, 0), Some(&rows[0])); assert_eq!( back.feature_carriageway(dict::LAYER_ROADS, 2), Some(&Carriageway::default()), ); assert_eq!(back.convention, Some(convention)); } /// **The DEM heightmap path, end to end.** A synthetic per-tile grid handed to the tiler reaches /// the archive on the tile it covers and reads back through [`tilecodec::mamaps::body::Heightmap::sample`] /// — and a build with no DEM leaves every tile's heightmap unset, a valid v6 with no terrain /// section. #[test] fn a_dem_grid_reaches_the_archive_and_reads_back_via_sample() { use tilecodec::mamaps::body::Heightmap; let (z, dim) = (14u8, 17u16); let (tx, ty) = (2730u64, 6335u64); // The tile's centre, so a small building lands squarely inside it (and so in exactly the // tile the synthetic DEM covers). let n = (1u64 << z) as f64; let clon = (tx as f64 + 0.5) / n * 360.0 - 180.0; let clat = { let m = std::f64::consts::PI * (1.0 - 2.0 * (ty as f64 + 0.5) / n); m.sinh().atan().to_degrees() }; let building = || Feature { class: Class::area(dict::LAYER_BUILDINGS, crate::schema::kind("building"), 14), geometry: square(clon - 0.001, clat - 0.001, 0.001), name: None, id: tilecodec::mamaps::body::ID_NONE, transit_color: 0, transit_ordinal: 0, transit_lanes: 0, transit_taper: 0, lane_count: 0, turn_fwd: Vec::new(), turn_bwd: Vec::new(), building: None, carriageway: tilecodec::mamaps::body::Carriageway::default(), }; // A ramp grid: sample(col, row) = 32768 + row*10 + col, so a read-back names its cell. let mut grid = Vec::with_capacity(dim as usize * dim as usize); for row in 0..dim as usize { for col in 0..dim as usize { grid.push(32768u16 + (row * 10 + col) as u16); } } let dem = crate::dem::Dem::from_grids(z, dim, vec![(tile_id(z, tx, ty), grid.clone())]); let with_dem = Settings { dem, ..settings(14, 14) }; let (bytes, _) = build(&spilled(&[building()]), &with_dem).expect("build with dem"); // v9: leaves compress by default, which the v8 byte cannot name. assert_eq!( bytes[7], tilecodec::mamaps::header::FORMAT_VERSION_V9, "the archive header carries the writer's own format version", ); let entries = tilecodec::mamaps::read::read_all(&bytes).expect("read"); let mut saw = false; for (id, _, body) in &entries { let body = Body::parse(body).expect("parse"); if *id == tile_id(z, tx, ty) { let hm = body.heightmap.expect("the covered tile carries a heightmap"); assert_eq!(hm.dim, dim); assert_eq!(hm.samples, grid, "the grid reaches the archive verbatim at its own zoom"); assert_eq!(hm.sample(0, 0), Some(32768), "sea level at the top-left"); assert_eq!(hm.sample(4, 3), Some(32768 + 34)); assert_eq!(Heightmap::metres(hm.sample(4, 3).unwrap()), 34); saw = true; } } assert!(saw, "the building's tile should be emitted and carry the DEM grid"); // Without a DEM the same build is a valid v6 whose tiles carry no heightmap section. let (plain, _) = build(&spilled(&[building()]), &settings(14, 14)).expect("build without dem"); for (_, _, body) in &tilecodec::mamaps::read::read_all(&plain).expect("read") { let body = Body::parse(body).expect("parse"); assert!(body.heightmap.is_none(), "no DEM means no heightmap section"); } }