• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.uwb;
18 
19 import android.annotation.FloatRange;
20 import android.annotation.NonNull;
21 import android.annotation.SystemApi;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 import java.util.Objects;
26 
27 /**
28  * Angle measurement
29  *
30  * <p>The actual angle is interpreted as:
31  *   {@link #getRadians()} +/- {@link #getErrorRadians()} ()} at {@link #getConfidenceLevel()}
32  *
33  * @hide
34  */
35 @SystemApi
36 public final class AngleMeasurement implements Parcelable {
37     private final double mRadians;
38     private final double mErrorRadians;
39     private final double mConfidenceLevel;
40 
41     /**
42      * Constructs a new {@link AngleMeasurement} object
43      *
44      * @param radians the angle in radians
45      * @param errorRadians the error of the angle measurement in radians
46      * @param confidenceLevel confidence level of the angle measurement
47      *
48      * @throws IllegalArgumentException if the radians, errorRadians, or confidenceLevel is out of
49      *                                  allowed range
50      */
AngleMeasurement( @loatRangefrom = -Math.PI, to = +Math.PI) double radians, @FloatRange(from = 0.0, to = +Math.PI) double errorRadians, @FloatRange(from = 0.0, to = 1.0) double confidenceLevel)51     public AngleMeasurement(
52             @FloatRange(from = -Math.PI, to = +Math.PI) double radians,
53             @FloatRange(from = 0.0, to = +Math.PI) double errorRadians,
54             @FloatRange(from = 0.0, to = 1.0) double confidenceLevel) {
55         if (radians < -Math.PI || radians > Math.PI) {
56             throw new IllegalArgumentException("Invalid radians: " + radians);
57         }
58         mRadians = radians;
59 
60         if (errorRadians < 0.0 || errorRadians > Math.PI) {
61             throw new IllegalArgumentException("Invalid error radians: " + errorRadians);
62         }
63         mErrorRadians = errorRadians;
64 
65         if (confidenceLevel < 0.0 || confidenceLevel > 1.0) {
66             throw new IllegalArgumentException("Invalid confidence level: " + confidenceLevel);
67         }
68         mConfidenceLevel = confidenceLevel;
69     }
70 
71     /**
72      * Angle measurement in radians
73      *
74      * @return angle in radians
75      */
76     @FloatRange(from = -Math.PI, to = +Math.PI)
getRadians()77     public double getRadians() {
78         return mRadians;
79     }
80 
81     /**
82      * Error of angle measurement in radians
83      *
84      * <p>Must be a positive value
85      *
86      * @return angle measurement error in radians
87      */
88     @FloatRange(from = 0.0, to = +Math.PI)
getErrorRadians()89     public double getErrorRadians() {
90         return mErrorRadians;
91     }
92 
93     /**
94      * Angle measurement confidence level expressed as a value between
95      * 0.0 to 1.0.
96      *
97      * <p>A value of 0.0 indicates there is no confidence in the measurement. A value of 1.0
98      * indicates there is maximum confidence in the measurement.
99      *
100      * @return the confidence level of the angle measurement
101      */
102     @FloatRange(from = 0.0, to = 1.0)
getConfidenceLevel()103     public double getConfidenceLevel() {
104         return mConfidenceLevel;
105     }
106 
107     /**
108      * @hide
109     */
110     @Override
equals(Object obj)111     public boolean equals(Object obj) {
112         if (this == obj) {
113             return true;
114         }
115 
116         if (obj instanceof AngleMeasurement) {
117             AngleMeasurement other = (AngleMeasurement) obj;
118             return mRadians == other.getRadians()
119                     && mErrorRadians == other.getErrorRadians()
120                     && mConfidenceLevel == other.getConfidenceLevel();
121         }
122         return false;
123     }
124 
125     /**
126      * @hide
127      */
128     @Override
hashCode()129     public int hashCode() {
130         return Objects.hash(mRadians, mErrorRadians, mConfidenceLevel);
131     }
132 
133     @Override
describeContents()134     public int describeContents() {
135         return 0;
136     }
137 
138     @Override
writeToParcel(@onNull Parcel dest, int flags)139     public void writeToParcel(@NonNull Parcel dest, int flags) {
140         dest.writeDouble(mRadians);
141         dest.writeDouble(mErrorRadians);
142         dest.writeDouble(mConfidenceLevel);
143     }
144 
145     public static final @android.annotation.NonNull Creator<AngleMeasurement> CREATOR =
146             new Creator<AngleMeasurement>() {
147                 @Override
148                 public AngleMeasurement createFromParcel(Parcel in) {
149                     return new AngleMeasurement(in.readDouble(), in.readDouble(), in.readDouble());
150                 }
151 
152                 @Override
153                 public AngleMeasurement[] newArray(int size) {
154                     return new AngleMeasurement[size];
155                 }
156     };
157 }
158