UNPKG

@openhps/core

Version:

Open Hybrid Positioning System - Core component

58 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Accuracy = void 0; const tslib_1 = require("tslib"); const unit_1 = require("../../utils/unit"); const Vector3_1 = require("../../utils/math/Vector3"); const decorators_1 = require("../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_1.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; } }; exports.Accuracy = Accuracy; tslib_1.__decorate([ (0, decorators_1.SerializableMember)(), tslib_1.__metadata("design:type", Object) ], Accuracy.prototype, "value", void 0); tslib_1.__decorate([ (0, decorators_1.SerializableMember)({ name: 'unit', }), tslib_1.__metadata("design:type", unit_1.Unit) ], Accuracy.prototype, "_unit", void 0); exports.Accuracy = Accuracy = tslib_1.__decorate([ (0, decorators_1.SerializableObject)(), tslib_1.__metadata("design:paramtypes", [Object, Object]) ], Accuracy); //# sourceMappingURL=Accuracy.js.map