1#include "../Instruments/StreetMapProjection.h"
2
3#include <cmath>
4#include <cstdlib>
5#include <iostream>
6
7static int checks = 0;
8static void Check(bool condition, const char* message)
9{
10 ++checks;
11 if (!condition) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
12}
13
14static bool Near(float actual, float expected)
15{
16 return std::fabs(actual - expected) < 0.001f;
17}
18
19int main()
20{
22 Check(!map.
valid,
"a missing StreetView must not provide a route viewport");
25
26
27 map.
source = { 989, 1007, 1058, 1039 };
30
31 for (int originY : { 208, 213 })
32 {
35 for (float scale : { 5.0f, 10.0f, 20.0f, 40.0f, 80.0f, 160.0f })
36 {
40 Check(
Near(sameNode.x, center.x) &&
Near(sameNode.y, center.y),
41 "a route node at the vehicle has a separate center offset");
43 Check(
Near(corner.x, 0.0f) &&
Near(corner.y,
static_cast<float>(originY)),
44 "the sampled map corner does not use the vehicle layout origin");
45
46
47 const auto east = map.
WorldToScreen({ vehicle.
x + 3.0f / 2048.0f, vehicle.
y });
48 const auto south = map.
WorldToScreen({ vehicle.
x, vehicle.
y + 3.0f / 2048.0f });
50 "east/west route distances use a different magnification");
52 "north/south route distances use a different magnification");
53
54
55
60 "the route does not follow a changed map crop");
63 }
64 }
65
70 Check(
Near(before.x, 70.0f) &&
Near(before.y, 242.0f),
71 "integer crop rounding was replaced with a hard-coded geometric center");
75 Check(
Near(relocated.x - before.x, 31.0f) &&
Near(relocated.y - before.y, 5.0f),
76 "switching vehicle layouts leaves the route at the old origin");
80 "a one-texel pan must move the route exactly two pixels at maximum zoom");
81
82
83 for (int height : { 64, 69 })
84 {
85 for (float magnification : { 2.0f, 1.0f, 0.5f, 0.25f, 0.125f, 0.0625f })
86 {
87 for (float fraction : { 0.0f, 0.125f, 0.5f, 0.999f })
88 {
91 centered.
y = height == 69 ? 208 : 213;
95 centered.
centerTexture = { 1024.0f + fraction, 1024.0f + fraction };
98 const float markerX = 99.0f;
102 Check(std::fabs(route.x - markerX) <= 0.5001f,
103 "the route center drifts from the fixed marker during panning or zooming");
104 Check(
Near(route.x - bitmap.x, 3.0f) &&
Near(route.y, bitmap.y),
105 "the road calibration must remain three screen pixels at every zoom");
110 Check(topLeft.x <= centered.
x &&
Near(topLeft.y,
static_cast<float>(centered.
y)),
111 "panning exposes an empty strip at the screen origin");
112 Check(bottomRight.x >= centered.
x + centered.
width && bottomRight.y >= centered.
y + height,
113 "the bitmap fails to cover the right or bottom edge of the XML screen");
116 Check(
Near(nextNode.x - route.x, magnification) &&
Near(nextNode.y - route.y, magnification),
117 "calibration changes the scale of the route relative to the map");
120 Check(
Near(repeated.x, route.x) &&
Near(repeated.y, route.y),
121 "repeated frames accumulate the bitmap pan");
122 }
123 }
124 }
125 std::cout << "PASS: " << checks << " street-map projection checks\n";
126}
bool Near(const Body &b, const Triangle &t, double extra)
Point TextureToScreen(Point position) const
static Point WorldToTexture(Point position)
Point WorldToScreen(Point position) const
void CenterOverlays(float vehicleCenterX, float roadCorrectionPixels)
Point OverlayToScreen(Point texturePosition) const