Exemplo n.º 1
0
 /** Returns {@code true} if this direct position is equals to the given object. */
 @Override
 public boolean equals(final Object object) {
   if (object instanceof DirectPosition) {
     final DirectPosition other = (DirectPosition) object;
     if (other.getCoordinateReferenceSystem() == null) {
       return Arrays.equals(ordinates, other.getCoordinate());
     }
   }
   return false;
 }
Exemplo n.º 2
0
  /**
   * Executes a linear Interpolation between two positions and returns the DirectPosition at the
   * distance 'par' on this straight line
   *
   * <p>This method is NON-ROBUST, e.g. it might suffer by errors caused by the Floating-point
   * arithmetic
   *
   * @param p0 - start position of linear interpolation
   * @param p1 - end position of linear interpolation
   * @param par - distance on the straight line, for which to search DirectPosition (from p0 to p1)
   * @return Position on the straight line at parameter 'par'
   */
  public static DirectPositionImpl linearInterpolate(
      DirectPosition p0, DirectPosition p1, double par) {
    // Test ok

    // 0.0 <= factor <= 1.0
    // par = 0 => result = dp0
    // par = 1 => result = dp1
    double[] coord = AlgoPointND.evaluate(p0.getCoordinates(), p1.getCoordinates(), par);
    return new DirectPositionImpl(p0.getCoordinateReferenceSystem(), coord);
  }
Exemplo n.º 3
0
 /**
  * Make sure that the specified location uses the same CRS as this one.
  *
  * @param location
  * @throws MismatchedReferenceSystemException if the CRS are incompatible.
  */
 protected void ensureCompatibleReferenceSystem(DirectPosition location) {
   if (crs != null) {
     final CoordinateReferenceSystem other = location.getCoordinateReferenceSystem();
     if (other != null) {
       if (!CRS.equalsIgnoreMetadata(crs, other)) {
         throw new MismatchedReferenceSystemException(
             Errors.format(ErrorKeys.MISMATCHED_COORDINATE_REFERENCE_SYSTEM));
       }
     }
   }
 }
 /** Returns a hash value for the given coordinate. */
 static int hashCode(final DirectPosition position) {
   final int dimension = position.getDimension();
   int code = 1;
   for (int i = 0; i < dimension; i++) {
     final long bits = Double.doubleToLongBits(position.getOrdinate(i));
     code = 31 * code + ((int) (bits) ^ (int) (bits >>> 32));
   }
   final CoordinateReferenceSystem crs = position.getCoordinateReferenceSystem();
   if (crs != null) {
     code += crs.hashCode();
   }
   return code;
 }
 /**
  * Returns {@code true} if the specified object is also a {@linkplain DirectPosition direct
  * position} with equals {@linkplain #getCoordinate coordinate} and {@linkplain
  * #getCoordinateReferenceSystem CRS}.
  *
  * @param object The object to compare with this position.
  * @return {@code true} if the given object is equals to this position.
  */
 @Override
 public boolean equals(final Object object) {
   if (object instanceof DirectPosition) {
     final DirectPosition that = (DirectPosition) object;
     final int dimension = getDimension();
     if (dimension == that.getDimension()) {
       for (int i = 0; i < dimension; i++) {
         if (!Utilities.equals(this.getOrdinate(i), that.getOrdinate(i))) {
           return false;
         }
       }
       if (Utilities.equals(
           this.getCoordinateReferenceSystem(), that.getCoordinateReferenceSystem())) {
         assert hashCode() == that.hashCode() : this;
         return true;
       }
     }
   }
   return false;
 }