tidy(ui): remove layer scaling reducers

This commit is contained in:
psychedelicious 2024-08-01 13:11:09 +10:00
parent dc9fa1a735
commit e940754795
3 changed files with 1 additions and 45 deletions

View File

@ -32,7 +32,6 @@ import {
layerImageCacheChanged,
layerRectShapeAdded,
layerReset,
layerScaled,
layerTranslated,
rgBboxChanged,
rgBrushLineAdded,
@ -91,9 +90,7 @@ export class CanvasStateApi {
};
onScaleChanged = (arg: ScaleChangedArg, entityType: CanvasEntity['type']) => {
log.debug('onScaleChanged');
if (entityType === 'layer') {
this.store.dispatch(layerScaled(arg));
} else if (entityType === 'inpaint_mask') {
if (entityType === 'inpaint_mask') {
this.store.dispatch(imScaled(arg));
} else if (entityType === 'regional_guidance') {
this.store.dispatch(rgScaled(arg));

View File

@ -66,7 +66,6 @@ const initialState: CanvasV2State = {
eraser: {
width: 50,
},
isTransforming: false,
},
bbox: {
rect: { x: 0, y: 0, width: 512, height: 512 },
@ -221,7 +220,6 @@ export const {
layerImageAdded,
layerAllDeleted,
layerImageCacheChanged,
layerScaled,
layerBrushLineAdded,
layerEraserLineAdded,
layerRectShapeAdded,

View File

@ -16,7 +16,6 @@ import type {
LayerEntity,
PositionChangedArg,
RectShape,
ScaleChangedArg,
} from './types';
import { imageDTOToImageObject, imageDTOToImageWithDims } from './types';
@ -179,35 +178,6 @@ export const layersReducers = {
layer.objects.push(rectShape);
state.layers.imageCache = null;
},
layerScaled: (state, action: PayloadAction<ScaleChangedArg>) => {
const { id, scale, position } = action.payload;
const layer = selectLayer(state, id);
if (!layer) {
return;
}
for (const obj of layer.objects) {
if (obj.type === 'brush_line') {
obj.points = obj.points.map((point) => Math.round(point * scale));
obj.strokeWidth = Math.round(obj.strokeWidth * scale);
} else if (obj.type === 'eraser_line') {
obj.points = obj.points.map((point) => Math.round(point * scale));
obj.strokeWidth = Math.round(obj.strokeWidth * scale);
} else if (obj.type === 'rect_shape') {
obj.x = Math.round(obj.x * scale);
obj.y = Math.round(obj.y * scale);
obj.height = Math.round(obj.height * scale);
obj.width = Math.round(obj.width * scale);
} else if (obj.type === 'image') {
obj.x = Math.round(obj.x * scale);
obj.y = Math.round(obj.y * scale);
obj.height = Math.round(obj.height * scale);
obj.width = Math.round(obj.width * scale);
}
}
layer.position.x = Math.round(position.x);
layer.position.y = Math.round(position.y);
state.layers.imageCache = null;
},
layerImageAdded: (
state,
action: PayloadAction<ImageObjectAddedArg & { objectId: string; pos?: { x: number; y: number } }>
@ -240,12 +210,3 @@ export const layersReducers = {
state.layers.imageCache = null;
},
} satisfies SliceCaseReducers<CanvasV2State>;
const scalePoints = (points: number[], scaleX: number, scaleY: number) => {
const newPoints: number[] = [];
for (let i = 0; i < points.length; i += 2) {
newPoints.push(points[i]! * scaleX);
newPoints.push(points[i + 1]! * scaleY);
}
return newPoints;
};