Add distance float position handling with backward compatibility #1

Merged
p.vanderwilt merged 22 commits from :main into main 2025-09-26 11:41:53 +00:00
Showing only changes of commit 3f90685834 - Show all commits

View File

@@ -95,9 +95,7 @@ class MeasurementContainer {
// Turn string positions into numeric values
if (typeof positionValue == "string") {
positionValue = positionValue == "upstream" ? Number.NEGATIVE_INFINITY : positionValue;
positionValue = positionValue == "atEquipment" ? 0.0 : positionValue;
positionValue = positionValue == "downstream" ? Number.POSITIVE_INFINITY : positionValue;
positionValue = this._convertPositionStr2Num(positionValue);
}
this._currentPosition = positionValue;
@@ -330,7 +328,7 @@ class MeasurementContainer {
Object.keys(this.measurements[this._currentType]) : [];
}
getPositions() {
getPositions(asNumber = false) {
if (!this._currentType || !this._currentVariant) {
throw new Error('Type and variant must be specified before listing positions');
}
@@ -340,6 +338,10 @@ class MeasurementContainer {
return [];
}
if (asNumber) {
return Object.keys(this.measurements[this._currentType][this._currentVariant]).map(this._convertPositionNum2Str);
}
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;