#include "component_action_keep_in_rectangle.h"

/* DEPENDENCIES: Physics */

/* Sets action_keep_in_rectangle component info. */
void
component_action_keep_in_rectangle_init(ComponentActionKeepInRectangle* self, Rectangle rectangle)
{
	self->rectangle = rectangle;
}

/* Ticks action_keep_in_rectangle component. */
void
component_action_keep_in_rectangle_tick(ComponentActionKeepInRectangle* self, ECS* ecs)
{
	ComponentPhysics* physics;

	physics = ecs_component_get(ecs, ECS_COMPONENT_PHYSICS, self->component.id);

	physics->position[0] = CLAMP(physics->position[0], self->rectangle.x + physics->size[0], self->rectangle.x + self->rectangle.w - physics->size[0]);
	physics->position[1] = CLAMP(physics->position[1], self->rectangle.y + physics->size[1], self->rectangle.y + self->rectangle.h - physics->size[1]);
}
