From c0005eb0637315b65c413595013105f60607f8f1 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Thu, 17 Nov 2022 20:26:54 +1100 Subject: [PATCH] Fixes bounding box not being rounded to 64 --- frontend/src/features/canvas/store/canvasSlice.ts | 3 ++- .../src/features/canvas/util/roundDimensionsTo64.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 frontend/src/features/canvas/util/roundDimensionsTo64.ts diff --git a/frontend/src/features/canvas/store/canvasSlice.ts b/frontend/src/features/canvas/store/canvasSlice.ts index ccaf9df5ee..7a9d913444 100644 --- a/frontend/src/features/canvas/store/canvasSlice.ts +++ b/frontend/src/features/canvas/store/canvasSlice.ts @@ -23,6 +23,7 @@ import { isCanvasBaseImage, isCanvasMaskLine, } from './canvasTypes'; +import roundDimensionsTo64 from '../util/roundDimensionsTo64'; export const initialLayerState: CanvasLayerState = { objects: [], @@ -180,7 +181,7 @@ export const canvasSlice = createSlice({ }; }, setBoundingBoxDimensions: (state, action: PayloadAction) => { - state.boundingBoxDimensions = action.payload; + state.boundingBoxDimensions = roundDimensionsTo64(action.payload); }, setBoundingBoxCoordinates: (state, action: PayloadAction) => { state.boundingBoxCoordinates = floorCoordinates(action.payload); diff --git a/frontend/src/features/canvas/util/roundDimensionsTo64.ts b/frontend/src/features/canvas/util/roundDimensionsTo64.ts new file mode 100644 index 0000000000..992d343fc9 --- /dev/null +++ b/frontend/src/features/canvas/util/roundDimensionsTo64.ts @@ -0,0 +1,11 @@ +import { roundToMultiple } from 'common/util/roundDownToMultiple'; +import { Dimensions } from '../store/canvasTypes'; + +const roundDimensionsTo64 = (dimensions: Dimensions): Dimensions => { + return { + width: roundToMultiple(dimensions.width, 64), + height: roundToMultiple(dimensions.height, 64), + }; +}; + +export default roundDimensionsTo64;