UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

65 lines 2.49 kB
import { __decorate, __metadata } from "tslib"; import { TimeService } from '../../service/TimeService'; import { Unit } from '../../utils'; import { Vector3 } from '../../utils/math'; import { SerializableMember, SerializableObject, NumberType } from '../decorators'; import { Accuracy } from './Accuracy'; import { Accuracy1D } from './Accuracy1D'; /** * 3D vector sensor value with accuracy and timestamp. */ let SensorValue = class SensorValue extends Vector3 { constructor(x, y, z, unit, defaultUnit, accuracy) { var _a; if (unit && defaultUnit) { super(unit.convert(x ? x : 0, defaultUnit), unit.convert(y ? y : 0, defaultUnit), unit.convert(z ? z : 0, defaultUnit)); this._defaultUnit = defaultUnit; } else { super(x, y, z); } this.unit = (_a = defaultUnit !== null && defaultUnit !== void 0 ? defaultUnit : unit) !== null && _a !== void 0 ? _a : Unit.UNKNOWN; this.timestamp = TimeService.now(); this.accuracy = accuracy || new Accuracy1D(1, this._defaultUnit || Unit.UNKNOWN); } /** * Set the accuracy of the absolute position * @param {number | Accuracy} accuracy Accuracy object or number * @returns {SensorValue} instance */ setAccuracy(accuracy) { if (typeof accuracy === 'number') { this.accuracy = new Accuracy1D(accuracy, this._defaultUnit); } else { this.accuracy = accuracy; } return this; } /** * Convert sensor value to tuple * @param {Unit} [unit] Conversion unit * @returns {Vector3Tuple} Tuple of three numbers */ toTuple(unit) { if (unit) { return [this.unit.convert(this.x, unit), this.unit.convert(this.y, unit), this.unit.convert(this.z, unit)]; } else { return this.toArray(); } } clone() { const vector = super.clone(); vector.accuracy = this.accuracy; vector.timestamp = this.timestamp; return vector; } }; __decorate([SerializableMember({ isRequired: false, numberType: NumberType.LONG }), __metadata("design:type", Number)], SensorValue.prototype, "timestamp", void 0); __decorate([SerializableMember({ isRequired: false }), __metadata("design:type", Accuracy)], SensorValue.prototype, "accuracy", void 0); __decorate([SerializableMember(() => Unit), __metadata("design:type", Object)], SensorValue.prototype, "unit", void 0); SensorValue = __decorate([SerializableObject(), __metadata("design:paramtypes", [Number, Number, Number, Unit, Object, Accuracy])], SensorValue); export { SensorValue };