Leaflet.DistortableImage
Leaflet.DistortableImage copied to clipboard
In scale mode, overlapping handles cause crash
Describe the bug:
When scaling an image in "scale" mode, if you try to make image really small, at some point the scaling handles can overlap. I expect this to not cause any issue. But in fact it causes an error :
When this happens, handles are then detached, and image isn't scaled anymore :
This happens when the _scaleBy
function receive a value of 0
as scale. I tried a rough fix of changing the value to 1 when scale = 0, and it appears to fix this bug :
overlay.editing._scaleBy(scale !== Infinity && scale !== NaN && scale !== 0 ? scale : 1);
A better fix might be to add this scale check directly in the _scaleBy function in DistortableImage.Edit.js. If you agree with that, I can offer a pull request for fixing this issue.
Reproduce the behavior:
- Load an image
- Go in scale mode
- Drag the handles in order to make symbol exactly overlap
- It crashes
Browser, version, and operating system:
- Firefox 67.0.3, under Arch Linux
Thanks for opening your first issue here! Please follow the issue template to help us help you 👍🎉😄 If you have screenshots to share demonstrating the issue, that's really helpful! 📸 You can make a gif too!
@PanierAvide I was seeing a few issues open for the scale
mode, and I completely missed your offer to open a PR! Please do so if you have a minute so you can credit for the idea
Sorry, I missed your message as I was offline for few days. By checking to commits, it seems that you fixed the issue, so this PR is not necessary anymore ?
@PanierAvide so in the commits you saw we fixed distortions during scaling and I also prevented this error by modifying scaleHandle.js
to use an edgeMinWidth
property to prevent the handles from ever fully overlapping:
https://github.com/publiclab/Leaflet.DistortableImage/blob/2640118d1654a8d05e46de2ad46d0cd5499e9297/src/edit/ScaleHandle.js#L26-L40
I left this open because:
- your idea might fix it without the edgeMinWidth property, so handles can overlap without the possibility of an error, which I think is preferable
- It has been on our todo to implement an overall scale limit to ensure there is no possibility of an error on that end - also maybe that could be a solution to #402 ??
Also noting _scaleBy
is now scaleBy
and called directly on the overlay
Thanks for your feedback and the details about the change. Glad to see this project evolving and improving everyday ! :+1:
Thanks for your feedback and the details about the change. Glad to see this project evolving and improving everyday ! 👍
@rexagod @jywarren <3