You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
autohero/backend/migrations/000031_town_positions_min_t...

30 lines
1.2 KiB
SQL

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- Scale world positions so every road segment (straight line between town centers)
-- is at least (1.2 world_units/sec) * (1.5 * 3600 sec) = 6480 units.
-- Method: uniform scale from centroid of towns 1..31; factor = 6480 / min_edge
-- where min_edge was ~870.54 (towns 82) before this migration.
-- Server recomputes road polylines and Distance in LoadRoadGraph from town coords.
-- Centroid and scale (derived from pre-migration layout including 000030 towns).
-- cx, cy = AVG(world_x), AVG(world_y) over ids 1..31 before scale.
DO $$
DECLARE
cx double precision := 5365.609677419355;
cy double precision := 4259.612903225806;
s double precision := 6480.0 / 870.5435801842434;
BEGIN
UPDATE public.towns
SET world_x = cx + (world_x - cx) * s,
world_y = cy + (world_y - cy) * s
WHERE id BETWEEN 1 AND 31;
UPDATE public.heroes
SET position_x = cx + (position_x - cx) * s,
position_y = cy + (position_y - cy) * s;
END $$;
-- Stored road.distance is overwritten at runtime; scale placeholders for any SQL/reporting.
UPDATE public.roads SET distance = distance * (6480.0 / 870.5435801842434);
-- Legacy table not read by Go server; remove stale geometry so DB matches new world.
TRUNCATE TABLE public.road_waypoints;