/* * Copyright 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.uwb; import android.annotation.FloatRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; import java.util.Objects; /** * A data point for the distance measurement * *
The actual distance is interpreted as: * {@link #getMeters()} +/- {@link #getErrorMeters()} at {@link #getConfidenceLevel()} * * @hide */ @SystemApi public final class DistanceMeasurement implements Parcelable { private final double mMeters; private final double mErrorMeters; private final double mConfidenceLevel; private DistanceMeasurement(double meters, double errorMeters, double confidenceLevel) { mMeters = meters; mErrorMeters = errorMeters; mConfidenceLevel = confidenceLevel; } /** * Distance measurement in meters * * @return distance in meters */ public double getMeters() { return mMeters; } /** * Error of distance measurement in meters *
Must be positive * * @return error of distance measurement in meters */ @FloatRange(from = 0.0) public double getErrorMeters() { return mErrorMeters; } /** * Distance measurement confidence level expressed as a value between 0.0 to 1.0. * *
A value of 0.0 indicates no confidence in the measurement. A value of 1.0 represents
* maximum confidence in the measurement
*
* @return confidence level
*/
@FloatRange(from = 0.0, to = 1.0)
public double getConfidenceLevel() {
return mConfidenceLevel;
}
/**
* @hide
*/
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DistanceMeasurement) {
DistanceMeasurement other = (DistanceMeasurement) obj;
return mMeters == other.getMeters()
&& mErrorMeters == other.getErrorMeters()
&& mConfidenceLevel == other.getConfidenceLevel();
}
return false;
}
/**
* @hide
*/
@Override
public int hashCode() {
return Objects.hash(mMeters, mErrorMeters, mConfidenceLevel);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeDouble(mMeters);
dest.writeDouble(mErrorMeters);
dest.writeDouble(mConfidenceLevel);
}
public static final @android.annotation.NonNull Creator