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

Segment Stringify #2086

Open
NIkola458 opened this issue Sep 25, 2024 · 1 comment
Open

Segment Stringify #2086

NIkola458 opened this issue Sep 25, 2024 · 1 comment

Comments

@NIkola458
Copy link

Description/Steps to reproduce

Stringifying a segment leads to just an array, instead of an object with labeled properties like point, handleIn, and handleOut."

Link to reproduction test-case

https://codepen.io/nikola12334/pen/JjgopMK

Expected result

"segment":{"point":{"x":242,"y":259},"handleIn":{"x":0,"y":0},"handleOut":{"x":0,"y":0}}

Actual result

"['Path',{'applyMatrix':true,'segments':[[[100,50],[0,0],[80,100]],[[300,50],[-80,-100],[0,0]]],'strokeColor':[0,0,0]}]"

Additional information

mac os: 14.6.1 , Node: v16.13.0

@OblivionSY
Copy link

For clarity, I think you're comparing a segment with the whole path. I think your actual result should be showing just a segment. And therfore, from your codepen, this is your actual result

if you do console.log(JSON.stringify(secondSegment)) you get this:

"['Segment',[300,50],[-80,-100],[0,0]]"

and you would expect

"segment":{"point":{"x":300,"y":50},"handleIn":{"x":-80,"y":-100},"handleOut":{"x":0,"y":0}}

though it may be handleOut could be omitted since it is 0,0

The real issue, which you've not mentioned, is when you JSON.Parse(...) you do not get back to the Segment object. The question is why does stringify trash the object structure in this way, and what is the workaround.

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