fix: fixes bug with rectangle resizing

This commit is contained in:
Mark Mankarious 2023-10-17 13:52:22 +01:00
parent ccbedd7c98
commit 0731757060
2 changed files with 18 additions and 4 deletions

View file

@ -5,9 +5,9 @@ import {
getItemAtTile,
getBoundingBox,
outermostCornerPositions,
getTilePosition,
convertBoundsToNamedAnchors,
hasMovedTile
hasMovedTile,
isoToScreen
} from 'src/utils';
import { TRANSFORM_ANCHOR_SIZE } from 'src/config';
import { ModeActions, AnchorPositionsEnum } from 'src/types';
@ -74,9 +74,10 @@ export const TransformRectangle: ModeActions = {
// Check if the user has mousedown'd on an anchor
const rectangleBounds = getBoundingBox([rectangle.to, rectangle.from]);
const anchorPositions = rectangleBounds.map((corner, i) => {
return getTilePosition({
return isoToScreen({
tile: corner,
origin: outermostCornerPositions[i]
origin: outermostCornerPositions[i],
rendererSize: uiState.rendererSize
});
});
const activeAnchorIndex = anchorPositions.findIndex((anchorPosition) => {

View file

@ -104,6 +104,19 @@ export const getTilePosition = ({
}
};
type IsoToScreen = GetTilePosition & {
rendererSize: Size;
};
export const isoToScreen = ({ tile, origin, rendererSize }: IsoToScreen) => {
const position = getTilePosition({ tile, origin });
return {
x: position.x + rendererSize.width / 2,
y: position.y + rendererSize.height / 2
};
};
export const sortByPosition = (tiles: Coords[]) => {
const xSorted = [...tiles];
const ySorted = [...tiles];