2d-polygon-boolean icon indicating copy to clipboard operation
2d-polygon-boolean copied to clipboard

Strange behavior

Open romka-chev opened this issue 9 years ago • 0 comments

Hello!

I ran into a rather strange behavior of the library. I think that all of the examples will be clear.

In both examples, the left side on the map can be set for the geometry subjectPolygon and clipPolygon (they can push and edit). On the map to the right shows the output for this example. The resulting polygons can pull apart to see in detail what happened.

Yellow polygon is a "clipPolygon" Blue polygons is a "subjectPolygons"

Actually, the strange behavior is the first example - there is no right "and" polygon.

A second example, despite the fact that the geometry is really mad, everything works as it should.

What is the problem? Maybe I'm somewhere makes a mistake?

First (wierd) example - http://jsfiddle.net/romkachev/jjaaxnng/ Second (normal) example - http://jsfiddle.net/romkachev/c2o8816a/

P.S. Here is the listing of code on nodejs which process requests:

var express = require('express');
var polygonBoolean = require('2d-polygon-boolean');
var _ = require('lodash');
var router = express.Router();

router.get('/polygons-boolean', function (req, res) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");

    var subjectPolygons = req.query['subjectPolygons'];
    var clipPolygon = req.query['clipPolygon'];
    var mode = req.query['mode'];

    var result = [];

    _.each(subjectPolygons, function (subjectPolygon) {
        var innerResult = [];
        // in case of polygons don't even intersects
        try {
            innerResult = polygonBoolean(subjectPolygon, clipPolygon, mode);
        } catch (e) {
        }

        if (innerResult.length) {
            _.each(innerResult, function (polygon) {
                result.push(polygon);
            })
        }
    });

    res.type('application/json');
    res.send(result);
});

module.exports = router;

PPS - sorry for my engrish.

romka-chev avatar Dec 02 '15 17:12 romka-chev