using Theriapolis.Core.Util;

namespace Theriapolis.Core.World;

/// <summary>
/// A bridge where a road or rail polyline crosses a river.
/// Endpoints are in world-pixel space and follow the actual road polyline,
/// so the deck visually matches the road at the crossing regardless of meander.
/// </summary>
public readonly struct Bridge
{
    public readonly Vec2 Start;
    public readonly Vec2 End;
    public readonly int  RoadId;

    public Bridge(Vec2 start, Vec2 end, int roadId)
    {
        Start  = start;
        End    = end;
        RoadId = roadId;
    }

    /// <summary>Center of the deck (midpoint of Start–End).</summary>
    public float WorldPixelX => (Start.X + End.X) * 0.5f;
    public float WorldPixelY => (Start.Y + End.Y) * 0.5f;

    /// <summary>Road direction angle (radians) from Start to End.</summary>
    public float RoadAngle => MathF.Atan2(End.Y - Start.Y, End.X - Start.X);
}
