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

Issue with the trace function #73

Open
hpedro-github opened this issue Sep 2, 2024 · 1 comment
Open

Issue with the trace function #73

hpedro-github opened this issue Sep 2, 2024 · 1 comment

Comments

@hpedro-github
Copy link

hpedro-github commented Sep 2, 2024

Hello,

I was using your leaflet plugin and I found an issue with the trace with the "S" case with a pathData like this:
pathData = ['M', [lat0,lng0], 'S', [lat1,lng0], [lat1,lng0]]

for(var i = 0; i < this._points.length; i++){
	point = this._points[i];
	if(typeof point == 'string' || point instanceof String){
		curCommand = point;

		if(curCommand == 'Z'){
			samples = samples.concat(this._linearTrace(t, curEndPoint, curStartPoint));
		}
	}else{
		switch(curCommand){ 
(....)

case 'S':
	p1 = this._reflectPoint(p2, curEndPoint);
	p2 = point;
	p3 = this._points[++i];
	samples = samples.concat(this._cubicTrace(t, curEndPoint, p1, p2, p3));

p1 cannot be calculated because p2 is not defined yet. So I defined p2=curEndPoint on the case 'M' (the first point). And it work well.

case 'M': curStartPoint = point; curEndPoint = point; **p2=curEndPoint;** break;

Same kind of issue with the case T.

@elfalem
Copy link
Owner

elfalem commented Sep 22, 2024

Thanks @hpedro-github for highlighting this. I think your modification is correct according to the documentation for the S command:

Draws a cubic Bézier curve from the current point to (x,y). The first control point is assumed to be the reflection of the second control point on the previous command relative to the current point. (If there is no previous command or if the previous command was not an C, c, S or s, assume the first control point is coincident with the current point.)

Would you be willing to submit a PR?

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

No branches or pull requests

2 participants