예제 #1
0
파일: Zone.java 프로젝트: xizhonghua/cs675
  /**
   * Check whether a given zone can be merged to this zone
   *
   * @param zone zone to merge
   * @return
   */
  public boolean canMerge(Zone zone) {

    if ((this.x != zone.x && this.y != zone.y)
        || (this.x == zone.x && this.y + this.height != zone.y && zone.y + zone.height != this.y)
        || (this.y == zone.y && this.x + this.width != zone.x && zone.x + zone.width != this.x))
      return false;

    Rectangle newRect = this.union(zone);

    if (newRect.getWidth() * newRect.getHeight()
        != this.getWidth() * this.getHeight() + zone.getWidth() * zone.getHeight()) return false;

    return true;
  }
예제 #2
0
파일: Zone.java 프로젝트: xizhonghua/cs675
  /**
   * Split the zone Update self
   *
   * @return the split zone
   */
  public Zone split() {

    // Split zone
    final int w = this.width;
    final int h = this.height;

    Zone newZone = new Zone();

    if (w == h) {
      // The zone is square, split it vertically
      int sw = w / 2;
      newZone.setBounds(this.x + w - sw, this.y, sw, h);
      this.setSize(w - sw, h);
    } else {
      // The zone is rectangle, split it horizontally
      int sh = h / 2;
      newZone.setBounds(this.x, this.y + h - sh, w, sh);
      this.setSize(w, h - sh);
    }

    // Split files
    for (String key : this.files.keySet()) {
      Point coord = HashUtil.getCoordinate(key);
      if (newZone.contains(coord)) {
        newZone.files.put(key, this.files.get(key));
      }
    }

    for (String key : newZone.files.keySet()) {
      this.files.remove(key);
    }

    // Split neighbors

    return newZone;
  }