summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/geometry/ProjectedMeters.java
blob: d4e6dc3105205e0e79f4a3934bdc214c697ccce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.mapbox.mapboxsdk.geometry;

import android.os.Parcel;
import android.os.Parcelable;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * ProjectedMeters is a projection of longitude, latitude points in Mercator meters.
 * <p>
 * these have been projected into Mapbox GL's Mercator projection. Instead of decimal
 * degrees, it uses Mercator meters (which are notably not equivalent to SI meters)
 * except at the equator.
 * </p>
 */
public class ProjectedMeters implements Parcelable {

  /**
   * Inner class responsible for recreating Parcels into objects.
   */
  public static final Creator<ProjectedMeters> CREATOR = new Creator<ProjectedMeters>() {
    public ProjectedMeters createFromParcel(@NonNull Parcel in) {
      return new ProjectedMeters(in);
    }

    public ProjectedMeters[] newArray(int size) {
      return new ProjectedMeters[size];
    }
  };

  private double northing;
  private double easting;

  /**
   * Creates a ProjectedMeters based on projected meters in north and east direction.
   *
   * @param northing the northing in meters
   * @param easting  the easting in meters
   */
  @Keep
  public ProjectedMeters(double northing, double easting) {
    this.northing = northing;
    this.easting = easting;
  }

  /**
   * Creates a ProjecteMeters based on another set of projected meters.
   *
   * @param projectedMeters The projected meters to be based on.
   */
  public ProjectedMeters(ProjectedMeters projectedMeters) {
    this.northing = projectedMeters.northing;
    this.easting = projectedMeters.easting;
  }

  /**
   * Creates a ProjectedMeters from a Parcel.
   *
   * @param in The parcel to create from
   * @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
   */
  private ProjectedMeters(Parcel in) {
    northing = in.readDouble();
    easting = in.readDouble();
  }

  /**
   * Get projected meters in north direction.
   *
   * @return Projected meters in north.
   */
  public double getNorthing() {
    return northing;
  }

  /**
   * Get projected meters in east direction.
   *
   * @return Projected meters in east.
   */
  public double getEasting() {
    return easting;
  }

  /**
   * Indicates whether some other object is "equal to" this one.
   *
   * @param other The object to compare this to
   * @return true if equal, false if not
   */
  @Override
  public boolean equals(@Nullable Object other) {
    if (this == other) {
      return true;
    }
    if (other == null || getClass() != other.getClass()) {
      return false;
    }

    ProjectedMeters projectedMeters = (ProjectedMeters) other;

    return Double.compare(projectedMeters.easting, easting) == 0
      && Double.compare(projectedMeters.northing, northing) == 0;
  }

  /**
   * Returns a hash code value for the object.
   *
   * @return the hash code of this
   */
  @Override
  public int hashCode() {
    int result;
    long temp;
    temp = Double.doubleToLongBits(easting);
    result = (int) (temp ^ (temp >>> 32));
    temp = Double.doubleToLongBits(northing);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    return result;
  }

  /**
   * Returns a string representation of the object.
   *
   * @return the string representation of this
   */
  @NonNull
  @Override
  public String toString() {
    return "ProjectedMeters [northing=" + northing + ", easting=" + easting + "]";
  }

  /**
   * Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
   *
   * @return a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
   */
  @Override
  public int describeContents() {
    return 0;
  }

  /**
   * Flatten this object in to a Parcel.
   *
   * @param out   The Parcel in which the object should be written.
   * @param flags Additional flags about how the object should be written
   */
  @Override
  public void writeToParcel(@NonNull Parcel out, int flags) {
    out.writeDouble(northing);
    out.writeDouble(easting);
  }
}