require('pathfinding/polygon');
require('pathfinding/node');
require('pathfinding/polygrid');
TestGridBuilder	=	class.new();

function TestGridBuilder:constructor()
	self.nodes	=	{};
end

function TestGridBuilder:build()
	local poly1	=	Polygon(Vertex(1,3), Vertex(2,2), Vertex(3,2), Vertex(4,3));--:offset(0.2);
	local poly2	=	Polygon(Vertex(5,2), Vertex(6,2), Vertex(6,5), Vertex(2, 5), Vertex(2, 4), Vertex(5,4));--:offset(0.2);

	local polygons	=	{poly1, poly2};
	--local nodes1 = poly1:toNodes();
--[[	for i,v in pairs(nodes1) do
		printf("Node at (%d,%d)\n", v.x, v.y);
		local neighbors = v:getNeighbors();
		for j,k in pairs(neighbors) do
			printf("\tConnects to (%d,%d)\n", k.x, k.y);
		end
	end
	error("");
]]
--[[
	local nodes2 = poly2:toNodes();


	print("Poly 1 nodes");
	for i,v in pairs(nodes1) do
		printf("\tNode (%0.3f, %0.3f\n", v.x, v.y);
	end

	print("Poly 2 nodes");
	for i,v in pairs(nodes2) do
		printf("\tNode (%0.3f, %0.3f\n", v.x, v.y);
	end

	-- Connect nodes1 to nodes2
	nodes1[1]:addConnection(nodes2[4]);
	nodes1[1]:addConnection(nodes2[5]);
	nodes1[1]:addConnection(nodes2[6]);
	nodes1[3]:addConnection(nodes2[1]);
	nodes1[4]:addConnection(nodes2[1]);
	nodes1[4]:addConnection(nodes2[5]);
	nodes1[4]:addConnection(nodes2[6]);

	-- Connect nodes2 back to nodes1
	nodes2[4]:addConnection(nodes1[1]);
	nodes2[5]:addConnection(nodes1[1]);
	nodes2[6]:addConnection(nodes1[1]);
	nodes2[1]:addConnection(nodes1[3]);
	nodes2[1]:addConnection(nodes1[4]);
	nodes2[5]:addConnection(nodes1[4]);
	nodes2[6]:addConnection(nodes1[4]);

	-- Move nodes2 into nodes1
	for i,v in pairs(nodes2) do
		table.insert(nodes1, v);
	end
]]
	return PolyGrid(polygons, 0.2);--nodes1);
end