Skip to content

Commit f713435

Browse files
Revert "lints"
This reverts commit 2952988.
1 parent 6b0a022 commit f713435

File tree

5 files changed

+61
-86
lines changed

5 files changed

+61
-86
lines changed

invokeai/frontend/web/src/features/controlLayers/components/InpaintMask/InpaintMaskBboxAdjuster.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
33
import { bboxChangedFromCanvas } from 'features/controlLayers/store/canvasSlice';
44
import { selectMaskBlur } from 'features/controlLayers/store/paramsSlice';
55
import { selectCanvasSlice } from 'features/controlLayers/store/selectors';
6-
import type {
6+
import type {
7+
Rect,
78
CanvasBrushLineState,
89
CanvasBrushLineWithPressureState,
910
CanvasEraserLineState,
1011
CanvasEraserLineWithPressureState,
11-
CanvasImageState,
1212
CanvasRectState,
13-
Rect,
13+
CanvasImageState,
1414
} from 'features/controlLayers/store/types';
15+
import { transformMaskObjectsRelativeToBbox, calculateMaskBoundsFromBitmap } from 'features/controlLayers/util/maskObjectTransform';
1516
import { convertTransformedToOriginal } from 'features/controlLayers/util/coordinateTransform';
16-
import {
17-
calculateMaskBoundsFromBitmap,
18-
transformMaskObjectsRelativeToBbox,
19-
} from 'features/controlLayers/util/maskObjectTransform';
2017
import { memo, useCallback, useMemo } from 'react';
2118
import { useTranslation } from 'react-i18next';
2219
import { PiCropBold } from 'react-icons/pi';
@@ -46,7 +43,7 @@ export const InpaintMaskBboxAdjuster = memo(() => {
4643
| CanvasRectState
4744
| CanvasImageState
4845
)[] = [];
49-
46+
5047
for (const mask of inpaintMasks) {
5148
if (!mask.isEnabled || !mask.objects || mask.objects.length === 0) {
5249
continue;
@@ -65,7 +62,7 @@ export const InpaintMaskBboxAdjuster = memo(() => {
6562

6663
// Calculate bounds from the rendered bitmap for accurate results
6764
const maskBounds = calculateMaskBoundsFromBitmap(allObjects, bboxRect.width, bboxRect.height);
68-
65+
6966
if (!maskBounds) {
7067
return null;
7168
}

invokeai/frontend/web/src/features/controlLayers/hooks/useCanvasAdjustBboxHotkey.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@ import { useCanvasIsBusy } from 'features/controlLayers/hooks/useCanvasIsBusy';
44
import { bboxChangedFromCanvas } from 'features/controlLayers/store/canvasSlice';
55
import { selectMaskBlur } from 'features/controlLayers/store/paramsSlice';
66
import { selectCanvasSlice } from 'features/controlLayers/store/selectors';
7-
import type {
7+
import type {
8+
Rect,
89
CanvasBrushLineState,
910
CanvasBrushLineWithPressureState,
1011
CanvasEraserLineState,
1112
CanvasEraserLineWithPressureState,
12-
CanvasImageState,
1313
CanvasRectState,
14-
Rect,
14+
CanvasImageState,
1515
} from 'features/controlLayers/store/types';
16+
import { transformMaskObjectsRelativeToBbox, calculateMaskBoundsFromBitmap } from 'features/controlLayers/util/maskObjectTransform';
1617
import { convertTransformedToOriginal } from 'features/controlLayers/util/coordinateTransform';
17-
import {
18-
calculateMaskBoundsFromBitmap,
19-
transformMaskObjectsRelativeToBbox,
20-
} from 'features/controlLayers/util/maskObjectTransform';
2118
import { useRegisteredHotkeys } from 'features/system/components/HotkeysModal/useHotkeyData';
2219
import { useCallback, useMemo } from 'react';
2320

@@ -45,7 +42,7 @@ export const useCanvasAdjustBboxHotkey = () => {
4542
| CanvasRectState
4643
| CanvasImageState
4744
)[] = [];
48-
45+
4946
for (const mask of inpaintMasks) {
5047
if (!mask.isEnabled || !mask.objects || mask.objects.length === 0) {
5148
continue;
@@ -64,7 +61,7 @@ export const useCanvasAdjustBboxHotkey = () => {
6461

6562
// Calculate bounds from the rendered bitmap for accurate results
6663
const maskBounds = calculateMaskBoundsFromBitmap(allObjects, bboxRect.width, bboxRect.height);
67-
64+
6865
if (!maskBounds) {
6966
return null;
7067
}
@@ -107,4 +104,4 @@ export const useCanvasAdjustBboxHotkey = () => {
107104
options: { enabled: isAdjustBboxAllowed && !isBusy, preventDefault: true },
108105
dependencies: [isAdjustBboxAllowed, isBusy, handleAdjustBbox],
109106
});
110-
};
107+
};

invokeai/frontend/web/src/features/controlLayers/hooks/useCanvasInvertMaskHotkey.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useAssertSingleton } from 'common/hooks/useAssertSingleton';
33
import { useCanvasIsBusy } from 'features/controlLayers/hooks/useCanvasIsBusy';
44
import { inpaintMaskInverted } from 'features/controlLayers/store/canvasSlice';
55
import { selectCanvasSlice, selectSelectedEntityIdentifier } from 'features/controlLayers/store/selectors';
6-
import type { CanvasEntityIdentifier } from 'features/controlLayers/store/types';
76
import { useRegisteredHotkeys } from 'features/system/components/HotkeysModal/useHotkeyData';
87
import { useCallback, useMemo } from 'react';
98

@@ -28,11 +27,7 @@ export const useCanvasInvertMaskHotkey = () => {
2827
return;
2928
}
3029

31-
dispatch(
32-
inpaintMaskInverted({
33-
entityIdentifier: selectedEntityIdentifier as CanvasEntityIdentifier<'inpaint_mask'>,
34-
})
35-
);
30+
dispatch(inpaintMaskInverted({ entityIdentifier: selectedEntityIdentifier as any }));
3631
}, [dispatch, selectedEntityIdentifier, canvasSlice]);
3732

3833
const isInvertMaskAllowed = useMemo(() => {
@@ -54,4 +49,4 @@ export const useCanvasInvertMaskHotkey = () => {
5449
options: { enabled: isInvertMaskAllowed && !isBusy, preventDefault: true },
5550
dependencies: [isInvertMaskAllowed, isBusy, handleInvertMask],
5651
});
57-
};
52+
};

invokeai/frontend/web/src/features/controlLayers/util/coordinateTransform.ts

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type {
33
CanvasBrushLineWithPressureState,
44
CanvasEraserLineState,
55
CanvasEraserLineWithPressureState,
6-
CanvasImageState,
76
CanvasRectState,
7+
CanvasImageState,
88
Coordinate,
99
Rect,
1010
} from 'features/controlLayers/store/types';
@@ -75,13 +75,7 @@ export interface TransformedImage {
7575
* @returns A new mask object with transformed coordinates
7676
*/
7777
export function transformMaskObject(
78-
obj:
79-
| CanvasBrushLineState
80-
| CanvasBrushLineWithPressureState
81-
| CanvasEraserLineState
82-
| CanvasEraserLineWithPressureState
83-
| CanvasRectState
84-
| CanvasImageState,
78+
obj: CanvasBrushLineState | CanvasBrushLineWithPressureState | CanvasEraserLineState | CanvasEraserLineWithPressureState | CanvasRectState | CanvasImageState,
8579
offset: Coordinate
8680
): TransformedMaskObject {
8781
switch (obj.type) {
@@ -157,7 +151,10 @@ export function transformRect(rect: Rect, offset: Coordinate): Rect {
157151
* @param container The container rectangle to clip to
158152
* @returns A new mask object clipped to the container boundaries, or null if completely outside
159153
*/
160-
export function clipMaskObjectToContainer(obj: TransformedMaskObject, container: Rect): TransformedMaskObject | null {
154+
export function clipMaskObjectToContainer(
155+
obj: TransformedMaskObject,
156+
container: Rect
157+
): TransformedMaskObject | null {
161158
switch (obj.type) {
162159
case 'brush_line':
163160
case 'brush_line_with_pressure':
@@ -175,32 +172,28 @@ export function clipMaskObjectToContainer(obj: TransformedMaskObject, container:
175172
* Clips a line object to container boundaries.
176173
*/
177174
function clipLineToContainer(
178-
obj:
179-
| TransformedBrushLine
180-
| TransformedBrushLineWithPressure
181-
| TransformedEraserLine
182-
| TransformedEraserLineWithPressure,
175+
obj: TransformedBrushLine | TransformedBrushLineWithPressure | TransformedEraserLine | TransformedEraserLineWithPressure,
183176
container: Rect
184177
): typeof obj | null {
185178
// For lines, we clip the points to the container boundaries
186179
const clippedPoints: number[] = [];
187-
180+
188181
for (let i = 0; i < obj.points.length; i += 2) {
189182
const x = obj.points[i] ?? 0;
190183
const y = obj.points[i + 1] ?? 0;
191-
184+
192185
// Clip coordinates to container boundaries
193186
const clippedX = Math.max(container.x, Math.min(container.x + container.width, x));
194187
const clippedY = Math.max(container.y, Math.min(container.y + container.height, y));
195-
188+
196189
clippedPoints.push(clippedX, clippedY);
197190
}
198-
191+
199192
// If no points remain, return null
200193
if (clippedPoints.length === 0) {
201194
return null;
202195
}
203-
196+
204197
return {
205198
...obj,
206199
points: clippedPoints,
@@ -213,18 +206,18 @@ function clipLineToContainer(
213206
*/
214207
function clipRectToContainer(obj: TransformedRect, container: Rect): TransformedRect | null {
215208
const rect = obj.rect;
216-
209+
217210
// Calculate intersection
218211
const left = Math.max(rect.x, container.x);
219212
const top = Math.max(rect.y, container.y);
220213
const right = Math.min(rect.x + rect.width, container.x + container.width);
221214
const bottom = Math.min(rect.y + rect.height, container.y + container.height);
222-
215+
223216
// If no intersection, return null
224217
if (left >= right || top >= bottom) {
225218
return null;
226219
}
227-
220+
228221
return {
229222
...obj,
230223
rect: {
@@ -239,7 +232,7 @@ function clipRectToContainer(obj: TransformedRect, container: Rect): Transformed
239232
/**
240233
* Clips an image object to container boundaries.
241234
*/
242-
function clipImageToContainer(obj: TransformedImage, _container: Rect): TransformedImage | null {
235+
function clipImageToContainer(obj: TransformedImage, container: Rect): TransformedImage | null {
243236
// For images, we don't clip them - they remain as-is
244237
return obj;
245238
}
@@ -267,21 +260,17 @@ export function calculateMaskObjectBounds(obj: TransformedMaskObject): Rect | nu
267260
* Calculates bounds for a line object.
268261
*/
269262
function calculateLineBounds(
270-
obj:
271-
| TransformedBrushLine
272-
| TransformedBrushLineWithPressure
273-
| TransformedEraserLine
274-
| TransformedEraserLineWithPressure
263+
obj: TransformedBrushLine | TransformedBrushLineWithPressure | TransformedEraserLine | TransformedEraserLineWithPressure
275264
): Rect | null {
276265
if (obj.points.length < 2) {
277266
return null;
278267
}
279-
268+
280269
let minX = obj.points[0] ?? 0;
281270
let minY = obj.points[1] ?? 0;
282271
let maxX = minX;
283272
let maxY = minY;
284-
273+
285274
for (let i = 2; i < obj.points.length; i += 2) {
286275
const x = obj.points[i] ?? 0;
287276
const y = obj.points[i + 1] ?? 0;
@@ -290,7 +279,7 @@ function calculateLineBounds(
290279
maxX = Math.max(maxX, x);
291280
maxY = Math.max(maxY, y);
292281
}
293-
282+
294283
// Add stroke width to bounds
295284
const strokeRadius = obj.strokeWidth / 2;
296285
return {
@@ -321,13 +310,7 @@ function calculateImageBounds(obj: TransformedImage): Rect | null {
321310
*/
322311
export function convertTransformedToOriginal(
323312
obj: TransformedMaskObject
324-
):
325-
| CanvasBrushLineState
326-
| CanvasBrushLineWithPressureState
327-
| CanvasEraserLineState
328-
| CanvasEraserLineWithPressureState
329-
| CanvasRectState
330-
| CanvasImageState {
313+
): CanvasBrushLineState | CanvasBrushLineWithPressureState | CanvasEraserLineState | CanvasEraserLineWithPressureState | CanvasRectState | CanvasImageState {
331314
switch (obj.type) {
332315
case 'brush_line':
333316
return {
@@ -354,4 +337,4 @@ export function convertTransformedToOriginal(
354337
case 'image':
355338
return obj;
356339
}
357-
}
340+
}

invokeai/frontend/web/src/features/controlLayers/util/maskObjectTransform.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ import type {
33
CanvasBrushLineWithPressureState,
44
CanvasEraserLineState,
55
CanvasEraserLineWithPressureState,
6-
CanvasImageState,
76
CanvasRectState,
7+
CanvasImageState,
88
Coordinate,
99
Rect,
1010
} from 'features/controlLayers/store/types';
11-
12-
import { maskObjectsToBitmap } from './bitmapToMaskObjects';
1311
import {
14-
calculateMaskObjectBounds,
12+
transformMaskObject,
1513
clipMaskObjectToContainer,
14+
calculateMaskObjectBounds,
1615
convertTransformedToOriginal,
1716
type TransformedMaskObject,
18-
transformMaskObject,
1917
} from './coordinateTransform';
18+
import { maskObjectsToBitmap } from './bitmapToMaskObjects';
2019

2120
/**
2221
* Transforms mask objects relative to a bounding box container.
@@ -58,7 +57,10 @@ export function transformMaskObjectsRelativeToBbox(
5857
* @param container The container rectangle to clip to
5958
* @returns Array of clipped mask objects (null values are filtered out)
6059
*/
61-
export function clipMaskObjectsToContainer(objects: TransformedMaskObject[], container: Rect): TransformedMaskObject[] {
60+
export function clipMaskObjectsToContainer(
61+
objects: TransformedMaskObject[],
62+
container: Rect
63+
): TransformedMaskObject[] {
6264
return objects
6365
.map((obj) => clipMaskObjectToContainer(obj, container))
6466
.filter((obj): obj is TransformedMaskObject => obj !== null);
@@ -120,7 +122,7 @@ export function calculateMaskBoundsFromBitmap(
120122

121123
// Convert transformed objects back to original types for compatibility
122124
const originalObjects = objects.map(convertTransformedToOriginal);
123-
125+
124126
// Render the consolidated mask to a bitmap
125127
const bitmap = maskObjectsToBitmap(originalObjects, canvasWidth, canvasHeight);
126128
const { width, height, data } = bitmap;
@@ -165,7 +167,10 @@ export function calculateMaskBoundsFromBitmap(
165167
* @param container The container rectangle to invert within
166168
* @returns Array of mask objects representing the inverted mask
167169
*/
168-
export function invertMask(objects: TransformedMaskObject[], container: Rect): TransformedMaskObject[] {
170+
export function invertMask(
171+
objects: TransformedMaskObject[],
172+
container: Rect
173+
): TransformedMaskObject[] {
169174
// Create a rectangle that covers the entire container
170175
const fullCoverageRect: TransformedMaskObject = {
171176
id: 'inverted_mask_rect',
@@ -181,24 +186,19 @@ export function invertMask(objects: TransformedMaskObject[], container: Rect): T
181186

182187
// For each original mask object, create an eraser line that removes it
183188
const eraserObjects: TransformedMaskObject[] = [];
184-
189+
185190
for (const obj of objects) {
186191
if (obj.type === 'rect') {
187192
// For rectangles, create an eraser rectangle
188193
const eraserRect: TransformedMaskObject = {
189194
id: `eraser_${obj.id}`,
190195
type: 'eraser_line',
191196
points: [
192-
obj.rect.x,
193-
obj.rect.y,
194-
obj.rect.x + obj.rect.width,
195-
obj.rect.y,
196-
obj.rect.x + obj.rect.width,
197-
obj.rect.y + obj.rect.height,
198-
obj.rect.x,
199-
obj.rect.y + obj.rect.height,
200-
obj.rect.x,
201-
obj.rect.y, // Close the rectangle
197+
obj.rect.x, obj.rect.y,
198+
obj.rect.x + obj.rect.width, obj.rect.y,
199+
obj.rect.x + obj.rect.width, obj.rect.y + obj.rect.height,
200+
obj.rect.x, obj.rect.y + obj.rect.height,
201+
obj.rect.x, obj.rect.y, // Close the rectangle
202202
],
203203
strokeWidth: 1,
204204
clip: container,
@@ -233,6 +233,9 @@ export function invertMask(objects: TransformedMaskObject[], container: Rect): T
233233
* @param bboxRect The bounding box to clip to
234234
* @returns Array of clipped mask objects
235235
*/
236-
export function ensureMaskObjectsWithinBbox(objects: TransformedMaskObject[], bboxRect: Rect): TransformedMaskObject[] {
236+
export function ensureMaskObjectsWithinBbox(
237+
objects: TransformedMaskObject[],
238+
bboxRect: Rect
239+
): TransformedMaskObject[] {
237240
return clipMaskObjectsToContainer(objects, bboxRect);
238-
}
241+
}

0 commit comments

Comments
 (0)