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

Incorrect Position at SVG Path for lengths < 0.01 #1869

Open
FrontSide opened this issue Jan 3, 2025 · 0 comments
Open

Incorrect Position at SVG Path for lengths < 0.01 #1869

FrontSide opened this issue Jan 3, 2025 · 0 comments

Comments

@FrontSide
Copy link

When retrieving the position at a given length along a path created from SVG data, the wrong position is returned if the given length along the path is smaller than 0.01.

JSFiddle: https://jsbin.com/muciqinade/edit?js,console,output

Example:

let path = new Konva.Path({
  id: "p1",
  x: 0,
  y: 0,
  data: "M 614.96002,7.5147864 611.20262,429.59529",
  stroke: 'red',
  strokeWidth: 2,
})

console.log(path.getPointAtLength(0.008))
console.log(path.getPointAtLength(0.12))

The above is a vertical line starting at position 614.96002,7.5147864 and ending at 611.20262,429.59529.

The console output will read:

[object Object] {
  x: 611.20262,
  y: 429.59529
}
[object Object] {
  x: 614.9589517911361,
  y: 7.634781645446739
}

As you can see, the position returned for length=0.008 is farther ahead on the line than that for length=0.12.
That's clearly a bug.

I believe the bug is here: https://github.com/konvajs/konva/blob/master/src/shapes/Path.ts#L260
where we are returning the two points of the last path segment, which in this case marks the end of the path.
Instead we should be returning the startX and startY coordinates of the segment.

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

1 participant