Ejemplo n.º 1
0
  /**
   * Returns a flag indicating if the geometry matches that of the specified grid geometry. The
   * geometries are considered a match if they contain the same corner points, number of rows and
   * number of columns.
   *
   * @param geometry the geometry to compare.
   * @return <i>true</i> if geometries match; <i>false</i> if not.
   */
  public boolean matchesGeometry(final GridGeometry2d gridGeometry) {
    // Check that the number of lines are equal.
    if (getNumLines() != gridGeometry.getNumLines()) {
      return false;
    }

    // Check each line.
    int numLines = getNumLines();
    for (int i = 0; i < numLines; i++) {
      // Check that the # of points in each line are equal.
      CoordinateSeries points1 = getLine(i).getPoints();
      CoordinateSeries points2 = gridGeometry.getLine(i).getPoints();
      if (points1.getNumPoints() != points2.getNumPoints()) {
        return false;
      }
      // Check that the point x,y coordinates are equal.
      for (int j = 0; j < points1.getNumPoints(); j++) {
        if (!MathUtil.isEqual(points1.getX(j), points2.getX(j))
            || !MathUtil.isEqual(points1.getY(j), points2.getY(j))) {
          return false;
        }
      }
    }

    // The match conditions have been satisfied.
    return true;
  }
Ejemplo n.º 2
0
 /**
  * Checks if an object is "equal" to this one. To be considered "equal", the object be an instance
  * of the <code>GridGeometry2d</code> class, and its corner points and row,column definitions must
  * be the same.
  *
  * @param object the object to check for equality.
  * @return <i>true</i> if the object is "equal"; <i>false</i> if not.
  */
 @Override
 public boolean equals(final Object object) {
   // Check that it is an instance of a grid geometry.
   if (object != null && object instanceof GridGeometry2d) {
     GridGeometry2d grid = (GridGeometry2d) object;
     // Compare the display names.
     if (!getDisplayName().equals(grid.getDisplayName())) {
       return false;
     }
     // If the display names match, then compare the geometries.
     return matchesGeometry(grid);
   }
   return false;
 }