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

Counter clockwise #3

Open
mezgaAladar opened this issue Nov 28, 2016 · 0 comments
Open

Counter clockwise #3

mezgaAladar opened this issue Nov 28, 2016 · 0 comments

Comments

@mezgaAladar
Copy link

mezgaAladar commented Nov 28, 2016

Hello guys,

I'm using your module and it is a very great tool! But unfortunately it is not works if I want to slice by counter-clockwise polygons. I rewrote the testLineAndRing method within the module, and it works now, but only with counter-clockwise. Can someone recomment an ultimate solution?

I know I can check it with shoelace formula, and use one of the two methods in the particular cases, but I'm looking for a more simple solution.

My script is:
`
var tempSegments = [];
var cutPoints = [];
var actualSegment;
for (var k = 0; k < segments.length; k++) {
var curr = [];
for (var l = 0; l < segments[k].length - 1; l++) {
curr.push(segments[k][l]);
actualSegment = segments[k][l];

        //Collecting the intersection points
        for (var m = 0; m < ring.length - 1; m++) {
            if (equal(segments[k][l], ring[m])) {
                tempSegments.push(curr.slice());
                curr = [segments[k][l]];
                continue;
            }

            var is = linesIntersect(
                segments[k][l],
                segments[k][l + 1],
                ring[m],
                ring[m + 1]
            );

            if (is) {
                cutPoints.push(is);
            }
        }
    }

    while (cutPoints.length > 0) {
        //Which is the closest point?
        var minDist = Number.MAX_VALUE;
        var minDistSpot = -1;
        for (var c=0; c < cutPoints.length; c++) {
            if ( getDistanceByEndpoints(actualSegment[0],actualSegment[1],cutPoints[c][0],cutPoints[c][1]) < minDist ) {
                minDist = getDistanceByEndpoints(actualSegment[0],actualSegment[1],cutPoints[c][0],cutPoints[c][1]);
                minDistSpot = c;
            }
        }
        curr.push(cutPoints[minDistSpot]);
        tempSegments.push(curr.slice());
        curr = [cutPoints[minDistSpot]];
        cutPoints.splice(minDistSpot,1);

    }
    curr.push(segments[k][segments[k].length - 1]);
    tempSegments.push(curr.slice());

}

`

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

1 participant