/******************************************************************************
*	File		-	types.cpp
*	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.
******************************************************************************/


#include "types.h"

namespace lunarium
{
    ////////////////////////////////////////////////////////////
    //				COLOR
    ////////////////////////////////////////////////////////////
    Color::Color(float _r, float _g, float _b, float _a)
        : Red(_r), Green(_g), Blue(_b), Alpha(_a)
    {

    }

    Color::Color()
        : Red(0.0f), Green(0.0f), Blue(0.0f), Alpha(0.0f)
    {

    }

    ////////////////////////////////////////////////////////////
    //				RECTANGLE
    ////////////////////////////////////////////////////////////
    Rectangle::Rectangle()
        : Left(0.0f), Top(0.0f), Width(0.0f), Height(0.0f)
    {
        
    }

    Rectangle::Rectangle(float _left, float _top, float _width, float _height)
        : Left(_left), Top(_top), Width(_width), Height(_height)
    {

    }
    float Rectangle::Area() const
    {
        return Width * Height;
    }

    bool Rectangle::ContainsPoint(glm::vec2 point) const
    {
        if (point.x < this->Left || point.x > this->right())
            return false;

        if (point.y < this->Top || point.y > this->bottom())
            return false;

        return true;
    }

    bool Rectangle::Intersects(const Rectangle& other, glm::vec2& centers) const
    {
        glm::vec2 myCenter = glm::vec2(this->Left + (this->Width / 2.0f), this->Top + (this->Height / 2.0f));
        glm::vec2 otherCenter = glm::vec2(other.Left + (other.Width / 2.0f), other.Top + (other.Height / 2.0f));
        centers = myCenter - otherCenter;

        if (this->Left > other.right() || other.Left > this->right())
            return false;

        if (this->Top > other.bottom() || other.Top > this->bottom())
            return false;

        return true;
    }
}