@@ -505,18 +505,23 @@ inline float2 bezier(float2 A, float2 B, float2 C, float t) {
505505 return (1 - t) * (1 - t) * A + 2 * (1 - t) * t * B + t * t * C;
506506}
507507
508- inline bool lineTest (float2 p, float2 A, float2 B) {
509-
510- int cs = (A.y < p.y ) * 2 + (B.y < p.y );
511-
512- if (cs == 0 or cs == 3 ) return false ; // trivial reject
508+ inline bool side (float2 p, float2 A, float2 B) {
513509
514510 auto v = B - A;
515511
516512 // Intersect line with x axis.
517513 float t = (p.y -A.y )/v.y ;
518514
519515 return (A.x + t*v.x ) > p.x ;
516+ }
517+
518+ inline bool lineTest (float2 p, float2 A, float2 B) {
519+
520+ int cs = (A.y < p.y ) * 2 + (B.y < p.y );
521+
522+ if (cs == 0 or cs == 3 ) return false ; // trivial reject
523+
524+ return side (p, A, B);
520525
521526}
522527
@@ -530,8 +535,17 @@ inline bool bezierTest(float2 p, float2 A, float2 B, float2 C) {
530535 float s = (v2.x * v1.y - v1.x * v2.y ) / det;
531536 float t = (v0.x * v2.y - v2.x * v0.y ) / det;
532537
533- if (s < 0 or t < 0 or (1 -s-t) < 0 ) {
534- return false ; // outside triangle
538+ // Concave or convex?
539+ // Try to be consistent with lineTest so we don't
540+ // double-flip the inside/outside in edge cases.
541+ if (side (B, A, C)) {
542+ if (s <= 0 or t < 0 or (1 -s-t) < 0 ) {
543+ return false ; // outside triangle
544+ }
545+ } else {
546+ if (s < 0 or t < 0 or (1 -s-t) < 0 ) {
547+ return false ; // outside triangle
548+ }
535549 }
536550
537551 // Transform to canonical coordinte space.
0 commit comments