diff --git a/admin-lehrer/components/ocr-pipeline/StepReconstruction.tsx b/admin-lehrer/components/ocr-pipeline/StepReconstruction.tsx index ad374bb..8bb998e 100644 --- a/admin-lehrer/components/ocr-pipeline/StepReconstruction.tsx +++ b/admin-lehrer/components/ocr-pipeline/StepReconstruction.tsx @@ -501,18 +501,18 @@ export function StepReconstruction({ sessionId, onNext }: StepReconstructionProp const cellTop = bboxPct.y const cellBottom = bboxPct.y + bboxPct.h - const cellCenter = cellTop + bboxPct.h / 2 + const boxMid = (boxZonesPct[0].topPct + boxZonesPct[0].bottomPct) / 2 for (const { topPct, bottomPct } of boxZonesPct) { - // Cell ABOVE box: clamp height so bottom doesn't exceed box top - if (cellCenter < topPct && cellBottom > topPct) { - return { ...bboxPct, h: topPct - cellTop } - } - // Cell BELOW box: push top down to box bottom - if (cellCenter > bottomPct && cellTop < bottomPct) { - const newY = bottomPct - return { ...bboxPct, y: newY, h: cellBottom - newY } + // Check if cell overlaps with box zone at all + if (cellBottom <= topPct || cellTop >= bottomPct) continue + + // Cell starts ABOVE box midpoint → belongs above, clamp bottom to box top + if (cellTop < boxMid) { + return { ...bboxPct, h: Math.max(0.5, topPct - cellTop) } } + // Cell starts AT or BELOW box midpoint → belongs below, push top to box bottom + return { ...bboxPct, y: bottomPct, h: Math.max(0.5, cellBottom - bottomPct) } } return bboxPct }