UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

45 lines 1.48 kB
import { __decorate, __metadata } from "tslib"; import { Unit } from '../../utils/unit'; import { Vector3 } from '../../utils/math/Vector3'; import { SerializableObject, SerializableMember } from '../decorators'; let Accuracy = class Accuracy { constructor(value, unit) { this.value = value; this._unit = unit; } /** * Convert the value to another unit * @param {Unit} unit Target unit * @returns {Accuracy} Converted value */ to(unit) { if (!unit) { throw new Error(`${this.constructor.name} does not have a unit to convert from!`); } const value = this.value; if (!(value instanceof Vector3) && typeof value !== 'number') { throw new Error(`${this.constructor.name} can not be converted!`); } const result = this.unit.convert(value, unit); return new this.constructor(result, unit); } /** * Unit this value is in * @returns {Unit} Unit this value is in */ get unit() { return this._unit; } clone() { const result = new this.constructor(); result.value = this.value; result._unit = this._unit; return result; } }; __decorate([SerializableMember(), __metadata("design:type", Object)], Accuracy.prototype, "value", void 0); __decorate([SerializableMember({ name: 'unit' }), __metadata("design:type", Unit)], Accuracy.prototype, "_unit", void 0); Accuracy = __decorate([SerializableObject(), __metadata("design:paramtypes", [Object, Object])], Accuracy); export { Accuracy };