Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

Shape quadratic bezier hitTest #2448

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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