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

IsoLines does not trace lines, if multiple isolines are not closed. #29

Open
kerkovits opened this issue Jan 26, 2023 · 1 comment
Open

Comments

@kerkovits
Copy link

Minimal non-working example:

MarchingSquaresJS.isoLines([[1,1,1,1],[0,0,0,0],[1,1,1,1]],0.5,{linearRing:false});

This should return two open isolines. Instead, the first isoline is connected, the second one is left in small segments without connecting them.

@MattiasJa
Copy link

I run into the same issue with isoLines in many small segments. This does not work well, or look well, when drawing paths in dashArray style...
I did some experimenting with below function to combine arrays that seems to be connected. Works well in my case as a workaround :

function mergeConnectedPaths(pointArrays) {
    // Helper function to check if two arrays are connected
    function areConnected(array1, array2) {
        const end1 = array1[array1.length - 1];
        const start2 = array2[0];
        return end1[0] === start2[0] && end1[1] === start2[1];
    }
    const mergedPaths: number[][] = [];
    pointArrays.forEach((points) => {
        let merged = false;
        for (let i = 0; i < mergedPaths.length; i++) {
            const path = mergedPaths[i];

            if (areConnected(path, points)) {
                // Merge current points at the end of the existing path
                mergedPaths[i] = path.concat(points.slice(1));
                merged = true;
                break;
            } else if (areConnected(points, path)) {
                // Merge existing path at the end of the current points
                mergedPaths[i] = points.concat(path.slice(1));
                merged = true;
                break;
            }
        }
        if (!merged) {
            mergedPaths.push(points);
        }
    });
    return mergedPaths;
}

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