#include "rectangle.h"

/* Are two rectangles colliding? */
bool
rectangle_collide(vec4 a, vec4 b)
{
	vec2 aSize;
	vec2 bSize;

	aSize[0] = fabs(a[2] - a[0]);
	aSize[1] = fabs(a[3] - a[1]);
	bSize[0] = fabs(b[2] - b[0]);
	bSize[1] = fabs(b[3] - b[1]);

	if
	(
		a[0] < b[0] + bSize[0] &&
		a[0] + aSize[0] > b[0] &&
		a[1] < b[1] + bSize[1] &&
		a[1] + aSize[1] > b[1]
	)
		return true;
	return false;
}

/* Does the rectangle contain a point? */
bool
rectangle_has_point(vec4 self, vec2 point)
{
	vec2 size;

	size[0] = fabs(self[2] - self[0]);
	size[1] = fabs(self[3] - self[1]);

	if
	(
		point[0] > self[0] &&
		point[0] < self[0] + size[0] &&
		point[1] > self[1] &&
		point[1] < self[1] + size[1]
	)
		return true;
	return false;
}
