Leaflet.DistortableImage icon indicating copy to clipboard operation
Leaflet.DistortableImage copied to clipboard

In scale mode, overlapping handles cause crash

Open PanierAvide opened this issue 5 years ago • 6 comments

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 : scale_value

When this happens, handles are then detached, and image isn't scaled anymore : broken_handles

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

PanierAvide avatar Jun 28 '19 11:06 PanierAvide

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!

welcome[bot] avatar Jun 28 '19 11:06 welcome[bot]

@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

sashadev-sky avatar Aug 12 '19 04:08 sashadev-sky

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 avatar Aug 19 '19 10:08 PanierAvide

@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:

  1. your idea might fix it without the edgeMinWidth property, so handles can overlap without the possibility of an error, which I think is preferable
  2. 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

sashadev-sky avatar Aug 30 '19 04:08 sashadev-sky

Thanks for your feedback and the details about the change. Glad to see this project evolving and improving everyday ! :+1:

PanierAvide avatar Aug 30 '19 12:08 PanierAvide

Thanks for your feedback and the details about the change. Glad to see this project evolving and improving everyday ! 👍

@rexagod @jywarren <3

sashadev-sky avatar Aug 30 '19 23:08 sashadev-sky