feat(ui): add optimal size handling

This commit is contained in:
psychedelicious
2024-01-03 23:56:28 +11:00
committed by Kent Keirsey
parent 1a4be78013
commit 4fdc4c15f9
30 changed files with 461 additions and 416 deletions

View File

@ -2,19 +2,22 @@ import { roundToMultiple } from 'common/util/roundDownToMultiple';
import type { Dimensions } from 'features/canvas/store/canvasTypes';
import { CANVAS_GRID_SIZE_FINE } from 'features/canvas/store/constants';
const getScaledBoundingBoxDimensions = (dimensions: Dimensions) => {
const getScaledBoundingBoxDimensions = (
dimensions: Dimensions,
optimalDimension: number
) => {
const { width, height } = dimensions;
const scaledDimensions = { width, height };
const targetArea = 512 * 512;
const targetArea = optimalDimension * optimalDimension;
const aspectRatio = width / height;
let currentArea = width * height;
let maxDimension = 448;
let maxDimension = optimalDimension - CANVAS_GRID_SIZE_FINE;
while (currentArea < targetArea) {
maxDimension += CANVAS_GRID_SIZE_FINE;
if (width === height) {
scaledDimensions.width = 512;
scaledDimensions.height = 512;
scaledDimensions.width = optimalDimension;
scaledDimensions.height = optimalDimension;
break;
} else {
if (aspectRatio > 1) {