summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Position.java
blob: cd6218d3e26356d4326cc19be9562863ede73811 (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
package com.mapbox.mapboxsdk.style.light;

/**
 * Position of the light source relative to lit (extruded) geometries.
 * <p>
 * The position is constructed out of a radial coordinate, an azimuthal angle and a polar angle.
 * where the radial coordinate indicates the distance from the center of the base of an object to its light, the
 * azimuthal angle indicates the position of the light relative to 0° (0° when
 * {@link com.mapbox.mapboxsdk.style.layers.Property.ANCHOR} is set to viewport corresponds to the top of the
 * viewport, or 0° when {@link com.mapbox.mapboxsdk.style.layers.Property.ANCHOR} is set to map corresponds to due
 * north, and degrees proceed clockwise), and polar indicates the height of the light
 * (from 0°, directly above, to 180°, directly below).
 */
public class Position {

  private float radialCoordinate;
  private float azimuthalAngle;
  private float polarAngle;

  /**
   * Creates a Position from a radial coordinate, an azimuthal angle and a polar angle.
   *
   * @param radialCoordinate the distance from the center of the base of an object to its light
   * @param azimuthalAngle the position of the light relative to 0°
   * @param polarAngle the height of the light
   */
  public Position(float radialCoordinate, float azimuthalAngle, float polarAngle) {
    this.radialCoordinate = radialCoordinate;
    this.azimuthalAngle = azimuthalAngle;
    this.polarAngle = polarAngle;
  }

  /**
   * Returns a Position from a radial coordinate, an azimuthal angle and a polar angle
   *
   * @param radialCoordinate the radial coordinate
   * @param azimuthalAngle the azimuthal angle
   * @param polarAngle the polar angle
   * @return the created Position object
   */
  public static Position fromPosition(float radialCoordinate, float azimuthalAngle, float polarAngle) {
    return new Position(radialCoordinate, azimuthalAngle, polarAngle);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    Position position = (Position) o;

    if (Float.compare(position.radialCoordinate, radialCoordinate) != 0) {
      return false;
    }
    if (Float.compare(position.azimuthalAngle, azimuthalAngle) != 0) {
      return false;
    }
    return Float.compare(position.polarAngle, polarAngle) == 0;
  }

  @Override
  public int hashCode() {
    int result = (radialCoordinate != +0.0f ? Float.floatToIntBits(radialCoordinate) : 0);
    result = 31 * result + (azimuthalAngle != +0.0f ? Float.floatToIntBits(azimuthalAngle) : 0);
    result = 31 * result + (polarAngle != +0.0f ? Float.floatToIntBits(polarAngle) : 0);
    return result;
  }

  @Override
  public String toString() {
    return "Position{"
      + "radialCoordinate=" + radialCoordinate
      + ", azimuthalAngle=" + azimuthalAngle
      + ", polarAngle=" + polarAngle
      + '}';
  }
}