#include "BreakoutLocationArray.h"

BreakoutLocationArray::BreakoutLocationArray(const AABBi &boxArea, const Vector2i &boxSize, int padding /* = 1 */)
: m_pLocationArray(0), m_width(0), m_height(0)
{
	int boxPaddedWidth = (boxSize.x + (padding * 2));
	int areaWidth = boxArea.Right - boxArea.Left;
	m_width = areaWidth / boxPaddedWidth; //Pad either side of the box.

	int boxPaddedHeight = (boxSize.y + (padding * 2));
	int areaHeight = boxArea.Top - boxArea.Bottom;
	m_height = areaHeight / boxPaddedHeight;
	if(m_height < 0)
		m_height = -m_height;

	m_pLocationArray = new Vector2i[m_width * m_height];
	for(int x = 0; x < m_width; x++)
	{
		for(int y = 0; y < m_height; y++)
		{
			int idx = (y * m_width) + x;
			m_pLocationArray[idx].x = boxArea.Left + (x * boxPaddedWidth) + padding;
			m_pLocationArray[idx].y = boxArea.Bottom + (y * boxPaddedHeight) + padding;
		}
	}
}

BreakoutLocationArray::~BreakoutLocationArray()
{
	if(m_pLocationArray)
		delete[] m_pLocationArray;
}
