From 8c9a027ba4da472745d97f6df88a00dc193b9ed5 Mon Sep 17 00:00:00 2001 From: Syahmi Zul <99678350+syahmizul@users.noreply.github.com> Date: Thu, 19 Jun 2025 20:09:45 +0800 Subject: [PATCH] fix: clarify comments for inclusive range calculation and offset adjustments in OSD positioning --- src/js/tabs/osd.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/js/tabs/osd.js b/src/js/tabs/osd.js index 3d8300ad..52d4f29c 100644 --- a/src/js/tabs/osd.js +++ b/src/js/tabs/osd.js @@ -3088,12 +3088,16 @@ OSD.presetPosition.applyPosition = function (fieldChanged, positionKey) { if (fieldChanged.preview.constructor == Array) { const limits = OSD.searchLimitsElement(fieldChanged.preview); + // Note: Using +1 for inclusive range calculation, which is mathematically + // correct for counting occupied positions. An element spanning coordinates + // -2 to 2 occupies 5 positions: [-2, -1, 0, 1, 2] elementWidth = limits.maxX - limits.minX + 1; elementHeight = limits.maxY - limits.minY + 1; // Offset adjustments are needed because the positioning system expects // these values to account for the difference between logical and visual positioning. - adjustOffsetX = limits.minX; // keep raw limits – the centering maths upstream expects this + // Use raw limits for offsets since they represent coordinate positions, not dimensions + adjustOffsetX = limits.minX; adjustOffsetY = limits.minY; } else if (fieldChanged.preview.constructor === String) { elementHeight = 1; @@ -3147,7 +3151,7 @@ OSD.presetPosition.applyPosition = function (fieldChanged, positionKey) { if (canPlace) { finalPosition = testY * OSD.data.displaySize.x + testX; - // If this doesn't exist then advanced elements won't be where we expect them to be. + // Needed for advanced elements or else they won't be where we expect them to be. finalPosition -= adjustOffsetX; finalPosition -= adjustOffsetY * OSD.data.displaySize.x;