@openhps/core
Version:
Open Hybrid Positioning System - Core component
92 lines • 2.96 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Relative2DPosition = void 0;
const tslib_1 = require("tslib");
const utils_1 = require("../../utils");
const math_1 = require("../../utils/math");
const decorators_1 = require("../decorators");
const RelativePosition_1 = require("./RelativePosition");
/**
* Relative 2D Position relative to another object. This indicates the translation
* relative to another reference object.
*/
let Relative2DPosition = class Relative2DPosition extends RelativePosition_1.RelativePosition {
constructor(referenceObject, x, y, unit = utils_1.LengthUnit.METER) {
super(referenceObject, new math_1.Vector3(), unit);
this.referenceValue.x = x ? x : 0;
this.referenceValue.y = y ? y : 0;
}
get x() {
if (!this.referenceValue) {
return undefined;
}
return this.referenceValue.x;
}
set x(value) {
if (!this.referenceValue) {
return;
}
this.referenceValue.x = value;
}
get y() {
if (!this.referenceValue) {
return undefined;
}
return this.referenceValue.y;
}
set y(value) {
if (!this.referenceValue) {
return;
}
this.referenceValue.y = value;
}
fromVector(vector, unit) {
if (unit) {
this.x = unit.convert(vector.x, this.unit);
this.y = unit.convert(vector.y, this.unit);
}
else {
this.x = vector.x;
this.y = vector.y;
}
return this;
}
toVector3(unit) {
if (unit) {
return new math_1.Vector3(this.unit.convert(this.x, unit), this.unit.convert(this.y, unit));
}
else {
return new math_1.Vector3(this.x, this.y);
}
}
/**
* Clone the position
* @returns {Absolute2DPosition} Cloned position
*/
clone() {
const position = super.clone();
position.x = this.x;
position.y = this.y;
return position;
}
};
exports.Relative2DPosition = Relative2DPosition;
tslib_1.__decorate([
(0, decorators_1.SerializableMember)({
numberType: decorators_1.NumberType.DECIMAL,
}),
tslib_1.__metadata("design:type", Number),
tslib_1.__metadata("design:paramtypes", [Number])
], Relative2DPosition.prototype, "x", null);
tslib_1.__decorate([
(0, decorators_1.SerializableMember)({
numberType: decorators_1.NumberType.DECIMAL,
}),
tslib_1.__metadata("design:type", Number),
tslib_1.__metadata("design:paramtypes", [Number])
], Relative2DPosition.prototype, "y", null);
exports.Relative2DPosition = Relative2DPosition = tslib_1.__decorate([
(0, decorators_1.SerializableObject)(),
tslib_1.__metadata("design:paramtypes", [Object, Number, Number, utils_1.LengthUnit])
], Relative2DPosition);
//# sourceMappingURL=Relative2DPosition.js.map