Skip to content

Commit 4346f55

Browse files
committed
Fix ruler label placement
1 parent e6437de commit 4346f55

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

frontend/src/components/widgets/inputs/RulerInput.svelte

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
$: isHorizontal = direction === "Horizontal";
3131
$: trackedAxis = isHorizontal ? axes.horiz : axes.vert;
3232
$: otherAxis = isHorizontal ? axes.vert : axes.horiz;
33-
$: otherVec = flipVec(otherAxis.vec, flip);
33+
$: crossAxisDirection = flipVector(otherAxis.vec, flip);
3434
$: stretchFactor = 1 / Math.max(Math.abs(isHorizontal ? trackedAxis.vec[0] : trackedAxis.vec[1]), 1e-10);
3535
$: stretchedSpacing = majorMarkSpacing * stretchFactor;
36-
$: effectiveOrigin = projectOntoRuler(direction, originX, originY, otherVec);
37-
$: svgPath = computeSvgPath(direction, effectiveOrigin, stretchedSpacing, stretchFactor, minorDivisions, microDivisions, rulerLength, otherVec);
38-
$: svgTexts = computeSvgTexts(direction, effectiveOrigin, stretchedSpacing, numberInterval, rulerLength, trackedAxis, otherAxis.vec, tilt);
39-
$: cursorIndicatorPath = computeCursorIndicator(direction, cursorPosition, otherVec);
36+
$: effectiveOrigin = projectOntoRuler(direction, originX, originY, crossAxisDirection);
37+
$: svgPath = computeSvgPath(direction, effectiveOrigin, stretchedSpacing, stretchFactor, minorDivisions, microDivisions, rulerLength, crossAxisDirection);
38+
$: svgTexts = computeSvgTexts(direction, effectiveOrigin, stretchedSpacing, numberInterval, rulerLength, trackedAxis, crossAxisDirection);
39+
$: cursorIndicatorPath = computeCursorIndicator(direction, cursorPosition, crossAxisDirection);
4040
4141
function computeAxes(tilt: number): { horiz: Axis; vert: Axis } {
4242
const normTilt = ((tilt % TAU) + TAU) % TAU;
@@ -54,7 +54,7 @@
5454
return { horiz: posY, vert: negX };
5555
}
5656
57-
function flipVec(vec: [number, number], flipped: boolean): [number, number] {
57+
function flipVector(vec: [number, number], flipped: boolean): [number, number] {
5858
return flipped ? [-vec[0], vec[1]] : vec;
5959
}
6060
@@ -82,14 +82,14 @@
8282
minorDivisions: number,
8383
microDivisions: number,
8484
rulerLength: number,
85-
otherVec: [number, number],
85+
crossAxisDirection: [number, number],
8686
): string {
8787
const adaptive = stretchFactor > 1.3 ? { minor: minorDivisions, micro: 1 } : { minor: minorDivisions, micro: microDivisions };
8888
const divisions = stretchedSpacing / adaptive.minor / adaptive.micro;
8989
const majorMarksFrequency = adaptive.minor * adaptive.micro;
9090
const shiftedOffsetStart = mod(effectiveOrigin, stretchedSpacing) - stretchedSpacing;
9191
92-
const { dx, dy, sxBase, syBase } = tickMarkGeometry(direction, otherVec[0], otherVec[1]);
92+
const { dx, dy, sxBase, syBase } = tickMarkGeometry(direction, crossAxisDirection[0], crossAxisDirection[1]);
9393
9494
let path = "";
9595
let i = 0;
@@ -115,14 +115,13 @@
115115
numberInterval: number,
116116
rulerLength: number,
117117
trackedAxis: Axis,
118-
unflippedOtherVec: [number, number],
119-
tilt: number,
118+
crossAxisDirection: [number, number],
120119
): { transform: string; text: string }[] {
121120
const isVertical = direction === "Vertical";
122121
123-
// Tip offset uses the un-flipped axis so text stays on the correct side of tick marks
124-
const { dx: tipDx, dy: tipDy } = tickMarkGeometry(direction, unflippedOtherVec[0], unflippedOtherVec[1]);
125-
const tiltScale = tilt >= 0 ? 1 : 0.5;
122+
const { dx: tipDx, dy: tipDy } = tickMarkGeometry(direction, crossAxisDirection[0], crossAxisDirection[1]);
123+
const forwardTip = isVertical ? -tipDy : tipDx;
124+
const tiltScale = forwardTip >= 0 ? 1 : 0.5;
126125
const tipOffsetX = tipDx * MAJOR_MARK_THICKNESS * tiltScale;
127126
const tipOffsetY = tipDy * MAJOR_MARK_THICKNESS * tiltScale;
128127
@@ -151,11 +150,11 @@
151150
return results;
152151
}
153152
154-
function computeCursorIndicator(direction: RulerDirection, cursor: { x: number; y: number } | undefined, otherVec: [number, number]): string {
153+
function computeCursorIndicator(direction: RulerDirection, cursor: { x: number; y: number } | undefined, crossAxisDirection: [number, number]): string {
155154
if (cursor === undefined) return "";
156155
157-
const projected = projectOntoRuler(direction, cursor.x, cursor.y, otherVec);
158-
const { dx, dy, sxBase, syBase } = tickMarkGeometry(direction, otherVec[0], otherVec[1]);
156+
const projected = projectOntoRuler(direction, cursor.x, cursor.y, crossAxisDirection);
157+
const { dx, dy, sxBase, syBase } = tickMarkGeometry(direction, crossAxisDirection[0], crossAxisDirection[1]);
159158
160159
// Scale the line so it spans the full ruler bar thickness
161160
const thicknessComponent = Math.abs(direction === "Horizontal" ? dy : dx);

0 commit comments

Comments
 (0)