public bool AddConnection(int index1, Direction direction)
{
// if (!direction.IsCardinal())
// return false;
int index2 = index1 + GetIndexOffset(direction);
if (!Union(index1, index2))
return false;
nodes[index1] |= direction;
nodes[index2] |= direction.Opposite();
return true;
}