using UnityEngine;

public static class Extensions
{
    // Zeichnet eine Quadratic Bezier Kurve (Start, Control, End) mit N Punkten
    public static void SetQuadraticBezier(this LineRenderer line, Vector3 start, Vector3 control, Vector3 end, int segments)
    {
        line.positionCount = segments + 1;

        for (int i = 0; i <= segments; i++)
        {
            float t = i / (float)segments;
            // Quadratic Bezier Formel
            Vector3 point = (1 - t) * (1 - t) * start +
                            2 * (1 - t) * t * control +
                            t * t * end;

            line.SetPosition(i, point);
        }
    }

    public static void SetGreatCircleArc(this LineRenderer line, Vector3 start, Vector3 end, int segments, float radius)
    {
        // Normalize to sphere radius
        Vector3 startNorm = start.normalized * radius;
        Vector3 endNorm = end.normalized * radius;

        line.positionCount = segments + 1;

        for (int i = 0; i <= segments; i++)
        {
            float t = i / (float)segments;
            // spherical linear interpolation (slerp) between start and end
            Vector3 point = Vector3.Slerp(startNorm, endNorm, t);
            line.SetPosition(i, point);
        }
    }
}
