From f0726d9a2b10f3439bd9c7f3fc726d50266acea0 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Wed, 4 Mar 2026 11:12:13 +0100 Subject: [PATCH] fix: shrink overlapping neighbors after narrow column expansion When a narrow column expands into neighbor space, the neighbor's boundaries must be adjusted to avoid overlap. After expansion, left neighbor's right edge and right neighbor's left edge are trimmed to match the expanded column's new boundaries, with words re-assigned. Co-Authored-By: Claude Opus 4.6 --- klausur-service/backend/cv_vocab_pipeline.py | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/klausur-service/backend/cv_vocab_pipeline.py b/klausur-service/backend/cv_vocab_pipeline.py index 33a5a3a..a10a0c7 100644 --- a/klausur-service/backend/cv_vocab_pipeline.py +++ b/klausur-service/backend/cv_vocab_pipeline.py @@ -1976,6 +1976,41 @@ def expand_narrow_columns( "ExpandNarrowCols: col %d (%.1f%% → %.1f%%) x=%d w=%d words=%d", i, orig_pct, g.width / content_w * 100, g.x, g.width, g.word_count) + # --- Shrink overlapping neighbors to match new boundaries --- + # Left neighbor: its right edge must not exceed our new left edge + if i > 0: + left_nb = geometries[i - 1] + nb_right = left_nb.x + left_nb.width + if nb_right > g.x: + left_nb.width = g.x - left_nb.x + if left_nb.width < 0: + left_nb.width = 0 + left_nb.width_ratio = left_nb.width / content_w if content_w > 0 else 0.0 + # Re-assign words + nb_left_rel = left_nb.x - left_x + nb_right_rel = nb_left_rel + left_nb.width + left_nb.words = [wd for wd in word_dicts + if nb_left_rel <= wd['left'] < nb_right_rel] + left_nb.word_count = len(left_nb.words) + + # Right neighbor: its left edge must not be before our new right edge + if i + 1 < len(geometries): + right_nb = geometries[i + 1] + my_right = g.x + g.width + if right_nb.x < my_right: + old_right_edge = right_nb.x + right_nb.width + right_nb.x = my_right + right_nb.width = old_right_edge - right_nb.x + if right_nb.width < 0: + right_nb.width = 0 + right_nb.width_ratio = right_nb.width / content_w if content_w > 0 else 0.0 + # Re-assign words + nb_left_rel = right_nb.x - left_x + nb_right_rel = nb_left_rel + right_nb.width + right_nb.words = [wd for wd in word_dicts + if nb_left_rel <= wd['left'] < nb_right_rel] + right_nb.word_count = len(right_nb.words) + return geometries