fixed error
This commit is contained in:
@ -333,7 +333,7 @@ export class BScanClickHandler {
|
||||
const sweep = sweepHistory[sweepIndex];
|
||||
|
||||
// Use same logic as BScanProcessor: calibrated_data or sweep_data
|
||||
const hasCalibrated = sweep.calibrated_points && sweep.calibrated_points.length > 0;
|
||||
const hasCalibrated = this.hasCalibratedSweepData(sweep);
|
||||
const dataToProcess = hasCalibrated ? sweep.calibrated_points : (sweep.sweep_points || []);
|
||||
const referencePoints = sweep.reference_points || [];
|
||||
const openAirEnabled = config.open_air || false;
|
||||
@ -358,6 +358,90 @@ export class BScanClickHandler {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if sweep contains calibrated data that differs from raw points.
|
||||
* @param {Object} sweep - Sweep data entry from processor state
|
||||
* @returns {boolean} True when calibrated points appear to be applied
|
||||
*/
|
||||
hasCalibratedSweepData(sweep) {
|
||||
const calibratedPoints = Array.isArray(sweep?.calibrated_points) ? sweep.calibrated_points : [];
|
||||
if (calibratedPoints.length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const rawPoints = Array.isArray(sweep?.sweep_points) ? sweep.sweep_points : [];
|
||||
if (rawPoints.length === 0 || calibratedPoints.length !== rawPoints.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const tolerance = 1e-9;
|
||||
let comparablePoints = 0;
|
||||
|
||||
for (let i = 0; i < calibratedPoints.length; i++) {
|
||||
const calibrated = this._extractComplexPoint(calibratedPoints[i]);
|
||||
const raw = this._extractComplexPoint(rawPoints[i]);
|
||||
|
||||
if (!this._canCompareComplexPoints(calibrated, raw)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
comparablePoints++;
|
||||
|
||||
if (!this._areComplexPointsClose(calibrated, raw, tolerance)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
_extractComplexPoint(point) {
|
||||
if (!point) {
|
||||
return { real: NaN, imag: NaN };
|
||||
}
|
||||
|
||||
if (Array.isArray(point)) {
|
||||
return {
|
||||
real: this._toFiniteNumber(point[0]),
|
||||
imag: this._toFiniteNumber(point[1])
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof point === 'object') {
|
||||
const realCandidate = point.real ?? point.r ?? point.Re ?? point.re;
|
||||
const imagCandidate = point.imag ?? point.i ?? point.Im ?? point.im;
|
||||
return {
|
||||
real: this._toFiniteNumber(realCandidate),
|
||||
imag: this._toFiniteNumber(imagCandidate)
|
||||
};
|
||||
}
|
||||
|
||||
return { real: NaN, imag: NaN };
|
||||
}
|
||||
|
||||
_toFiniteNumber(value) {
|
||||
if (typeof value === 'number') {
|
||||
return Number.isFinite(value) ? value : NaN;
|
||||
}
|
||||
if (typeof value === 'string' && value.trim().length > 0) {
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : NaN;
|
||||
}
|
||||
return NaN;
|
||||
}
|
||||
|
||||
_canCompareComplexPoints(a, b) {
|
||||
return Number.isFinite(a.real) && Number.isFinite(a.imag) && Number.isFinite(b.real) && Number.isFinite(b.imag);
|
||||
}
|
||||
|
||||
_areComplexPointsClose(a, b, tolerance) {
|
||||
const realScale = Math.max(1, Math.abs(a.real), Math.abs(b.real));
|
||||
const imagScale = Math.max(1, Math.abs(a.imag), Math.abs(b.imag));
|
||||
|
||||
return Math.abs(a.real - b.real) <= tolerance * realScale &&
|
||||
Math.abs(a.imag - b.imag) <= tolerance * imagScale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show modal with sweep plot
|
||||
* @param {number} sweepNumber - Sweep number (1-based)
|
||||
|
||||
Reference in New Issue
Block a user