Files
gta6/tools/extract/tests/test_park_fit.py
T

64 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import math
from pathlib import Path
from types import SimpleNamespace
import pytest
from leonida.park import M_PER_DEG_LAT, M_PER_DEG_LON, REF_LAT, REF_LON, ParkFit, load_park, local_metres
DATA = Path(__file__).resolve().parents[1] / "data"
def latlon(x: float, y: float) -> tuple[float, float]:
"""Lokale Meter -> Breite/Länge, die Umkehrung von local_metres."""
return REF_LAT + y / M_PER_DEG_LAT, REF_LON + x / M_PER_DEG_LON
# Echter Park 100 × 200 m, Spielpark 200 × 400 m ab (1000 | 1000), Anlage 50 m vom Westrand:
# Welt-x = 1050 + x, Welt-y = 1000 + 2 · y.
FAKE = SimpleNamespace(
real={"sw": latlon(0, 0), "se": latlon(100, 0), "nw": latlon(0, 200)},
game={"sw": (1000.0, 1000.0), "se": (1200.0, 1000.0), "ne": (1200.0, 1400.0), "nw": (1000.0, 1400.0)},
scale_u=1.0, offset_u=50.0,
)
def test_reference_point_is_the_local_origin():
assert math.dist(local_metres(REF_LAT, REF_LON), (0.0, 0.0)) < 1e-9
def test_park_coords_run_west_to_east_and_south_to_north():
s, t = ParkFit(FAKE).park_coords(25.0, 150.0)
assert (s, t) == pytest.approx((0.25, 0.75))
def test_real_corners_and_centre_land_in_the_game_park():
fit = ParkFit(FAKE)
assert fit.to_game(*latlon(0, 0)) == pytest.approx((1050.0, 1000.0))
assert fit.to_game(*latlon(100, 0)) == pytest.approx((1150.0, 1000.0))
assert fit.to_game(*latlon(0, 200)) == pytest.approx((1050.0, 1400.0))
assert fit.to_game(*latlon(50, 100)) == pytest.approx((1100.0, 1200.0))
def test_quads_cover_real_and_game_park():
fit = ParkFit(FAKE)
assert fit.real_quad().area == pytest.approx(100 * 200)
assert fit.game_quad.area == pytest.approx(200 * 400)
def test_committed_fit_puts_tribune_and_hood_yard_within_one_and_a_half_metres():
config = load_park(DATA / "flamingo-park.toml")
fit = ParkFit(config)
for anchor in config.anchors:
assert math.dist(fit.to_game(*anchor.real), anchor.game) <= 1.5, anchor.name
def test_committed_fit_keeps_the_south_edge_true_to_scale_and_offset_from_the_corner():
config = load_park(DATA / "flamingo-park.toml")
fit = ParkFit(config)
sw, se, nw = (fit.to_game(*config.real[key]) for key in ("sw", "se", "nw"))
assert math.dist(sw, se) == pytest.approx(fit.real_width, abs=0.01)
assert fit.real_width == pytest.approx(200.57, abs=0.01)
assert math.dist(sw, config.game["sw"]) == pytest.approx(config.offset_u, abs=0.01)
assert math.dist(nw, config.game["nw"]) == pytest.approx(config.offset_u, abs=0.01)