#include "IPhysicsComponent.hpp"

IPhysicsComponent::IPhysicsComponent(TransformComponent* pos, Vec2D dim){
    m_position = pos;
    dimensions = dim;
}
IPhysicsComponent::~IPhysicsComponent(){};

bool IPhysicsComponent::IsColliding(IPhysicsComponent* other){
    Vec2D thisPos = m_position->getPos();
    Vec2D thisFarRight = thisPos + dimensions;
    Vec2D otherPos = other->GetPosition();
    Vec2D otherFarRight = otherPos + other->GetDimensions();
    return ((thisPos.x >= otherPos.x && thisPos.x <= otherFarRight.x) ||
            (thisPos.x <= otherPos.x && thisFarRight.x >= otherPos.x)) &&
           ((thisPos.y >= otherPos.y && thisPos.y <= otherFarRight.y) ||
            (thisPos.y <= otherPos.y && thisFarRight.y >= otherPos.y));
}

Vec2D IPhysicsComponent::GetPosition(){
    return m_position->getPos();
}

Vec2D IPhysicsComponent::GetDimensions(){
    return dimensions;
}

// Stubs to be implemented by child classes
void IPhysicsComponent::ApplyForce(Vec2D force){}
void IPhysicsComponent::ApplyAcceleration(Vec2D acceleration){}
void IPhysicsComponent::ApplyVelocity(){};
void IPhysicsComponent::SetVelocity(Vec2D vel){}
bool IPhysicsComponent::IsKinematic(){return false;}
bool IPhysicsComponent::IsElastic(){return false;}
bool IPhysicsComponent::UsesGravity(){return false;}
Vec2D IPhysicsComponent::GetVelocity(){return Vec2D(0,0);}
float IPhysicsComponent::GetMass(){return 0;}