Skip to content

Commit

Permalink
Merge pull request #1 from ivanpopelyshev/fix-quadcurve
Browse files Browse the repository at this point in the history
fix shape quadratic bezier hittest
  • Loading branch information
danimesq authored Mar 13, 2022
2 parents 997b932 + a882acf commit 8283f69
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions src/flash/display/Graphics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ module Shumway.AVMX.AS.flash.display {
return false;
}
if (fromX >= x && cpX >= x && toX >= x) {
return true;
return (toY > y) !== (fromY > y);
}

// Finding the intersections with our ray means solving a quadratic
Expand All @@ -293,17 +293,44 @@ module Shumway.AVMX.AS.flash.display {
}

d = Math.sqrt(d);
a = 1 / (a + a);
var t1 = (d - b) * a;
var t2 = (-b - d) * a;

var t1 = -c / b;
var t2 = 10.0;

if (a !== 0) {
a = 1 / (a + a);
t1 = (d - b) * a;
t2 = (-b - d) * a;
}

var goesDown = cpY > y || cpY === y && toY > y;
var goesUp = cpY > y || cpY === y && fromY > y;

if (d === 0) {
if (t1 === 0) {
return goesDown && fromX > x;
}
if (t1 === 1) {
return goesUp && toX > x;
}
return false;
}

var crosses = false;
if (t1 >= 0 && t1 <= 1 && quadraticBezier(fromX, cpX, toX, t1) > x) {
crosses = !crosses;
if (t1 >= 0 && t1 <= 1) {
if ((t1 > 0 || goesDown) && (t1 < 1 || goesUp)) {
if (quadraticBezier(fromX, cpX, toX, t1) > x) {
crosses = !crosses;
}
}
}

if (t2 >= 0 && t2 <= 1 && quadraticBezier(fromX, cpX, toX, t2) > x) {
crosses = !crosses;
if (t2 >= 0 && t2 <= 1) {
if ((t2 > 0 || goesDown) && (t2 < 1 || goesUp)) {
if (quadraticBezier(fromX, cpX, toX, t2) > x) {
crosses = !crosses;
}
}
}
return crosses;
}
Expand Down

0 comments on commit 8283f69

Please sign in to comment.