daybrush / moveable

Moveable! Draggable! Resizable! Scalable! Rotatable! Warpable! Pinchable! Groupable! Snappable!
https://daybrush.com/moveable/
MIT License
10.08k stars 618 forks source link

1px error with keepRatio #634

Closed GrigoreAlexandru closed 2 years ago

GrigoreAlexandru commented 2 years ago

In the storybook, we resize the target to a arbitrary size: image lock the aspect ratio, change the width and calculate the next height: image With the new 232px width, we should have a height of 182px image But what happens is we get a height of 183px. I believe this is because of some rounding somewhere. But 182.xxx px is still 182px on the screen, so there should be no rounding when dealing with width/height and instead discard the decimals with Math.trunc().

daybrush commented 2 years ago

@GrigoreAlexandru

I'm sorry. However, the browser recognizes it as rounding.

I'm thinking about not using rounding right now.

daybrush commented 2 years ago

@GrigoreAlexandru

moveable's new version is released.

use resizeFormat instead of throttleResize.

throttleResize={0}
resizeFormat={size => ([Math.trunc(size[0]), Math.trunc(size[1])])}