package com.parse;

import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.json.JSONArray;
import org.json.JSONException;

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

        @Override // android.os.Parcelable.Creator
        public ParsePolygon[] newArray(int i) {
            return new ParsePolygon[i];
        }
    };
    public List<ParseGeoPoint> coordinates;

    public ParsePolygon(Parcel parcel) {
        ArrayList arrayList = parcel.readArrayList(null);
        if (arrayList.size() < 3) {
            throw new IllegalArgumentException("Polygon must have at least 3 GeoPoints");
        }
        this.coordinates = arrayList;
    }

    public ParsePolygon(List<ParseGeoPoint> list) {
        if (list.size() < 3) {
            throw new IllegalArgumentException("Polygon must have at least 3 GeoPoints");
        }
        this.coordinates = list;
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x0071  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x00dc  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00df  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean containsPoint(ParseGeoPoint parseGeoPoint) {
        boolean z;
        boolean z2;
        double dMin = this.coordinates.get(0).latitude;
        double dMax = this.coordinates.get(0).latitude;
        double dMin2 = this.coordinates.get(0).longitude;
        double dMax2 = this.coordinates.get(0).longitude;
        for (int i = 1; i < this.coordinates.size(); i++) {
            ParseGeoPoint parseGeoPoint2 = this.coordinates.get(i);
            dMin = Math.min(parseGeoPoint2.latitude, dMin);
            dMax = Math.max(parseGeoPoint2.latitude, dMax);
            dMin2 = Math.min(parseGeoPoint2.longitude, dMin2);
            dMax2 = Math.max(parseGeoPoint2.longitude, dMax2);
        }
        double d = parseGeoPoint.latitude;
        if (d < dMin || d > dMax) {
            z = true;
        } else {
            double d2 = parseGeoPoint.longitude;
            if (d2 >= dMin2 && d2 <= dMax2) {
                z = false;
            }
        }
        if (z) {
            return false;
        }
        int size = this.coordinates.size() - 1;
        boolean z3 = false;
        for (int i2 = 0; i2 < this.coordinates.size(); i2++) {
            double d3 = this.coordinates.get(i2).latitude;
            double d4 = this.coordinates.get(i2).longitude;
            double d5 = this.coordinates.get(size).latitude;
            double d6 = this.coordinates.get(size).longitude;
            boolean z4 = z3;
            if ((d4 > parseGeoPoint.longitude) != (d6 > parseGeoPoint.longitude)) {
                z2 = z4;
                boolean z5 = parseGeoPoint.latitude < (((parseGeoPoint.longitude - d4) * (d5 - d3)) / (d6 - d4)) + d3;
                z3 = !z5 ? !z2 : z2;
                size = i2;
            } else {
                z2 = z4;
            }
            if (!z5) {
            }
            size = i2;
        }
        return z3;
    }

    public JSONArray coordinatesToJSONArray() throws JSONException {
        JSONArray jSONArray = new JSONArray();
        for (ParseGeoPoint parseGeoPoint : this.coordinates) {
            JSONArray jSONArray2 = new JSONArray();
            jSONArray2.put(parseGeoPoint.latitude);
            jSONArray2.put(parseGeoPoint.longitude);
            jSONArray.put(jSONArray2);
        }
        return jSONArray;
    }

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

    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof ParsePolygon)) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        ParsePolygon parsePolygon = (ParsePolygon) obj;
        if (this.coordinates.size() != parsePolygon.coordinates.size()) {
            return false;
        }
        for (int i = 0; i < this.coordinates.size(); i++) {
            if (this.coordinates.get(i).latitude != parsePolygon.coordinates.get(i).latitude || this.coordinates.get(i).longitude != parsePolygon.coordinates.get(i).longitude) {
                return false;
            }
        }
        return true;
    }

    public String toString() {
        return String.format(Locale.US, "ParsePolygon: %s", this.coordinates);
    }

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