Add distance float position handling with backward compatibility #1
@@ -95,9 +95,7 @@ class MeasurementContainer {
|
|||||||
|
|
||||||
// Turn string positions into numeric values
|
// Turn string positions into numeric values
|
||||||
if (typeof positionValue == "string") {
|
if (typeof positionValue == "string") {
|
||||||
positionValue = positionValue == "upstream" ? Number.NEGATIVE_INFINITY : positionValue;
|
positionValue = this._convertPositionStr2Num(positionValue);
|
||||||
positionValue = positionValue == "atEquipment" ? 0.0 : positionValue;
|
|
||||||
positionValue = positionValue == "downstream" ? Number.POSITIVE_INFINITY : positionValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._currentPosition = positionValue;
|
this._currentPosition = positionValue;
|
||||||
@@ -330,7 +328,7 @@ class MeasurementContainer {
|
|||||||
Object.keys(this.measurements[this._currentType]) : [];
|
Object.keys(this.measurements[this._currentType]) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
getPositions() {
|
getPositions(asNumber = false) {
|
||||||
if (!this._currentType || !this._currentVariant) {
|
if (!this._currentType || !this._currentVariant) {
|
||||||
throw new Error('Type and variant must be specified before listing positions');
|
throw new Error('Type and variant must be specified before listing positions');
|
||||||
}
|
}
|
||||||
@@ -339,6 +337,10 @@ class MeasurementContainer {
|
|||||||
!this.measurements[this._currentType][this._currentVariant]) {
|
!this.measurements[this._currentType][this._currentVariant]) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (asNumber) {
|
||||||
|
return Object.keys(this.measurements[this._currentType][this._currentVariant]).map(this._convertPositionNum2Str);
|
||||||
|
}
|
||||||
|
|
||||||
return Object.keys(this.measurements[this._currentType][this._currentVariant]);
|
return Object.keys(this.measurements[this._currentType][this._currentVariant]);
|
||||||
}
|
}
|
||||||
@@ -415,6 +417,34 @@ class MeasurementContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_convertPositionStr2Num(positionString) {
|
||||||
|
switch(positionString) {
|
||||||
|
case "atEquipment":
|
||||||
|
return 0;
|
||||||
|
case "upstream":
|
||||||
|
return Number.POSITIVE_INFINITY;
|
||||||
|
case "downstream":
|
||||||
|
return Number.NEGATIVE_INFINITY;
|
||||||
|
|
||||||
|
default:
|
||||||
|
this.logger.error(`Invalid positionVsParent provided: ${positionString}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_convertPositionNum2Str(positionValue) {
|
||||||
|
if (positionValue == 0) {
|
||||||
|
return "atEquipment";
|
||||||
|
}
|
||||||
|
if (positionValue < 0) {
|
||||||
|
return "upstream";
|
||||||
|
}
|
||||||
|
if (positionValue > 0) {
|
||||||
|
return "downstream";
|
||||||
|
}
|
||||||
|
this.logger.error(`Invalid position provided: ${positionValue}`);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = MeasurementContainer;
|
module.exports = MeasurementContainer;
|
||||||
|
|||||||
Reference in New Issue
Block a user