/**
  * Set the partition bit to true for segments on the border and where the direction is 0
  *
  * @param sl
  */
 private void setPartitionBitForCertainSegments(ArrayList<Seg> sl) {
   for (int i = 0; i != sl.size(); i++) {
     Seg se = sl.get(i);
     if (((se.x == 0 || se.x == width) && se.dx == 0)
         || ((se.y == 0 || se.y == height) && se.dy == 0)) se.partition = true;
   }
 }
예제 #2
0
 @Test
 public void analyze() throws RuleBaseException, TransformException {
   SortBlock block = define("<sort as='corresponding'>$src</sort>");
   setModGlobalScope(content.query());
   Seg seg = block.createSeg(mod);
   seg.analyze();
   assertThat(block.requiredVariables, is(collection(new QName(null, "src", null))));
 }
예제 #3
0
 private void print(String what, ASTNode where) {
   String addr = StringUtil.addrToString(segment.getCurrentAddress());
   modulePrinter.println(
       segment.getName()
           + " @ "
           + addr
           + ": "
           + what
           + " on line "
           + where.getLeftMostToken().beginLine);
 }
예제 #4
0
 /**
  * Store the content of a leaf node, in particular its list of segments. All entries carry the
  * number of the node as an index and each segment has an additional second index for the segment
  * number.
  *
  * @param doc document to add data to
  * @param mazeXML element to add data to
  * @param number is an index number for this node in the XML format
  * @return the highest used index number, in this case the given number
  */
 int store(Document doc, Element mazeXML, int number) {
   super.store(doc, mazeXML, number); // leaves number unchanged
   if (isleaf == false) System.out.println("WARNING: isleaf flag and class are inconsistent!");
   // store list of segments, store total number of elements first
   MazeFileWriter.appendChild(doc, mazeXML, "numSeg_" + number, slist.size());
   int i = 0;
   for (Seg s : slist) {
     s.storeSeg(doc, mazeXML, number, i);
     i++;
   }
   return number;
 }
예제 #5
0
  /**
   * Sets the seencells bit for all cells of a segment
   *
   * @param seg
   */
  private void udpateSeenCellsForSegment(Seg seg) {
    seg.seen = true; // updates the segment

    int sdx = seg.dx / map_unit; // constant, only set once here
    int sdy = seg.dy / map_unit; // constant, only set once here

    // get initial position right on loop variables sx, sy
    int sx = seg.x / map_unit;
    if (sdx < 0) sx--;
    int sy = seg.y / map_unit;
    if (sdy < 0) sy--;

    // define constants to avoid method calls in following loop
    int sdsx = MazeBuilder.getSign(sdx);
    int sdsy = MazeBuilder.getSign(sdy);
    int bit = (sdx != 0) ? Cells.CW_TOP : Cells.CW_LEFT;
    int len = Math.abs(sdx + sdy);
    // true loop variables are (sx,sy),
    for (int i = 0; i != len; i++) {
      // seencells[sx][sy] |= bit;
      seencells.setBitToOne(sx, sy, bit); // updates the cell
      sx += sdsx;
      sy += sdsy;
    }
  }
 /**
  * Method called in genNodes to determine the minimum of all such grades. The method is static,
  * i.e. it does not update internal attributes and just calculates the returned value.
  *
  * @param sl vector of segments
  * @param pe particular segment
  * @return undocumented
  */
 private int grade_partition(ArrayList<Seg> sl, Seg pe) {
   // copy attributes of parameter pe
   final int x = pe.x;
   final int y = pe.y;
   final int dx = pe.dx;
   final int dy = pe.dy;
   final int inc = (sl.size() >= 100) ? sl.size() / 50 : 1; // increment for iteration below
   // define some local counter
   int lcount = 0, rcount = 0, splits = 0;
   // check all segments
   for (int i = 0; i < sl.size(); i += inc) {
     Seg se = (Seg) sl.get(i);
     int df1x = se.x - x; // difference between beginning of segment and x
     int df1y = se.y - y; // difference between beginning of segment and y
     int sendx = se.x + se.dx; // end of segment
     int sendy = se.y + se.dy; // end of segment
     int df2x = sendx - x; // difference between end of segment and x
     int df2y = sendy - y; // difference between end of segment and y
     int nx = dy;
     int ny = -dx;
     int dot1 = df1x * nx + df1y * ny;
     int dot2 = df2x * nx + df2y * ny;
     if (getSign(dot1) != getSign(dot2)) {
       if (dot1 == 0) dot1 = dot2;
       else if (dot2 != 0) {
         splits++;
         continue;
       }
     }
     if (dot1 > 0 || (dot1 == 0 && se.getDir() == pe.getDir())) {
       rcount++;
     } else if (dot1 < 0 || (dot1 == 0 && se.getDir() == -pe.getDir())) {
       lcount++;
     } else {
       dbg("grade_partition problem: dot1 = " + dot1 + ", dot2 = " + dot2);
     }
   }
   return Math.abs(lcount - rcount) + splits * 3;
 }
예제 #7
0
 protected void addItem(Item i) {
   itemList.add(i);
   segment.advance(i.itemSize());
 }
예제 #8
0
 // .byte directive
 public void reserveBytes(Expr e, Expr f) {
   // TODO: fill section with particular value
   int result = e.evaluate(segment.getCurrentAddress(), this);
   modulePrinter.println("reserveBytes(" + e + ") -> " + result);
   addItem(new Item.UninitializedData(segment, result));
 }
예제 #9
0
 // .org directive
 public void setOrigin(Expr.Constant c) {
   int result = c.evaluate(segment.getCurrentAddress(), this);
   modulePrinter.println("setOrigin(" + c + ") -> " + result);
   segment.setOrigin(result);
 }
 /**
  * It generates the nodes. In every node, it has two section, left and right. It chooses the
  * segment which has the minimum grade value and then split this node into two nodes through this
  * segment. If all the segments in one node are partitioned, it will stop to split.
  *
  * @param sl
  * @return root node for BSP tree
  */
 private BSPNode genNodes(ArrayList<Seg> sl) {
   // if there is no segment with a partition bit set to false, there is nothing else to do and we
   // are at a leaf node
   if (countNonPartitions(sl) == 0) return new BSPLeaf(sl);
   // from the ones that have a partition bit set to false, pick a candidate with a low grade
   Seg pe = findPartitionCandidate(sl);
   // work on segment pe
   // mark pe as partitioned
   pe.partition = true;
   final int x = pe.x;
   final int y = pe.y;
   final int dx = pe.dx;
   final int dy = pe.dy;
   final ArrayList<Seg> lsl = new ArrayList<Seg>();
   final ArrayList<Seg> rsl = new ArrayList<Seg>();
   for (int i = 0; i != sl.size(); i++) {
     Seg se = (Seg) sl.get(i);
     int df1x = se.x - x;
     int df1y = se.y - y;
     int sendx = se.x + se.dx;
     int sendy = se.y + se.dy;
     int df2x = sendx - x;
     int df2y = sendy - y;
     int nx = dy;
     int ny = -dx;
     int dot1 = df1x * nx + df1y * ny;
     int dot2 = df2x * nx + df2y * ny;
     if (getSign(dot1) != getSign(dot2)) {
       if (dot1 == 0) dot1 = dot2;
       else if (dot2 != 0) {
         // we need to split this
         int spx = se.x;
         int spy = se.y;
         if (dx == 0) spx = x;
         else spy = y;
         Seg sps1 = new Seg(se.x, se.y, spx - se.x, spy - se.y, se.dist, colchange);
         Seg sps2 = new Seg(spx, spy, sendx - spx, sendy - spy, se.dist, colchange);
         if (dot1 > 0) {
           rsl.add(sps1);
           lsl.add(sps2);
         } else {
           rsl.add(sps2);
           lsl.add(sps1);
         }
         sps1.partition = sps2.partition = se.partition;
         continue;
       }
     }
     if (dot1 > 0 || (dot1 == 0 && se.getDir() == pe.getDir())) {
       rsl.add(se);
       if (dot1 == 0) se.partition = true;
     } else if (dot1 < 0 || (dot1 == 0 && se.getDir() == -pe.getDir())) {
       lsl.add(se);
       if (dot1 == 0) se.partition = true;
     } else {
       dbg("error xx 1 " + dot1);
     }
   }
   if (lsl.size() == 0) return new BSPLeaf(rsl);
   if (rsl.size() == 0) return new BSPLeaf(lsl);
   return new BSPBranch(x, y, dx, dy, genNodes(lsl), genNodes(rsl)); // recursion on both branches
 }