raphael icon indicating copy to clipboard operation
raphael copied to clipboard

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

Open penggelies07 opened this issue 2 years ago • 3 comments

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!

penggelies07 avatar Dec 16 '21 13:12 penggelies07

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 ?

ibrierley avatar Dec 16 '21 13:12 ibrierley

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.

penggelies07 avatar Dec 17 '21 01:12 penggelies07

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.

ibrierley avatar Dec 17 '21 07:12 ibrierley