public static int intersectQuad ( float x1 , float y1 , float cx , float cy , float x2 , float y2 , float rx1 , float ry1 , float rx2 , float ry2 ) { // LEFT/RIGHT/UP ------------------------------------------------------ if ( ( rx2 < x1 && rx2 < cx && rx2 < x2 ) || ( rx1 > x1 && rx1 > cx && rx1 > x2 ) || ( ry1 > y1 && ry1 > cy && ry1 > y2 ) ) { return 0 ; } // DOWN --------------------------------------------------------------- if ( ry2 < y1 && ry2 < cy && ry2 < y2 && rx1 != x1 && rx1 != x2 ) { if ( x1 < x2 ) { return x1 < rx1 && rx1 < x2 ? 1 : 0 ; } return x2 < rx1 && rx1 < x1 ? - 1 : 0 ; } // INSIDE ------------------------------------------------------------- QuadCurve c = new QuadCurve ( x1 , y1 , cx , cy , x2 , y2 ) ; float px1 = rx1 - x1 ; float py1 = ry1 - y1 ; float px2 = rx2 - x1 ; float py2 = ry2 - y1 ; float [ ] res1 = new float [ 3 ] ; float [ ] res2 = new float [ 3 ] ; int rc1 = c . solvePoint ( res1 , px1 ) ; int rc2 = c . solvePoint ( res2 , px2 ) ; // INSIDE-LEFT/RIGHT if ( rc1 == 0 && rc2 == 0 ) { return 0 ; } // Build bound -------------------------------------------------------- float minX = px1 - DELTA ; float maxX = px2 + DELTA ; float [ ] bound = new float [ 28 ] ; int bc = 0 ; // Add roots bc = c . addBound ( bound , bc , res1 , rc1 , minX , maxX , false , 0 ) ; bc = c . addBound ( bound , bc , res2 , rc2 , minX , maxX , false , 1 ) ; // Add extremal points rc2 = c . solveExtreme ( res2 ) ; bc = c . addBound ( bound , bc , res2 , rc2 , minX , maxX , true , 2 ) ; // Add start and end if ( rx1 < x1 && x1 < rx2 ) { bound [ bc ++ ] = 0f ; bound [ bc ++ ] = 0f ; bound [ bc ++ ] = 0f ; bound [ bc ++ ] = 4 ; } if ( rx1 < x2 && x2 < rx2 ) { bound [ bc ++ ] = 1f ; bound [ bc ++ ] = c . ax ; bound [ bc ++ ] = c . ay ; bound [ bc ++ ] = 5 ; } // End build bound ---------------------------------------------------- int cross = crossBound ( bound , bc , py1 , py2 ) ; if ( cross != UNKNOWN ) { return cross ; } return c . cross ( res1 , rc1 , py1 , py2 ) ; }
Returns how many times rectangle stripe cross quad curve or the are intersect