Skip to content

Commit 31aab0e

Browse files
committed
refactor(line-selection): extract dx/dy, fix actual 1 px gap
Reviewer-spotted (gemini-code-assist on PR #51): - Hoist dispX2-dispX1 / dispY2-dispY1 into dx, dy locals; less repetition in the perpendicular-vector math. - Offset was lineStrokeWidth / 2 + 1, which puts the selection stroke *centre* 1 px past the body's edge. With a 1 px-wide selection stroke that leaves an actual visual gap of only 0.5 px between the edges. Bump to +1.5 so the gap matches the comment.
1 parent 91a6ab5 commit 31aab0e

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

‎src/components/Canvas/LineObject.tsx‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,21 @@ export function LineObject({
222222
// top) keeps the body's difference-blend intact for reverse
223223
// lines and matches the Illustrator-style stroke selection
224224
// affordance. Guarded against zero-length (degenerate) lines.
225-
const len = Math.hypot(dispX2 - dispX1, dispY2 - dispY1);
225+
//
226+
// Offset breakdown for a 1 px visual gap between body and
227+
// selection edges:
228+
// lineStrokeWidth / 2 — half of the body (centre → body edge)
229+
// 0.5 — half of the 1 px selection stroke
230+
// (centre → selection's body-side edge)
231+
// 1 — actual gap requested between the two
232+
// adjacent edges
233+
const dx = dispX2 - dispX1;
234+
const dy = dispY2 - dispY1;
235+
const len = Math.hypot(dx, dy);
226236
if (len === 0) return null;
227-
const off = lineStrokeWidth / 2 + 1;
228-
const px = (-(dispY2 - dispY1) / len) * off;
229-
const py = ((dispX2 - dispX1) / len) * off;
237+
const off = lineStrokeWidth / 2 + 1.5;
238+
const px = (-dy / len) * off;
239+
const py = (dx / len) * off;
230240
return (
231241
<>
232242
<KLine

0 commit comments

Comments
 (0)