Пример #1
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);
     }
   }
 }
Пример #2
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);
 }