Stirling-Tools/Stirling-PDF · error · Error
Invalid PDF distance (must be positive)
Error message
Invalid PDF distance (must be positive)
What it means
Thrown by calculateCalibratedScale when pdfDistancePts fails Number.isFinite or is <= 0. pdfDistancePts is the distance between two calibration points measured in PDF points (1/72 inch) and is divided into realDistance to derive the scale factor, so it must be a positive finite number.
Source
Thrown at frontend/editor/src/core/utils/measurementUtils.ts:363
}
const baseFactor = getUnitFactor(unit);
if (!baseFactor) {
return null;
}
// ratio = factor / baseFactor
const ratio = factor / baseFactor;
return Number.isFinite(ratio) && ratio > 0 ? ratio : null;
}
export function calculateCalibratedScale(
pdfDistancePts: number,
realDistance: number,
unit: string,
): MeasureScale {
if (!Number.isFinite(pdfDistancePts) || pdfDistancePts <= 0) {
throw new Error("Invalid PDF distance (must be positive)");
}
if (!Number.isFinite(realDistance) || realDistance <= 0) {
throw new Error("Invalid real-world distance (must be positive)");
}
const baseFactor = getUnitFactor(unit);
if (!baseFactor) {
throw new Error(`Unsupported unit: ${unit}`);
}
const factor = realDistance / pdfDistancePts;
const ratio = deriveRatioFromFactor(factor, unit);
return {
factor,
ratio,
unit,View on GitHub (pinned to 9ef20dcab8)
Solutions
- Reject calibration when the two points are within an epsilon (e.g. < 1pt) and prompt the user to drag further.
- Validate PagePoint coordinates are finite numbers before computing distance.
- Ensure page geometry (width/height/rotation/scale) is loaded before enabling the calibration gesture.
- Wrap calculateCalibratedScale in try/catch at the UI layer and show an actionable message.
Example fix
// before
const scale = calculateCalibratedScale(pdfDistancePts, realDistance, unit);
// after
if (pdfDistancePts < 1) {
throw new Error("Click and drag across the feature you want to measure; the measured distance is too small.");
}
const scale = calculateCalibratedScale(pdfDistancePts, realDistance, unit); Defensive patterns
Strategy: validation
Validate before calling
if (!Number.isFinite(pdfDistancePts) || pdfDistancePts < 1) {
throw new Error("Calibration failed: drag across a larger feature (measured distance too small).");
}
const scale = calculateCalibratedScale(pdfDistancePts, realDistance, unit); Type guard
const isValidPdfDistance = (d: unknown): d is number => typeof d === "number" && Number.isFinite(d) && d > 0;
Prevention
- Reject calibration when the two points are within an epsilon (< 1pt).
- Confirm PagePoint coordinates are finite before computing distance.
- Ensure page geometry is loaded before enabling the calibration gesture.
When it happens
Trigger: Two calibration clicks land on the same coordinate (distance 0); the measurement tool computes distance from an uninitialized/deleted PagePoint (NaN); a corrupt or zero-size page geometry yields 0; Infinity from a broken coordinate transform.
Common situations: User clicks without dragging during calibration; page viewport math returns NaN for a rotated/scaled page; race condition where calibration fires before the page geometry is loaded.
Related errors
- Invalid scale ratio: ${ratio}
- Invalid real-world distance (must be positive)
- Unsupported unit: ${unit}
- No team resolved yet
- No automation configuration provided
AI-assisted analysis of Stirling-Tools/Stirling-PDF@9ef20dcab8 (2026-08-13).
Data as JSON: /api/errors/e6d514cb96f96a5a.
Report an issue: GitHub.