Exemplo n.º 1
0
  /**
   * Computes the absolute distance to the other coordinate's longitude
   *
   * @methodtype get
   * @methodproperty regular
   */
  public double getLongitudinalDistance(SphericCoordinate other) {
    if (other == null) {
      throw new IllegalArgumentException("Other coordinate must not be null");
    }

    double result;

    if (Math.signum(this.getLongitude()) != Math.signum(other.getLatitude())) {
      result = Math.abs(this.getLongitude()) + Math.abs(other.getLongitude());
      if (result > 180.) {
        result = 360. - result;
      }
    } else {
      result = Math.abs(Math.abs(this.getLongitude()) - Math.abs(other.getLongitude()));
    }
    return result;
  }
 @Override
 public boolean equals(Object obj) {
   if (obj == null) return false;
   if (!(obj instanceof SphericCoordinate)) return false;
   SphericCoordinate otherCoordinate = (SphericCoordinate) obj;
   if (latitude == otherCoordinate.getLatitude()
       && longitude == otherCoordinate.getLongitude()
       && radius == otherCoordinate.getRadius()) return true;
   else return false;
 }
  /**
   * @param other the other Coordinate-Object
   * @return distance between the longitude-values of both coordinates as double-value
   * @methodtype query
   */
  public double getLongitudinalDistance(SphericCoordinate secondCoordinate) {
    // preconditions
    assertNotNull(secondCoordinate);

    double longitudinalDistance = this.longitude - secondCoordinate.getLongitude();
    longitudinalDistance = Math.abs(longitudinalDistance);
    // check for shortest way
    if (longitudinalDistance > 180) {
      longitudinalDistance = 360 - longitudinalDistance;
    }

    // postconditions
    assertIsValidDistance(longitudinalDistance);

    return longitudinalDistance;
  }