#include <Util.h>
#include <Random.h>

sf::Vector2f getOverlap(sf::FloatRect first, sf::FloatRect second)
{
	sf::Vector2f result;
	sf::Vector2f delta;
	delta.x = std::abs(second.position.x - first.position.x);
	delta.y = std::abs(second.position.y - first.position.y);
	
	result.x = (first.size.x + second.size.x) - delta.x; 
	result.y = (first.size.y + second.size.y) - delta.y; 
	return result;
}

sf::Vector2f velocityInRandomDir(float speed_in)
{
	const bool upOrDown{(bool)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
	sf::Angle angle = sf::degrees(upOrDown ? Random::get(225, 315) : Random::get(45, 135));
	if (angle.asDegrees() == 90.f || angle.asDegrees() == 270)
	{
		angle += sf::degrees(1);
	}

	return sf::Vector2f{speed_in * std::cos(angle.asRadians()), speed_in * std::sin(angle.asRadians())};
}

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