Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point groups with only 2 points are not drawn #720

Open
MattL75 opened this issue May 31, 2023 · 4 comments
Open

Point groups with only 2 points are not drawn #720

MattL75 opened this issue May 31, 2023 · 4 comments

Comments

@MattL75
Copy link

MattL75 commented May 31, 2023

If you have a question, please ask it on StackOverflow and use signature-pad tag instead of creating an issue.

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
If a point group only has 2 points, nothing gets drawn.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar (template: https://jsfiddle.net/szimek/h80phxyr/).
https://jsfiddle.net/xvoqnyu9/16/
Not quite sure why clicking the buttons multiple times crashes signature_pad. So just refresh (or save) before clicking each button. You can see the one with 2 points does not render anything while the one with 3 points renders a line.

What is the expected behavior?
Even with 2 points it should render a line.

Which versions of SignaturePad, and which browser / device are affected by this issue? Did this work in previous versions of SignaturePad?
As far as I know it hasn't worked previously. 4.1.5 affected, chrome latest.

EXPLANATION:
signature_pad.ts line 575 allows a point group with 2 points to go through to the _addPoint function (for the curve).

signature_pad.ts line 454 does not allow something with 2 points to go through to the rest of the logic. This is fine if there are more points, but if there are ONLY 2, then nothing happens and the logic ends there. The point group is essentially ignored.

I'm not sure if this is intentional. Maybe the customer we have that provided this point group just needs to provide better point groups.

@UziTech
Copy link
Collaborator

UziTech commented Jun 1, 2023

The signature is created by adding Bezier curves so the drawing follows closer to the place the user actually signed instead of lines connecting points that we happened to detect. The Bezier curves require 4 points to calculate. We fudge the beginning a little by introducing the first point twice so we can calculate the first curve with 3 points. You can read more about it here.

@MattL75
Copy link
Author

MattL75 commented Jun 1, 2023

It absolutely makes sense. However just like there's an exception to the rule for a pointgroup with only 1 point (draws a dot) maybe there could be an exception for 2 points that draws a straight line. What do you think?

@UziTech
Copy link
Collaborator

UziTech commented Jun 1, 2023

If you want to create a PR we could see how it looks. 😁👍

@MattL75
Copy link
Author

MattL75 commented Jun 1, 2023

Perfect I will investigate :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants