package com.parse;

import android.os.Parcel;
import android.os.Parcelable;
import java.util.Locale;

/* JADX INFO: loaded from: classes.dex */
public class ParseGeoPoint implements Parcelable {
    public static final Parcelable.Creator<ParseGeoPoint> CREATOR = new Parcelable.Creator<ParseGeoPoint>() { // from class: com.parse.ParseGeoPoint.1
        @Override // android.os.Parcelable.Creator
        public ParseGeoPoint createFromParcel(Parcel parcel) {
            ParseParcelDecoder parseParcelDecoder = ParseParcelDecoder.INSTANCE;
            return new ParseGeoPoint(parcel);
        }

        @Override // android.os.Parcelable.Creator
        public ParseGeoPoint[] newArray(int i) {
            return new ParseGeoPoint[i];
        }
    };
    public double latitude = 0.0d;
    public double longitude = 0.0d;

    public ParseGeoPoint() {
    }

    public ParseGeoPoint(double d, double d2) {
        setLatitude(d);
        setLongitude(d2);
    }

    public ParseGeoPoint(Parcel parcel) {
        setLatitude(parcel.readDouble());
        setLongitude(parcel.readDouble());
    }

    @Override // android.os.Parcelable
    public int describeContents() {
        return 0;
    }

    public double distanceInRadiansTo(ParseGeoPoint parseGeoPoint) {
        double d = this.latitude * 0.017453292519943295d;
        double d2 = this.longitude * 0.017453292519943295d;
        double d3 = parseGeoPoint.latitude * 0.017453292519943295d;
        double d4 = d2 - (parseGeoPoint.longitude * 0.017453292519943295d);
        double dSin = Math.sin((d - d3) / 2.0d);
        double dSin2 = Math.sin(d4 / 2.0d);
        return Math.asin(Math.sqrt(Math.min(1.0d, (Math.cos(d3) * Math.cos(d) * dSin2 * dSin2) + (dSin * dSin)))) * 2.0d;
    }

    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof ParseGeoPoint)) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        ParseGeoPoint parseGeoPoint = (ParseGeoPoint) obj;
        return parseGeoPoint.latitude == this.latitude && parseGeoPoint.longitude == this.longitude;
    }

    public void setLatitude(double d) {
        if (d > 90.0d || d < -90.0d) {
            throw new IllegalArgumentException("Latitude must be within the range (-90.0, 90.0).");
        }
        this.latitude = d;
    }

    public void setLongitude(double d) {
        if (d > 180.0d || d < -180.0d) {
            throw new IllegalArgumentException("Longitude must be within the range (-180.0, 180.0).");
        }
        this.longitude = d;
    }

    public String toString() {
        return String.format(Locale.US, "ParseGeoPoint[%.6f,%.6f]", Double.valueOf(this.latitude), Double.valueOf(this.longitude));
    }

    @Override // android.os.Parcelable
    public void writeToParcel(Parcel parcel, int i) {
        ParseParcelEncoder parseParcelEncoder = ParseParcelEncoder.INSTANCE;
        parcel.writeDouble(this.latitude);
        parcel.writeDouble(this.longitude);
    }
}
