Exemplo n.º 1
0
 /** Add the other IntMatrix to this one. */
 public void add(IntMatrix other, Position pos) {
   for (int i = 0; i < other.getHeight(); i++) {
     for (int j = 0; j < other.getWidth(); j++) {
       if (other.get(i, j) > 0) {
         this.set(pos.getRow() + i, pos.getColumn() + j, other.get(i, j));
       }
     }
   }
 }
Exemplo n.º 2
0
 /** Rotate the source IntMatrix clockwise and return the new created one. */
 public static IntMatrix transform(IntMatrix source) {
   IntMatrix target = new IntMatrix(source.getWidth(), source.getHeight());
   for (int i = 0; i < target.getHeight(); i++) {
     for (int j = 0; j < target.getWidth(); j++) {
       target.set(i, j, source.get(source.getHeight() - j - 1, i));
     }
   }
   return target;
 }
Exemplo n.º 3
0
  /** Return true if part of the other IntMatrix can be placed in this one. */
  public boolean canPartlyContain(IntMatrix other, Position pos, int begin) {
    if (pos.getRow() < 0 || pos.getColumn() < 0) {
      return false;
    }

    if (pos.getColumn() + other.getWidth() > this.width) {
      return false;
    }

    if (pos.getRow() + other.getHeight() - begin > this.height) {
      return false;
    }

    for (int i = begin; i < other.getHeight(); i++) {
      for (int j = 0; j < other.getWidth(); j++) {
        if (other.get(i, j) > 0 && this.get(i + pos.getRow() - begin, j + pos.getColumn()) > 0) {
          return false;
        }
      }
    }
    return true;
  }