/******************************************************************************
*	File		-	types.h
*	Author		-	Joey Pollack
*	Date		-	2021/08/30 (y/m/d)
*	Mod Date	-	2021/09/02 (y/m/d)
*	Description	-	Defines some generic types for use through out the engine.
******************************************************************************/

#ifndef TYPES_H_
#define TYPES_H_

#include <cstdint>
#include <glm/glm.hpp>
#include <box2d/box2d.h>

namespace lunarium
{
    ////////////////////////////////////////////////////////////
    //				POINT
    ////////////////////////////////////////////////////////////
    template <typename T>
    struct Point2D
    {
        T X;
        T Y;
    };

    typedef Point2D<int> Point2Di;
    typedef Point2D<unsigned> Point2Du;
    typedef Point2D<float> Point2Df;

    ///////////////////////////////////////////////////////
    //          SIZE
    //////////////////////////////////////////////////////
    template <typename T>
    struct Size
    {
        T Width;
        T Height;
    };

    typedef Size<int> Sizei;
    typedef Size<unsigned> Sizeu;
    typedef Size<float> Sizef;
    /////////////////////////////////////////////////

    /////////////////////////////////////////////////
    //          COLOR
    /////////////////////////////////////////////////
    struct Color
	{
		union
		{
			float arr[4];

			struct
			{
				float Red;
				float Green;
				float Blue;
				float Alpha;
			};
		};

		Color();
		Color(float _r, float _g, float _b, float _a = 1.0f);
	};
    /////////////////////////////////////////////////


    /////////////////////////////////////////////////
    //          RECTANGLE
    /////////////////////////////////////////////////
    struct Rectangle
	{
		float X;
		float Y;
		float HalfWidth;
		float HalfHeight;

        float left() const { return X - HalfWidth; }
        float top() const { return Y - HalfHeight; }
		float right() const { return X + HalfWidth; }
		float bottom() const { return Y + HalfHeight; }

        glm::vec2 CenterPoint() const;
        Sizef FullSize() const;

		Rectangle();
        Rectangle(b2AABB& box);
		Rectangle(float x, float y, float half_width, float half_height);

        void Scale(float x, float y);
		float Area() const;
        bool ContainsPoint(glm::vec2 point) const;

        // centers will be filled out with a vector the goes from the other
        // Rectangle's center to the invoking object's center.
        // This could be used for determining the angle of the intersection.
        bool Intersects(const Rectangle& other, glm::vec2& centers) const;

        static Rectangle MakeFromTopLeft(float left, float top, float width, float height);
	};
    /////////////////////////////////////////////////
}

#endif // TYPES_H_