{"action":"created","issue":{"url":"https://api.github.com/repos/paperjs/paper.js/issues/854","labels_url":"https://api.github.com/repos/paperjs/paper.js/issues/854/labels{/name}","comments_url":"https://api.github.com/repos/paperjs/paper.js/issues/854/comments","events_url":"https://api.github.com/repos/paperjs/paper.js/issues/854/events","html_url":"https://github.com/paperjs/paper.js/issues/854","id":122268005,"number":854,"title":"unite() on self intersecting path creates wrong result","user":{"login":"iconexperience","id":2122773,"avatar_url":"https://avatars.githubusercontent.com/u/2122773?v=3","gravatar_id":"","url":"https://api.github.com/users/iconexperience","html_url":"https://github.com/iconexperience","followers_url":"https://api.github.com/users/iconexperience/followers","following_url":"https://api.github.com/users/iconexperience/following{/other_user}","gists_url":"https://api.github.com/users/iconexperience/gists{/gist_id}","starred_url":"https://api.github.com/users/iconexperience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iconexperience/subscriptions","organizations_url":"https://api.github.com/users/iconexperience/orgs","repos_url":"https://api.github.com/users/iconexperience/repos","events_url":"https://api.github.com/users/iconexperience/events{/privacy}","received_events_url":"https://api.github.com/users/iconexperience/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-12-15T13:05:05Z","updated_at":"2015-12-17T08:41:00Z","closed_at":null,"body":"I found an example where `unite()` on a self intersecting path creates a wrong result.\r\n\r\n<a href=\"http://sketch.paperjs.org/#S/bVLBbtswDP0VwZemgCJQpCiRGXrqDwzYMc3BTbU2qGsHtrsdiv776LgZdhgkSKD4+Pgo8qPp27fa7Jofr3U+vjS+OQ5Pi/2rHd3Z3bm+/nbf2/ll8zHV57faz9Nu/9A7t48RvMtw8O5iqgZQSkoKlIWAvOMUImCBgokZC1HyDtYdMIIKJBAASpCyd1sIJMKlcEGVhERy8Ffqku3NqLAgFTRqDMqqEtWIi8oaj8QUS85kKxrRkogKIQMnBbY0pN4Er4ojFItIWggURJVNcpEgSTWbukQZc74q3qrVktHQuAjMauRbDpwSRiSIpCTI18+IAAFYKUqOjILxopiQpGgyHkWOl3iQEiFJNomarC4NZE6JVq5mjYukJf8Xr13Hbpjq024e3+vn7beH/hzmse2nrp3rxrJ6Z8f6Ph3brm7sy9NiL+0crZ3n8N6fDLtifp667n7ohsVzMz4/thtk/qdJtzcGG/8DM/df5BfMRudxrO3reTjZkDS7/eHzDw==\">Here is the Sketch</a>\r\n\r\nThis is how it looks (magnified):\r\n![image](https://cloud.githubusercontent.com/assets/2122773/11811227/9f526544-a334-11e5-8aff-a24ff2c33da1.png)\r\n\r\n\r\nIn the example the result in a Path, while one would expect a CompoundPath with two children. An interesting observation is that the original path is split at the intersection marked in the image below:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/2122773/11811187/56eb1512-a334-11e5-87d7-30e3f06ac41a.png)\r\n\r\nI will investigate further.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/paperjs/paper.js/issues/comments/165384501","html_url":"https://github.com/paperjs/paper.js/issues/854#issuecomment-165384501","issue_url":"https://api.github.com/repos/paperjs/paper.js/issues/854","id":165384501,"user":{"login":"iconexperience","id":2122773,"avatar_url":"https://avatars.githubusercontent.com/u/2122773?v=3","gravatar_id":"","url":"https://api.github.com/users/iconexperience","html_url":"https://github.com/iconexperience","followers_url":"https://api.github.com/users/iconexperience/followers","following_url":"https://api.github.com/users/iconexperience/following{/other_user}","gists_url":"https://api.github.com/users/iconexperience/gists{/gist_id}","starred_url":"https://api.github.com/users/iconexperience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iconexperience/subscriptions","organizations_url":"https://api.github.com/users/iconexperience/orgs","repos_url":"https://api.github.com/users/iconexperience/repos","events_url":"https://api.github.com/users/iconexperience/events{/privacy}","received_events_url":"https://api.github.com/users/iconexperience/received_events","type":"User","site_admin":false},"created_at":"2015-12-17T08:41:00Z","updated_at":"2015-12-17T08:41:00Z","body":"I have found the cause of this bug.\r\n\r\nWhen calling `unite()` on a path without arguments, the path is first \"prepared\", which calls `resolveCrossings()`and `reorient()`on the path.\r\n\r\n`resolveCrossings()` (which finds the self intersections, divides at the intersections, and traces the paths) works correctly. This creates a `CompoundPath` with two children like this (green: first child, red, second child):\r\n\r\n![image](https://cloud.githubusercontent.com/assets/2122773/11850531/2ccf81a0-a42e-11e5-99c7-2e22d13840fa.png)\r\n\r\nBoth children have clockwise orientation, which is correct in this case.\r\n\r\nBut then `reorient()`decides that the orientation of the second child should be counter clockwise, and this is wrong. So we should take another look on how children of compound paths are oriented, because this still causes problems.\r\n\r\n"}}