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

How to know the m or M point of path from all of points? #1135

Open
penggelies07 opened this issue Dec 16, 2021 · 3 comments
Open

How to know the m or M point of path from all of points? #1135

penggelies07 opened this issue Dec 16, 2021 · 3 comments

Comments

@penggelies07
Copy link

penggelies07 commented Dec 16, 2021

Hello, I have an svg picture like this, with M and m in the path. I can get all the points by calling Raphael.getTotalLength(path), but how can I know from which point is the path behind m.
I want to know all the absolute coordinate points of the inner border of the svg, so that I can get a data format similar to the following [[points of the outer border], [points of the inner border]].

Untitled-2.svg.zip

This is how I achieved it. I can get all the points, but I can’t distinguish which are the points of the inner frame and which are the points of the outer frame.

let points = [];
for (let i = 0; i < Raphael.getTotalLength(path); i += step_point) {
    const point = Raphael.getPointAtLength(path, i);
    points.push(point);
}

I really look forward to your answers, thank you!

@ibrierley
Copy link

If this is a one off, can't you take before the "m" (eg using some regex), and do Raphael.getTotalLength(firstPart) looping until the end of that ?

@penggelies07
Copy link
Author

penggelies07 commented Dec 17, 2021

If this is a one off, can't you take before the "m" (eg using some regex), and do Raphael.getTotalLength(firstPart) looping until the end of that ?

Thank you very much for your idea, but if there are multiple m after M, then even if the regular expression can get each segment, then the points of the M segment is correct, and the following m is relative coordinates, so the point cannot be obtained correctly positions.

@ibrierley
Copy link

I think in the case if there are multiple "m"s then you need to describe logically where you would make the cutoff. Typically if you can describe something clearly, you can program it.

For example, you may be able to use something like getSubpath(from,to) by traversing the path from the start to an "m" grab it's length, move between the m's and repeat. I am assuming getSubpath returns and absolute rather than a relative path here.

There is also Raphael.parsePathString(pathstring), but that could help.

It may also be useful to describe the overall aim with the points, as there may be a slightly different solution that gives someone some ideas.

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