@openhps/core
Version:
Open Hybrid Positioning System - Core component
75 lines • 2.32 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { LengthUnit } from '../../utils';
import { Vector3 } from '../../utils/math';
import { NumberType, SerializableMember, SerializableObject } from '../decorators';
import { RelativePosition } from './RelativePosition';
/**
* Relative 2D Position relative to another object. This indicates the translation
* relative to another reference object.
*/
let Relative2DPosition = class Relative2DPosition extends RelativePosition {
constructor(referenceObject, x, y, unit = LengthUnit.METER) {
super(referenceObject, new 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 Vector3(this.unit.convert(this.x, unit), this.unit.convert(this.y, unit));
} else {
return new 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;
}
};
__decorate([SerializableMember({
numberType: NumberType.DECIMAL
}), __metadata("design:type", Number), __metadata("design:paramtypes", [Number])], Relative2DPosition.prototype, "x", null);
__decorate([SerializableMember({
numberType: NumberType.DECIMAL
}), __metadata("design:type", Number), __metadata("design:paramtypes", [Number])], Relative2DPosition.prototype, "y", null);
Relative2DPosition = __decorate([SerializableObject(), __metadata("design:paramtypes", [Object, Number, Number, LengthUnit])], Relative2DPosition);
export { Relative2DPosition };