package commons.graph.worker;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import commons.graph.Calculator;
import commons.graph.model.Node;
import commons.graph.model.Nodes;
import commons.graph.model.Point;
public class RegularVirtualizer extends EdgeWorker
{

Set<String> done = new HashSet<String>();

public void init ()
{
// print(0, graph.getOrigin(), edges.countChildren(graph.getOrigin()), 0);
}

/**
 * Slightely redundant. Consider using specific traversion logic for this.
 */
public void work (String a, String b)
{
   if (done.contains(a)) return;
   Node parent = nodes.getNode(a);
   int nc = edges.countChildren(a);
   double step = Calculator.PI2 / (double)nc;
   int n = 0;
   if (nc > 0)
   {
      Nodes nodes = edges.getChildNodes(a);
      for (Iterator<Node> iter = nodes.nodeIterator(); iter.hasNext();)
      {
         Node child = iter.next();
         double radius = edges.distance(parent.label, child.label);
         if (depth > 1)
         {
            int d = (depth - 1) * 3;
            radius /= d;
         }
//         OsUtl.trace("n * step: " + (n * step) + " n:" + n + " step:" + step);
         
         Point point = Calculator.circularPoint(radius, n++ * step);
         // reposition point in accordance to parent point.
         point.add(parent.x, parent.y);
         
         child.x = point.x;
         child.y = point.y;
      }
   }
   done.add(a);
}
}
