/**
  * Identify segments of continuous walls in a vertical direction
  *
  * @param sl
  */
 private void generateSegmentsForVerticalWalls(ArrayList<Seg> sl) {
   int x;
   int y;
   // we search for vertical walls, so for each row
   for (x = 0; x != width; x++) {
     y = 0;
     while (y < height) {
       // find the beginning of a segment
       if (cells.hasNoWallOnLeft(x, y)) {
         y++;
         continue;
       }
       int starty = y;
       // find the end of a segment
       while (cells.hasWallOnLeft(x, y)) {
         y++;
         if (y == height) break;
         if (cells.hasWallOnTop(x, y)) break;
       }
       // create segment with (x,starty) being being the actual start position of the segment,
       // y-starty being the positive length
       sl.add(
           new Seg(
               x * Constants.MAP_UNIT,
               starty * Constants.MAP_UNIT,
               0,
               (y - starty) * Constants.MAP_UNIT,
               dists.getDistance(x, starty),
               colchange));
     }
     y = 0;
     while (y < height) {
       // find the beginning of a segment
       if (cells.hasNoWallOnRight(x, y)) {
         y++;
         continue;
       }
       int starty = y;
       // find the end of a segment
       while (cells.hasWallOnRight(x, y)) {
         y++;
         if (y == height) break;
         if (cells.hasWallOnTop(x, y)) break;
       }
       // create segment with (x+1,y) being being one off in both directions from the last cell in
       // this segment, starty-y being the negative length
       // since we are looking at right walls, one off in the right direction (x+1) are then cells
       // that have this segment on its left hand side
       sl.add(
           new Seg(
               (x + 1) * Constants.MAP_UNIT,
               y * Constants.MAP_UNIT,
               0,
               (starty - y) * Constants.MAP_UNIT,
               dists.getDistance(x, starty),
               colchange));
     }
   }
 }
 /**
  * Identify segments of continuous walls in a horizontal direction
  *
  * @param sl
  */
 private void generateSegmentForHorizontalWalls(ArrayList<Seg> sl) {
   int x;
   int y;
   // we search for horizontal walls, so for each column
   for (y = 0; y != height; y++) {
     // first round through rows
     x = 0;
     while (x < width) {
       // find the beginning of a segment
       if (cells.hasNoWallOnTop(x, y)) {
         x++;
         continue;
       }
       // found one
       int startx = x;
       // find the end of a segment
       // follow segment with wall on top till
       // x is the first index of a cell that has no wall on top
       // stop at outer bound or when hitting a wall (cell has wall on left)
       // such that length of the segment is startx-x, which is a negative value btw
       while (cells.hasWallOnTop(x, y)) {
         x++;
         if (x == width) break;
         if (cells.hasWallOnLeft(x, y)) break;
       }
       // create segment with (x,y) being the end positions, startx-x being the negative length
       // note the (x,y) is not part of the segment
       sl.add(
           new Seg(
               x * Constants.MAP_UNIT,
               y * Constants.MAP_UNIT,
               (startx - x) * Constants.MAP_UNIT,
               0,
               dists.getDistance(startx, y),
               colchange));
     }
     // second round through rows, same for bottom walls
     x = 0;
     while (x < width) {
       // find the beginning of a segment
       if (cells.hasNoWallOnBottom(x, y)) {
         x++;
         continue;
       }
       int startx = x;
       // find the end of a segment
       while (cells.hasWallOnBottom(x, y)) {
         x++;
         if (x == width) break;
         if (cells.hasWallOnLeft(x, y)) break;
       }
       // create segment with (startx,y+1) being one below the start position, x-startx being the
       // positive length
       // so this may represent a bottom wall segment as a top wall segment one below
       sl.add(
           new Seg(
               startx * Constants.MAP_UNIT,
               (y + 1) * Constants.MAP_UNIT,
               (x - startx) * Constants.MAP_UNIT,
               0,
               dists.getDistance(startx, y),
               colchange));
     }
   }
 }