Skip to content

Commit 0826d9d

Browse files
committed
refactor: address gemini review round 2 on PR #52
- BarcodeObject: revert textElements guard from Array.isArray to truthy check. Non-EAN rotated barcodes assign a single ReactNode (not an array), which the stricter check incorrectly filtered out, killing HRI text rendering. - snapGuides.computePointSnap: allow snapping to the label rect's centre in addition to its edges. Neighbour objects stay edge-only so the original 50%-snap regression remains fixed.
1 parent 8b002fb commit 0826d9d

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎src/components/Canvas/BarcodeObject.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ export function BarcodeObject({
695695
strokeWidth={isSelected ? 2 : 0}
696696
strokeScaleEnabled={false}
697697
/>
698-
{Array.isArray(textElements) && textElements.length > 0 && (
698+
{textElements && (
699699
<Group ref={excludeGroupFromBbox}>{textElements}</Group>
700700
)}
701701
</Group>

‎src/lib/snapGuides.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,21 @@ describe("computePointSnap", () => {
192192

193193
it("uses the label rect for edge alignment too", () => {
194194
const lbl = r("_lbl", 0, 0, 1000, 600);
195+
// y=300 sits exactly on the label's vertical centre — a valid
196+
// label-centre snap, so two guides fire (right edge + centre).
195197
const result = computePointSnap({ x: 998, y: 300 }, [], 6, lbl);
196198
expect(result.x).toBe(1000); // right edge of label
197-
expect(result.guides).toHaveLength(1);
199+
expect(result.y).toBe(300); // label vertical centre
200+
expect(result.guides).toHaveLength(2);
201+
});
202+
203+
it("snaps to label centre (allowed for label only, not for neighbour objects)", () => {
204+
const lbl = r("_lbl", 0, 0, 1000, 600);
205+
// Point near horizontal centre of label (500, 300).
206+
const result = computePointSnap({ x: 502, y: 302 }, [], 6, lbl);
207+
expect(result.x).toBe(500);
208+
expect(result.y).toBe(300);
209+
expect(result.guides).toHaveLength(2);
198210
});
199211

200212
it("respects the threshold — far targets are ignored", () => {

‎src/lib/snapGuides.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ export function computePointSnap(
5555
consider(endEdge, perpStart, perpEnd);
5656
}
5757
if (labelRect) {
58+
// Label edges *and* center are valid endpoint snap targets. Centre
59+
// is intentionally only allowed for the label (not for other
60+
// objects) — endpoint alignment to a neighbour's midpoint produced
61+
// the "50 %" artefact this helper was created to avoid.
5862
const startEdge = axis === 'x' ? labelRect.x : labelRect.y;
59-
const endEdge = startEdge + (axis === 'x' ? labelRect.width : labelRect.height);
63+
const size = axis === 'x' ? labelRect.width : labelRect.height;
64+
const endEdge = startEdge + size;
65+
const center = startEdge + size / 2;
6066
const perpStart = axis === 'x' ? labelRect.y : labelRect.x;
6167
const perpEnd = perpStart + (axis === 'x' ? labelRect.height : labelRect.width);
6268
consider(startEdge, perpStart, perpEnd);
69+
consider(center, perpStart, perpEnd);
6370
consider(endEdge, perpStart, perpEnd);
6471
}
6572
return { value: bestValue, guides: bestGuides };

0 commit comments

Comments
 (0)