Skip to content

Commit 263d86d

Browse files
fix(ui): points where x=255 sorted incorrectly
1 parent 0921805 commit 263d86d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

invokeai/frontend/web/src/features/controlLayers/components/RasterLayer/RasterLayerCurvesAdjustmentsEditor.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,18 @@ const clamp = (v: number, min: number, max: number) => (v < min ? min : v > max
2929

3030
const sortPoints = (pts: Array<[number, number]>) =>
3131
[...pts]
32-
.sort((a, b) => a[0] - b[0])
33-
.map(([x, y]) => [clamp(Math.round(x), 0, 255), clamp(Math.round(y), 0, 255)] as [number, number]);
32+
.sort((a, b) => {
33+
const xDiff = a[0] - b[0];
34+
if (xDiff) {
35+
return xDiff;
36+
}
37+
if (a[0] === 0 || a[0] === 255) {
38+
return a[1] - b[1];
39+
}
40+
return 0;
41+
})
42+
// Finally, clamp to valid range and round to integers
43+
.map(([x, y]) => [clamp(Math.round(x), 0, 255), clamp(Math.round(y), 0, 255)] satisfies [number, number]);
3444

3545
// Base canvas logical coordinate system (used for aspect ratio & initial sizing)
3646
const CANVAS_WIDTH = 256;

0 commit comments

Comments
 (0)