{"action":"created","issue":{"url":"https://api.github.com/repos/paperjs/paper.js/issues/788","labels_url":"https://api.github.com/repos/paperjs/paper.js/issues/788/labels{/name}","comments_url":"https://api.github.com/repos/paperjs/paper.js/issues/788/comments","events_url":"https://api.github.com/repos/paperjs/paper.js/issues/788/events","html_url":"https://github.com/paperjs/paper.js/issues/788","id":107234869,"number":788,"title":"Consider using a better algorithm for determining a curve's direction","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":[{"url":"https://api.github.com/repos/paperjs/paper.js/labels/boolean","name":"boolean","color":"fef2c0"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":16,"created_at":"2015-09-18T16:30:53Z","updated_at":"2015-09-20T09:59:22Z","closed_at":"2015-09-18T19:42:06Z","body":"The current algorithm for determining a curve's orientation works well for normal curves, but I think the behavious for curves with self intersections is correct. Even a tiny loop caused by a self intersection of a curve can cause the orientation to flip. Here is the result of the current algorithm with two very similar curves (the curve at the right has a self intersection near the top):\r\n\r\n![image](https://cloud.githubusercontent.com/assets/2122773/9964773/7cc9c3f6-5e32-11e5-8305-8cbfb29d18ec.png)\r\n\r\nIn my opinion the algorithm should return clockwise orientation, if they major part of the path has clockwise orientation.\r\n\r\nI have experimented a bit with the `Curve.getEdgeSum()` function and found that if we use half the handle lenghts for calculation, this gives pretty reasonable results.\r\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V1m3NhOlXgPvj6e+XT3yDw/agPU+ptEKoJWh7sVww0ina2Cd6czr7tPTJMJKakSZ021bpAWQpzVbOZmyvNxLLA1croT0nWN8ymS1nkvbtMJAzdE82KjFD77Q5nu3fmPDBqpab69kTCDiLDLiLhCSIdVdkiEp4hcnBRd62OrkRYQ13FdMd/ILKPWk/hjKZOcO1Eu98=\">Here is a sketch</a>\r\n\r\nGreen fill color indicates clockwise, red color indicates counter-clockwise orientation. The upper path uses the current implemenation, the lower one my suggested method. Move the handles to see the difference. My suggested method changes direction only if the loop exceeds a certain size.\r\n"},"comment":{"url":"https://api.github.com/repos/paperjs/paper.js/issues/comments/141768578","html_url":"https://github.com/paperjs/paper.js/issues/788#issuecomment-141768578","issue_url":"https://api.github.com/repos/paperjs/paper.js/issues/788","id":141768578,"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-09-20T09:59:22Z","updated_at":"2015-09-20T09:59:22Z","body":"@lehni Here is an update that uses the handles's signed distances to the line defined by the curve's end points to determine if the edge sum must be positive or negative as a condition for the existance of a self intersection.\r\n\r\n<a href=\"http://sketch.paperjs.org/#S/pVZLc+I4EP4rXT7MmInxYAJJFSw7h8wlVfuYnaTmAhyE3YA3ikxJMgOV4r9vS/ITM5PsLqSIpf7U/fVTfvEEe0Zv4j08oY63XuDFWWLW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h/dpMcHNE5hUmbF2W60Z4NBeJfKmKP/gy4lm0Z5s7WbIVh4K05T27ppvq3XW7+eF0ZHvbIdTe/FK4nsydpR3mTuRSNvefoH\"> Updated Sketch</a>\r\n\r\nThis is pretty good, even if the false positives as mentioned before still exist.\r\n\r\nPerformance could be improved by not calculating the inflection parameters, but simply checking if inflection points exist.\r\n\r\nBTW, I just noticed that `Line.getSide()` returns the opposite sign of `Line.getSignedDistance()`. Is this intentional? Shoud I open an issue for this?"}}