clone

an offline map explorer where each world, from a game map to a city's open data, ships as one .atlas file

feat/atlas-next-horizon
atlas / internal / app / vnext_projection_test.go
vnext_projection_test.go 4.0K
1package app23import (4 "strings"5 "testing"67 "github.com/FelineStateMachine/atlas/format/vnext"8)910func TestVNextEarthBuildsTheRendererDirectly(t *testing.T) {11 t.Parallel()1213 native, err := vnext.OpenFile("../../included/earth-20260803-28305c3d1811.atlas", vnext.StandardSchema())14 if err != nil {15 t.Fatalf("open native Earth: %v", err)16 }17 defer native.Close()18 semantic, err := native.Volume()19 if err != nil {20 t.Fatalf("restore native Earth: %v", err)21 }22 for _, set := range semantic.Worlds[0].FeatureSets {23 if len(set.Features) == 0 {24 continue25 }26 page, err := native.FeaturePage(vnext.FeaturePageRequest{FeatureSet: set.ID, Limit: 1})27 if err != nil || len(page.Features) != 1 || page.PartitionsRead != 1 || page.BytesRead == 0 {28 t.Fatalf("framing-1 feature demand = %#v, %v", page, err)29 }30 break31 }32 summaries, err := native.FeatureSetSummaries()33 if err != nil || len(summaries) == 0 || summaries[0].Rows == 0 {34 t.Fatalf("framing-1 feature summaries = %#v, %v", summaries, err)35 }3637 model, err := buildVNextWorld(semantic.Worlds[0], semantic.Assets)38 if err != nil {39 t.Fatalf("build vNext world: %v", err)40 }41 if len(model.Points) != 202 || len(model.Shapes) != 177 || len(model.Members) != 7 || len(model.Lenses) != 1 {42 t.Fatalf("runtime model has %d points, %d shapes, %d collections and %d lenses", len(model.Points), len(model.Shapes), len(model.Members), len(model.Lenses))43 }44 countries := nativeCollection(model, "Countries")45 if countries == nil || len(countries.Shapes) != 177 {46 t.Fatalf("Countries collection = %#v", countries)47 }48 fiji := nativeShape(countries, "Fiji")49 if fiji == nil || len(fiji.Polygons) < 2 || fiji.Feature == nil {50 t.Fatalf("Fiji native shape = %#v", fiji)51 }52 if !strings.Contains(fiji.ID, "/feature/") || countries.ID == "" {53 t.Fatalf("native identities were not preserved: feature=%q layer=%q", fiji.ID, countries.ID)54 }55}5657func TestNativeCoordinateLabelsRespectTheDeclaredSpace(t *testing.T) {58 t.Parallel()5960 space := vnext.CoordinateSpace{Kind: "projected", Unit: "metre", Extent: [4]float64{0, 0, 100, 100}}61 if got := coordinateLabel(space, tileGrid{}, vnext.Position{40, 60}); got != "40.000000, 60.000000 metre" {62 t.Fatalf("projected coordinate label = %q", got)63 }6465 legacy := tileGrid{SourceZoom: 5, FirstTile: 10, TileSize: 256, Size: 8192}66 got := coordinateLabel(vnext.CoordinateSpace{Kind: "projected", Unit: "world-pixel", Definition: "atlas:tile-plane"}, legacy, vnext.Position{4096, 4096})67 if strings.Contains(got, "world-pixel") || strings.Contains(got, "Inf") {68 t.Fatalf("legacy tile-plane label = %q", got)69 }70}7172func TestTileGridProjectsIndependentColumnAndRowOrigins(t *testing.T) {73 t.Parallel()7475 grid := tileGrid{SourceZoom: 4, OriginX: 3, OriginY: 6, FirstTile: 99, TileSize: 256, Size: 1024}76 latitude, longitude := grid.unproject(0, 0)77 x, y := grid.project(latitude, longitude)78 if x != 0 || y != 0 {79 t.Fatalf("origin round trip = %v,%v, want 0,0", x, y)80 }81}8283func TestNativeGridUsesTheAuthoritativeCoordinateExtent(t *testing.T) {84 space := vnext.CoordinateSpace{85 ID: "sample-grid", Kind: "projected", Unit: "metre", Definition: "local sample grid",86 Extent: [4]float64{10, 20, 110, 70}, OriginX: 7, OriginY: 11,87 }88 grid := nativeGrid(space)89 if grid.TileSize != 256 || grid.Size != 100 || grid.OriginX != 7 || grid.OriginY != 11 {90 t.Fatalf("native grid = %+v, want conventional tile step over the coordinate extent", grid)91 }92 space.SourceZoom, space.TileSize, space.Size = 3, 32, 25693 if got := coordinateLabel(space, nativeGrid(space), vnext.Position{40, 60}); got != "40.000000, 60.000000 metre" {94 t.Fatalf("local projected coordinate label = %q", got)95 }96}9798func nativeCollection(model *worldModel, title string) *collectionModel {99 for _, collection := range model.Members {100 if collection.Title == title {101 return collection102 }103 }104 return nil105}106107func nativeShape(collection *collectionModel, title string) *shapeModel {108 for _, shape := range collection.Shapes {109 if shape.Title == title {110 return shape111 }112 }113 return nil114}