{"action":"created","issue":{"url":"https://api.github.com/repos/paperjs/paper.js/issues/1085","repository_url":"https://api.github.com/repos/paperjs/paper.js","labels_url":"https://api.github.com/repos/paperjs/paper.js/issues/1085/labels{/name}","comments_url":"https://api.github.com/repos/paperjs/paper.js/issues/1085/comments","events_url":"https://api.github.com/repos/paperjs/paper.js/issues/1085/events","html_url":"https://github.com/paperjs/paper.js/issues/1085","id":160804408,"number":1085,"title":"Inconsistent calculation in Numerical.solveCubic and Numerical.solveQuadratic","user":{"login":"sapics","id":11169954,"avatar_url":"https://avatars.githubusercontent.com/u/11169954?v=3","gravatar_id":"","url":"https://api.github.com/users/sapics","html_url":"https://github.com/sapics","followers_url":"https://api.github.com/users/sapics/followers","following_url":"https://api.github.com/users/sapics/following{/other_user}","gists_url":"https://api.github.com/users/sapics/gists{/gist_id}","starred_url":"https://api.github.com/users/sapics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sapics/subscriptions","organizations_url":"https://api.github.com/users/sapics/orgs","repos_url":"https://api.github.com/users/sapics/repos","events_url":"https://api.github.com/users/sapics/events{/privacy}","received_events_url":"https://api.github.com/users/sapics/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/paperjs/paper.js/labels/cat:%20curve-intersection","name":"cat: curve-intersection","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2016-06-17T03:18:54Z","updated_at":"2016-06-20T16:32:42Z","closed_at":null,"body":"In [this sketch](http://sketch.paperjs.org/#S/hZBNC4JAEIb/yrInC1NX6CJ0ig5BWOFRPYzbUKLuxvhxif57a5J26INhYD6e4X2ZG1dQIQ94VGAjL9zmUp/6vgNiyFYsbCukXELpbA7RdrcPbUbCzOPUFP6zSNQE1brscN1mubQ8ZzlHmy3eksSMuS6TUKP4fmVYMSX5442fKKmVgdEp9dmiYZuoPnq/f40dWzgRNEbGmPFGTz84MXAvpY/y5mkZIRRXnaum5kGc3h8=), you can confirm that solutions of two equivalent equation are not same in Numerical.solveCubic and Numerical.solveQuadratic.\r\nIt is just a special case problem, thus, it would be enough to fix after 0.10 :)\r\n\r\n## Numerical.solveCubic\r\n\r\nThe solution of `a x^3 + b x^2 + c x + d = 0` is calculated in Numerical.solveCubic.\r\nhttps://github.com/paperjs/paper.js/blob/develop/src/util/Numerical.js#L302\r\n\r\nWhen the case1 (`a = 0.5*EPSILON, b = c = d = - EPSILON`) then, (because of `abs(a) < EPSILON`)\r\nit is converted to `b x^2 + c x + d = 0` in https://github.com/paperjs/paper.js/blob/develop/src/util/Numerical.js#L307.\r\n\r\nOn the other hand, the solution with case1 is equivalent to the solution with `a = 0.5, b = c = d = - 1` (case2) where Numerical.solveCubic return right solution.\r\nIn the case2, it is NOT converted to `b x^2 + c x + d = 0`, becase of `abs(a) > EPSILON`.\r\n\r\nThe conversion in case1 causes problem.\r\nI guess that we need to fix the conditions of this conversion in (https://github.com/paperjs/paper.js/blob/develop/src/util/Numerical.js#L307 and https://github.com/paperjs/paper.js/blob/develop/src/util/Numerical.js#L312).\r\n\r\n\r\n## Numerical.solveQuadratic\r\n\r\nSimilar problem is occured in Numerical.solveQuadratic.\r\n`a x^2 + b x + c = 0` with `a = EPSILON, b = 0, c = -EPSILON` which solutions are `-1` and `1`, but Numerical.solveQuadratic return no solutions.\r\nOn the other hand, Numerical.solveQuadratic could return right solutions for equivalent equation `a = 1, b = 0, c = -1`.\r\n\r\n\r\n## One of the solutions (but it might cause some other problem...)\r\n\r\nI create a branch(https://github.com/sapics/paper.js/tree/simpler-calculation) for discussion.\r\nIt is just simplified one by removing most of EPSILON error.\r\nI think that this branch would not have the problem which introduced above.\r\nHowever, I guess that original calculation is better than my branch for consistent calculation for epsilon error and collecting more solutions.\r\nIt would be impossible to avoid some epsilon error which is created in the Kahan's iterative calculation in Numerical.solveCubic.\r\nThus, for collecting the more solutions (but it might also collect more impossible solutions, in some case), original calculation might use calculations which cover some epsilon error, I guess.\r\n"},"comment":{"url":"https://api.github.com/repos/paperjs/paper.js/issues/comments/227195672","html_url":"https://github.com/paperjs/paper.js/issues/1085#issuecomment-227195672","issue_url":"https://api.github.com/repos/paperjs/paper.js/issues/1085","id":227195672,"user":{"login":"lehni","id":213275,"avatar_url":"https://avatars.githubusercontent.com/u/213275?v=3","gravatar_id":"","url":"https://api.github.com/users/lehni","html_url":"https://github.com/lehni","followers_url":"https://api.github.com/users/lehni/followers","following_url":"https://api.github.com/users/lehni/following{/other_user}","gists_url":"https://api.github.com/users/lehni/gists{/gist_id}","starred_url":"https://api.github.com/users/lehni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lehni/subscriptions","organizations_url":"https://api.github.com/users/lehni/orgs","repos_url":"https://api.github.com/users/lehni/repos","events_url":"https://api.github.com/users/lehni/events{/privacy}","received_events_url":"https://api.github.com/users/lehni/received_events","type":"User","site_admin":false},"created_at":"2016-06-20T16:32:42Z","updated_at":"2016-06-20T16:32:42Z","body":"No need for a PR yet. I haven't had the time to look into it all yet, but I can check out your branch locally to test."}}
{"actor":{"display_login":"lehni"}}