示例#1
0
  public static void draw(LayoutManager layout, int size, int dir) {
    List<LayoutNode> V = layout.generate(size, dir);

    System.out.println(
        "Layout " + layout.name() + ", size=" + V.size() + ": " + continuityCheck(V));
    long lowestX = Long.MAX_VALUE;
    long lowestY = Long.MAX_VALUE;
    long highestX = Long.MIN_VALUE;
    long highestY = Long.MIN_VALUE;
    Hashtable<Long, Vector<LayoutNode>> HY = new Hashtable<Long, Vector<LayoutNode>>();
    for (LayoutNode ls : V) {
      if (ls.coord()[0] < lowestX) lowestX = ls.coord()[0];
      if (ls.coord()[1] < lowestY) lowestY = ls.coord()[1];
      if (ls.coord()[0] > highestX) highestX = ls.coord()[0];
      if (ls.coord()[1] > highestY) highestY = ls.coord()[1];
      if (!HY.containsKey(Long.valueOf(ls.coord()[1])))
        HY.put(Long.valueOf(ls.coord()[1]), new Vector<LayoutNode>());
      HY.get(Long.valueOf(ls.coord()[1])).add(ls);
    }
    for (long y = lowestY; y <= highestY; y++) {
      Vector<LayoutNode> ys = HY.get(Long.valueOf(y));
      if (ys != null) {
        Hashtable<Long, LayoutNode> H = new Hashtable<Long, LayoutNode>();
        for (LayoutNode xs : ys) H.put(Long.valueOf(xs.coord()[0]), xs);
        for (int i = 0; i < 3; i++) {
          for (long x = lowestX; x <= highestX; x++)
            if (H.containsKey(Long.valueOf(x)))
              System.out.print(H.get(Long.valueOf(x)).getColorRepresentation(i));
            else System.out.print("   ");
          System.out.println("");
        }
      }
    }
  }
示例#2
0
 public boolean use(LayoutNode n, LayoutTypes nodeType) {
   if (isUsed(n.coord())) return false;
   used.put(getHashCode(n.coord()[0], n.coord()[1]), n);
   set.add(n);
   if (nodeType != null) n.reType(nodeType);
   return true;
 }
示例#3
0
 public static boolean continuityCheck(List<LayoutNode> set) {
   for (int s = 0; s < set.size(); s++) {
     LayoutNode node = set.get(s);
     for (Enumeration<LayoutNode> e = node.links().elements(); e.hasMoreElements(); )
       if (!set.contains(e.nextElement())) return false;
   }
   return true;
 }
示例#4
0
 public void clipLongStreets() {
   @SuppressWarnings("unchecked")
   Vector<LayoutNode> set2 = (Vector<LayoutNode>) set().clone();
   for (Enumeration<LayoutNode> e = set2.elements(); e.hasMoreElements(); ) {
     LayoutNode p = e.nextElement();
     if (isUsed(p) && p.isStreetLike())
       for (int d = 0; d < 4; d++)
         if (p.getLink(d) == null) {
           LayoutNode p2 = getNextNode(p, d);
           if ((p2 != null) && (!p.links().containsValue(p2))) {
             Enumeration<LayoutNode> nodes = p.links().elements();
             LayoutNode p_1 = nodes.nextElement();
             LayoutNode p_2 = nodes.nextElement();
             p.deLink();
             p_1.crossLink(p_2);
             unUse(p);
             LayoutNode p3 = makeNextNode(p2, Directions.getOpDirectionCode(d));
             p2.crossLink(p3);
             use(p3, LayoutTypes.leaf);
             break;
           }
         }
   }
 }
示例#5
0
 public boolean fillMaze(LayoutNode p) {
   Vector<Integer> dirs = new Vector<Integer>();
   for (int i = 0; i < 4; i++) dirs.add(Integer.valueOf(i));
   Vector<Integer> rdirs = new Vector<Integer>();
   while (dirs.size() > 0) {
     int x = r.nextInt(dirs.size());
     Integer dir = dirs.elementAt(x);
     dirs.removeElementAt(x);
     rdirs.addElement(dir);
   }
   for (int r = 0; r < rdirs.size(); r++) {
     Integer dir = rdirs.elementAt(r);
     LayoutNode p2 = getNextNode(p, dir.intValue());
     if (p2 == null) {
       p2 = makeNextNode(p, dir.intValue());
       p.crossLink(p2);
       use(p2, LayoutTypes.interior);
       fillMaze(p2);
     }
   }
   return true;
 }
示例#6
0
 public void unUse(LayoutNode n) {
   used.remove(getHashCode(n.coord()[0], n.coord()[1]));
   set.remove(n);
 }
示例#7
0
 public boolean isUsed(LayoutNode n) {
   return isUsed(n.coord()) && set.contains(n);
 }
示例#8
0
 public void fillInFlags() {
   for (Enumeration<LayoutNode> e = set().elements(); e.hasMoreElements(); ) {
     LayoutNode n = e.nextElement();
     int[] dirs = new int[n.links().size()];
     int x = 0;
     for (Integer dirLink : n.links().keySet()) dirs[x++] = dirLink.intValue();
     n.setExits(dirs);
     if ((dirs.length == 1) && (!n.isFlagged(LayoutFlags.gate))) n.reType(LayoutTypes.leaf);
   }
   for (Enumeration<LayoutNode> e = set().elements(); e.hasMoreElements(); ) {
     LayoutNode n = e.nextElement();
     if (n.links().size() == 2) {
       LayoutFlags flag = null;
       if (n.type() == LayoutTypes.interior)
         for (Integer dirLink : n.links().keySet()) {
           LayoutNode n2 = n.links().get(dirLink);
           if ((n2 != null) && (n2.type() == LayoutTypes.leaf)) flag = LayoutFlags.offleaf;
         }
       if (flag != null) n.flag(flag);
       else {
         Enumeration<Integer> dirs = n.links().keys();
         Integer lN1 = dirs.nextElement();
         Integer lN2 = dirs.nextElement();
         if (lN1.intValue() != Directions.getOpDirectionCode(lN2.intValue()))
           n.flag(LayoutFlags.corner);
       }
     } else if ((n.links().size() == 3)
         && (((n.type() == LayoutTypes.street) || (n.type() != LayoutTypes.surround)))) {
       boolean allStreet = true;
       for (Integer dirLink : n.links().keySet()) {
         LayoutNode n2 = n.links().get(dirLink);
         if ((n2 == null)
             || ((n2.type() != LayoutTypes.street) && (n2.type() != LayoutTypes.surround)))
           allStreet = false;
       }
       if (allStreet) n.flag(LayoutFlags.tee);
     } else if ((n.links().size() == 4)
         && (((n.type() == LayoutTypes.street) || (n.type() != LayoutTypes.surround)))) {
       boolean allStreet = true;
       for (Integer dirLink : n.links().keySet()) {
         LayoutNode n2 = n.links().get(dirLink);
         if ((n2 == null)
             || ((n2.type() != LayoutTypes.street) && (n2.type() != LayoutTypes.surround)))
           allStreet = false;
       }
       if (allStreet) n.flag(LayoutFlags.intersection);
     }
   }
 }
示例#9
0
 public void drawABox(int width, int height) {
   LayoutNode n = new DefaultLayoutNode(new long[] {0, 0});
   n.flag(LayoutFlags.corner);
   for (int y = 0; y < height - 1; y++) {
     use(n, LayoutTypes.surround);
     LayoutNode nn = getNextNode(n, Directions.NORTH);
     if (nn == null) nn = makeNextNode(n, Directions.NORTH);
     n.crossLink(nn);
     nn.flagRun(LayoutRuns.ns);
     n = nn;
   }
   n.flag(LayoutFlags.corner);
   use(n, LayoutTypes.surround);
   n = new DefaultLayoutNode(new long[] {width - 1, 0});
   n.flag(LayoutFlags.corner);
   for (int y = 0; y < height - 1; y++) {
     use(n, LayoutTypes.surround);
     LayoutNode nn = getNextNode(n, Directions.NORTH);
     if (nn == null) nn = makeNextNode(n, Directions.NORTH);
     n.crossLink(nn);
     nn.flagRun(LayoutRuns.ns);
     n = nn;
   }
   n.flag(LayoutFlags.corner);
   use(n, LayoutTypes.surround);
   n = getNode(new long[] {0, 0});
   n.flag(LayoutFlags.corner);
   for (int x = 0; x < width - 1; x++) {
     use(n, LayoutTypes.surround);
     LayoutNode nn = getNextNode(n, Directions.EAST);
     if (nn == null) nn = makeNextNode(n, Directions.EAST);
     n.crossLink(nn);
     nn.flagRun(LayoutRuns.ns);
     n = nn;
   }
   n.flag(LayoutFlags.corner);
   use(n, LayoutTypes.surround);
   n = getNode(new long[] {0, -height + 1});
   n.flag(LayoutFlags.corner);
   for (int x = 0; x < width - 1; x++) {
     use(n, LayoutTypes.surround);
     LayoutNode nn = getNextNode(n, Directions.EAST);
     if (nn == null) nn = makeNextNode(n, Directions.EAST);
     n.crossLink(nn);
     nn.flagRun(LayoutRuns.ns);
     n = nn;
   }
   n.flag(LayoutFlags.corner);
   use(n, LayoutTypes.surround);
 }
示例#10
0
 public LayoutNode getNextNode(LayoutNode n, int dir) {
   LayoutNode next = makeNextNode(n, dir);
   return getNode(next.coord());
 }
示例#11
0
 public LayoutNode makeNextNode(LayoutNode n, int dir) {
   long[] l = makeNextCoord(n.coord(), dir);
   if (l != null) return new DefaultLayoutNode(l);
   return null;
 }