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

Is it possible to have the pair of transformed coordinates returned as a dataset #66

Closed
smpa01 opened this issue Feb 27, 2024 · 2 comments

Comments

@smpa01
Copy link

smpa01 commented Feb 27, 2024

Is it possible for svgpath to have the pair of transformed segments returned in an array of objects? For example,

<path d="M650,300L650,150L640,150L640,300" fill="none" stroke="red"></path>

const d = document.querySelector('path').getAttribute('d');     
const path = svgpath(d)
        .matrix([0.707107, 0.707107, -0.707107, 0.707107, 402.513, 371.751])
        .toString();  

console.log(path);

The above would return M650.00045 300.00065000000006L756.0664999999999 193.93460000000005 748.9954299999999 186.86353000000008 642.92938 292.9295800000001.

But I was wondering if there is a method that could return the transformed coordinates in an array of objects like

[{650.00045, 300.00065000000006},{756.0664999999999, 193.93460000000005},{748.9954299999999, 186.86353000000008},{642.92938, 292.9295800000001}]

@puzrin
Copy link
Member

puzrin commented Feb 27, 2024

You can add your custom .toArray() method and process .segments property as you wish.

@puzrin puzrin closed this as completed Feb 27, 2024
@smpa01
Copy link
Author

smpa01 commented Feb 27, 2024

Sorry, I am having trouble implementing what you are suggesting. Can you kindly provide an example please?

The following returns the original coordinates and not the transformed coordinates.

 const path = svgpath(d)
        .matrix([matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]])
        .segments

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