module ecs_utils.math.vector;

struct vec2
{
    union
    {
        struct
        {
            float x;
            float y;
        }
        float[2] data;
    }

    vec2 opBinary(string op)(vec2 v)
    {
        static if (op == "+") return vec2(x + v.x, y + v.y);
        else static if (op == "-") return vec2(x - v.x, y - v.y);
        else static if (op == "*") return vec2(x * v.x, y * v.y);
        else static if (op == "/") return vec2(x / v.x, y / v.y);
        else static assert(0, "Operator "~op~" not implemented");
    }

    vec2 opBinary(string op)(float v)
    {
        static if (op == "+") return vec2(x + v, y + v);
        else static if (op == "-") return vec2(x - v, y - v);
        else static if (op == "*") return vec2(x * v, y * v);
        else static if (op == "/") return vec2(x / v, y / v);
        else static assert(0, "Operator "~op~" not implemented");
    }

    void opOpAssign(string op)(vec2 v)
    {
        static if (op == "+")
        {
            x += v.x;
            y += v.y;
        }
        else static if (op == "-")
        {
            x -= v.x;
            y -= v.y;
        }
        else static if (op == "*")
        {
            x *= v.x;
            y *= v.y;
        }
        else static if (op == "/")
        {
            x /= v.x;
            y /= v.y;
        }
        else static assert(0, "Operator "~op~" not implemented");
    }
}

struct vec4
{
    union
    {
        struct
        {
            float x;
            float y;
            float z;
            float w;
        }
        float[4] data;
    }
}

struct ivec2
{
    union
    {
        struct
        {
            int x;
            int y;
        }
        int[2] data;
    }
}

struct ivec4
{
    union
    {
        struct
        {
            int x;
            int y;
            int z;
            int w;
        }
        int[4] data;
    }
}