Enhance README with detailed testing instructions and clarify world generation process; implement chunk boundary handling in OsmWorldBuilder; integrate Vitest for testing in the web project; add theme toggle functionality and improve styling in the web interface.

This commit is contained in:
Leonid Pershin
2026-08-16 18:37:25 +03:00
parent 8460921bfa
commit 312d6bc58a
24 changed files with 2971 additions and 314 deletions
@@ -55,10 +55,11 @@ public class ImportPipelineTests
[Fact]
public void Imports_a_highway_as_a_road_with_a_width()
{
// Kept inside a single chunk so this test is about the attributes, not the splitting.
using var world = Build(WayWithGeometry(
id: 7,
tags: new() { ["highway"] = "residential", ["name"] = "Main Street" },
metres: [new Vector2(-200, 0), new Vector2(200, 0)]));
metres: [new Vector2(100, 0), new Vector2(300, 0)]));
var road = Assert.Single(Export(world)[0].Chunk.Roads);
@@ -76,12 +77,50 @@ public class ImportPipelineTests
tags: new() { ["highway"] = "primary" },
metres: [new Vector2(0, 0), new Vector2(50_000, 0)]));
var road = Assert.Single(Export(world)[0].Chunk.Roads);
var maxX = road.Path.Where((_, index) => index % 2 == 0).Max();
var maxX = Export(world)
.SelectMany(chunk => chunk.Chunk.Roads)
.SelectMany(road => road.Path.Where((_, index) => index % 2 == 0))
.Max();
Assert.True(maxX <= WorldSizeMeters / 2 + 0.5, $"Road reached {maxX} m, past the world edge.");
}
[Fact]
public void Splits_a_long_road_into_one_piece_per_chunk_it_crosses()
{
// Spans the full width of the world at y = 0, which crosses all four chunk columns of row 2.
using var world = Build(WayWithGeometry(
id: 12,
tags: new() { ["highway"] = "primary" },
metres: [new Vector2(-900, 0), new Vector2(900, 0)]));
var chunks = Export(world);
Assert.Equal(4, chunks.Count);
Assert.All(chunks, chunk => Assert.Equal(2, chunk.Coord.Y));
Assert.Equal([0, 1, 2, 3], chunks.Select(chunk => chunk.Coord.X));
// Every piece now sits inside its own chunk, so the chunk's bounds no longer stretch across the map.
foreach (var chunk in chunks)
{
var square = world.Grid.BoundsOf(chunk.Coord);
Assert.True(chunk.Index.Bounds[0] >= square.MinX - 2f);
Assert.True(chunk.Index.Bounds[2] <= square.MaxX + 2f);
}
}
[Fact]
public void Keeps_a_short_road_whole()
{
using var world = Build(WayWithGeometry(
id: 13,
tags: new() { ["highway"] = "service" },
metres: [new Vector2(10, 10), new Vector2(60, 40)]));
Assert.Single(Export(world));
Assert.Single(Export(world)[0].Chunk.Roads);
}
[Fact]
public void Assembles_a_multipolygon_relation_and_keeps_its_holes()
{
@@ -147,13 +186,13 @@ public class ImportPipelineTests
}
[Fact]
public void Chunk_bounds_stretch_to_cover_geometry_that_overhangs()
public void Chunk_bounds_stretch_to_cover_areas_that_overhang()
{
// A road whose centre sits in one chunk but which reaches well into its neighbours.
// Areas are still bucketed whole by the centre of their extent, so a large one overhangs its chunk.
using var world = Build(WayWithGeometry(
id: 12,
tags: new() { ["highway"] = "primary" },
metres: [new Vector2(-900, 0), new Vector2(900, 0)]));
id: 14,
tags: new() { ["landuse"] = "forest" },
metres: Square(0, 0, 1500, closed: true)));
var exported = Assert.Single(Export(world));
var square = world.Grid.BoundsOf(exported.Coord);