{"action":"created","issue":{"url":"https://api.github.com/repos/tmpvar/polygon.js/issues/8","labels_url":"https://api.github.com/repos/tmpvar/polygon.js/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/tmpvar/polygon.js/issues/8/comments","events_url":"https://api.github.com/repos/tmpvar/polygon.js/issues/8/events","html_url":"https://github.com/tmpvar/polygon.js/issues/8","id":89284508,"number":8,"title":"Union of two polygon bug","user":{"login":"YannPl","id":3104374,"avatar_url":"https://avatars.githubusercontent.com/u/3104374?v=3","gravatar_id":"","url":"https://api.github.com/users/YannPl","html_url":"https://github.com/YannPl","followers_url":"https://api.github.com/users/YannPl/followers","following_url":"https://api.github.com/users/YannPl/following{/other_user}","gists_url":"https://api.github.com/users/YannPl/gists{/gist_id}","starred_url":"https://api.github.com/users/YannPl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YannPl/subscriptions","organizations_url":"https://api.github.com/users/YannPl/orgs","repos_url":"https://api.github.com/users/YannPl/repos","events_url":"https://api.github.com/users/YannPl/events{/privacy}","received_events_url":"https://api.github.com/users/YannPl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-06-18T12:46:25Z","updated_at":"2015-10-28T09:08:11Z","closed_at":null,"body":"Hi,\r\nI'm using the **union** method in my application since 2 month now. \r\nI have a function that checks if 2 polygons share an intersection by using the union method and testing the length of the result.\r\nlength = 0 => no intersection.\r\nlength != 0 => there is an intersection.\r\n\r\nEverything worked fine until I updated my dependencies yesterday **(`npm update`)**.\r\nNow, when I run the same function with the same polygons I used before the update, it always returns an union even if the two polygons are clearly separated.\r\n\r\n**For example**, there are the two polygons I want to test the union:\r\n```\r\n[{\r\n        \"x\": 9,\r\n        \"y\": -86.328125\r\n    }, {\r\n        \"x\": 28,\r\n        \"y\": -86.328125\r\n    }, {\r\n        \"x\": 28,\r\n        \"y\": -59.828125\r\n    }, {\r\n        \"x\": 9,\r\n        \"y\": -59.828125\r\n}]\r\n\r\n[{\r\n        \"x\": 33.5,\r\n        \"y\": 188.171875\r\n    }, {\r\n        \"x\": 18,\r\n        \"y\": 191.671875\r\n    }, {\r\n        \"x\": 19.5,\r\n        \"y\": 173.171875\r\n    }, {\r\n        \"x\": 32.5,\r\n        \"y\": 180.671875\r\n}]\r\n```\r\n\r\nAnd there is the result of the union method called on the first polygon:\r\n```\r\n[{\r\n        \"x\": 9,\r\n        \"y\": -86.328125\r\n    }, {\r\n        \"x\": 28,\r\n        \"y\": -86.328125\r\n    }, {\r\n        \"x\": 28,\r\n        \"y\": -59.828125\r\n    }, {\r\n        \"x\": 9,\r\n        \"y\": -59.828125\r\n}]\r\n```\r\nI don't understand why the union method returns the polygon on which it was called in my case.\r\n\r\nSo I'd be grateful if you could help me find where this issue comes from =)"},"comment":{"url":"https://api.github.com/repos/tmpvar/polygon.js/issues/comments/151774004","html_url":"https://github.com/tmpvar/polygon.js/issues/8#issuecomment-151774004","issue_url":"https://api.github.com/repos/tmpvar/polygon.js/issues/8","id":151774004,"user":{"login":"YannPl","id":3104374,"avatar_url":"https://avatars.githubusercontent.com/u/3104374?v=3","gravatar_id":"","url":"https://api.github.com/users/YannPl","html_url":"https://github.com/YannPl","followers_url":"https://api.github.com/users/YannPl/followers","following_url":"https://api.github.com/users/YannPl/following{/other_user}","gists_url":"https://api.github.com/users/YannPl/gists{/gist_id}","starred_url":"https://api.github.com/users/YannPl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YannPl/subscriptions","organizations_url":"https://api.github.com/users/YannPl/orgs","repos_url":"https://api.github.com/users/YannPl/repos","events_url":"https://api.github.com/users/YannPl/events{/privacy}","received_events_url":"https://api.github.com/users/YannPl/received_events","type":"User","site_admin":false},"created_at":"2015-10-28T09:08:11Z","updated_at":"2015-10-28T09:08:11Z","body":"Hi ! \r\nSure, I can explain my workaround, It's a personnal interpretation only suited for my needs so it may not suits yours...\r\n\r\nBasically, I have created a function that tests if a polygon contains another polygon and use it in my intersection method.\r\n\r\nThere is the code woth french comments (sorry for that). \r\nThe `getCoordsArrayFromLatLngArray` method just transforms my coordinates into the format that Polygon needs.\r\nI only translated the importants ones for you:\r\n```javascript\r\n/**\r\n * Test si container contient totalement contained (pas d'intersection de leurs côtés)\r\n * Les deux paramètres sont un tableau de lat lng comme suit:\r\n * [\r\n *  {lat: xx,yyy, lng: xx,yyy},\r\n *  {lat: xx,yyy, lng: xx,yyy},\r\n *  {lat: xx,yyy, lng: xx,yyy},\r\n *  {lat: xx,yyy, lng: xx,yyy},\r\n *  {lat: xx,yyy, lng: xx,yyy}\r\n * ]\r\n * @param container : polygon le plus grand (ex: zone)\r\n * @param contained : polygon le plus petit (ex : allée)\r\n *\r\n * @returns boolean true ou false\r\n */\r\nfunction polygonContainsPolygon(container, contained) {\r\n\r\n    var polyContainer = new Polygon(getCoordsArrayFromLatLngArray(container));\r\n    var polyContained = new Polygon(getCoordsArrayFromLatLngArray(contained));\r\n\r\n    return polyContainer.containsPolygon(polyContained);\r\n}\r\n\r\n/**\r\n * Test l'intersection de deux polygons\r\n * [\r\n *  {lat: xx,yyy, lng: xx,yyy},\r\n *  {lat: xx,yyy, lng: xx,yyy},\r\n *  {lat: xx,yyy, lng: xx,yyy},\r\n *  {lat: xx,yyy, lng: xx,yyy},\r\n *  {lat: xx,yyy, lng: xx,yyy}\r\n * ]\r\n * @param poly1\r\n * @param poly2\r\n * @returns {boolean}\r\n */\r\nfunction polygonIntersection(poly1, poly2) {\r\n    var oPoly1 = new Polygon(getCoordsArrayFromLatLngArray(poly1));\r\n    var oPoly2 = new Polygon(getCoordsArrayFromLatLngArray(poly2));\r\n\r\n    // The polygons aren't fully containing each others, there is a possible intersection\r\n    if (!polygonContainsPolygon(poly1, poly2) || !polygonContainsPolygon(poly2, poly1)) {\r\n        var intersect = oPoly1.union(oPoly2);\r\n        // Test if we have an intersection\r\n        return (!intersect.equal(oPoly1) && !intersect.equal(oPoly2));\r\n    } else {\r\n        return false;\r\n    }\r\n}\r\n```"}}