#include <Physics.h>

#include <SFML/Graphics.hpp>

#include <Random.h>


sf::Vector2f getOverlap(const sf::FloatRect first, const sf::FloatRect second)
{
	const float deltaX = std::abs(second.position.x - first.position.x);
	const float deltaY = std::abs(second.position.y - first.position.y);
	
	const float resultX = (first.size.x + second.size.x) - deltaX; 
	const float resultY = (first.size.y + second.size.y) - deltaY; 
	return {resultX, resultY};
}

enum
{
	left,
	right
};

sf::Vector2f velocityInRandomDir(const float speed_in)
{
	const int side{Random::get(0,1)};

	// get angle within certain ranges so that the ball does not 
	// start moving straight side to side or up and down
	if (side == left)
	{// left
		const sf::Angle angle = sf::degrees((float)Random::get(220, 255));
		return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())};
	} 
	else if (side == right) 
	{// right
		const sf::Angle angle = sf::degrees((float)Random::get(285, 315));
		return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())};
	}

	return {0,0};// means something went wrong
}

// used for debugging
sf::Vector2f velocityInDirection(const float speed_in, const sf::Angle angle_in)
{
	return sf::Vector2f{speed_in * std::cos(angle_in.asRadians()), speed_in * std::sin(angle_in.asRadians())};
}
