@openhps/core
Version:
Open Hybrid Positioning System - Core component
63 lines • 2.05 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { NumberType, SerializableMember, SerializableObject } from '../decorators';
import { LengthUnit, Vector3 } from '../../utils';
import { Absolute2DPosition } from './Absolute2DPosition';
/**
* Absolute cartesian 3D position. This class uses a {@link Vector3}. This location can be used both as
* an absolute location or relative location.
* @category Position
*/
let Absolute3DPosition = class Absolute3DPosition extends Absolute2DPosition {
constructor(x, y, z, unit = LengthUnit.METER) {
super(x, y, unit);
this.vector.z = z ? z : 0;
}
get z() {
if (!this.vector) {
return undefined;
}
return this.vector.z;
}
set z(value) {
if (!this.vector) {
return;
}
this.vector.z = value;
}
fromVector(vector, unit) {
var _a, _b;
if (unit) {
this.x = unit.convert(vector.x, this.unit);
this.y = unit.convert(vector.y, this.unit);
this.z = unit.convert((_a = vector.z) !== null && _a !== void 0 ? _a : 0, this.unit);
} else {
this.x = vector.x;
this.y = vector.y;
this.z = (_b = vector.z) !== null && _b !== void 0 ? _b : 0;
}
return this;
}
toVector3(unit) {
if (unit) {
return new Vector3(this.unit.convert(this.x, unit), this.unit.convert(this.y, unit), this.unit.convert(this.z, unit));
} else {
return new Vector3(this.x, this.y, this.z);
}
}
/**
* Clone the position
* @returns {Absolute3DPosition} Cloned position
*/
clone() {
const position = super.clone();
position.x = this.x;
position.y = this.y;
position.z = this.z;
return position;
}
};
__decorate([SerializableMember({
numberType: NumberType.DECIMAL
}), __metadata("design:type", Number), __metadata("design:paramtypes", [Number])], Absolute3DPosition.prototype, "z", null);
Absolute3DPosition = __decorate([SerializableObject(), __metadata("design:paramtypes", [Number, Number, Number, LengthUnit])], Absolute3DPosition);
export { Absolute3DPosition };