38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate deterministic v1 little-endian OfflineFixture field payloads."""
|
|
|
|
from pathlib import Path
|
|
import struct
|
|
|
|
|
|
GRID = 16
|
|
ROOT = Path(__file__).resolve().parents[1] / "particle-fixtures"
|
|
ANDROID_ASSETS = (
|
|
Path(__file__).resolve().parents[1]
|
|
/ "platform/android/MapLibreAndroidTestApp/src/main/assets/integration/particle-fixtures"
|
|
)
|
|
|
|
|
|
def velocity(fixture: str, x: int, y: int) -> tuple[float, float]:
|
|
if fixture == "uniform-east":
|
|
return 1.0, 0.0
|
|
if fixture == "uniform-north":
|
|
return 0.0, 1.0
|
|
if fixture == "nodata":
|
|
return (-9999.0, -9999.0) if (x, y) == (3, 4) else (1.0, 0.0)
|
|
local_x = (x + 0.5) / GRID - 0.5
|
|
local_y = (y + 0.5) / GRID - 0.5
|
|
return -2.0 * local_y, 2.0 * local_x
|
|
|
|
|
|
for fixture in ("uniform-east", "uniform-north", "vortex", "nodata"):
|
|
payload = bytearray()
|
|
for y in range(GRID):
|
|
for x in range(GRID):
|
|
payload.extend(struct.pack("<ff", *velocity(fixture, x, y)))
|
|
(ROOT / fixture / "field.f32").write_bytes(payload)
|
|
asset_path = ANDROID_ASSETS / fixture / "field.f32"
|
|
asset_path.parent.mkdir(parents=True, exist_ok=True)
|
|
asset_path.write_bytes(payload)
|
|
(asset_path.parent / "metadata.json").write_bytes((ROOT / fixture / "metadata.json").read_bytes())
|