package org.lucci.madhoc.bining;
import org.lucci.up.data.Point;
public class Grid
{
private double edgeSize;
private Cel[][] cels;
public Grid(double surface)
{
if (surface < 10000)
throw new IllegalArgumentException("surface <= 10.000. surface= " + surface);
if (surface % 10000 != 0)
throw new IllegalArgumentException("surface must be divisible by 10.000");
this.edgeSize = (int) Math.sqrt(surface);
int celCount = (int) (edgeSize / 10 + 1);
cels = new Cel[celCount][celCount];
for (int i = 0; i < celCount; ++i)
{
for (int j = 0; j < celCount; ++j)
{
cels[i][j] = new Cel(i, j);
}
}
}
public double getEdgeLenght()
{
return edgeSize;
}
public Cel getCelAt(Point point)
{
return cels[(int) (point.getX() / 10f)][(int) (point.getY() / 10f)];
}
public Cel[][] getCels()
{
return cels;
}
}