question: public static int rectCrossingsForPath ( PathIterator pi , double rxmin , double rymin , double rxmax , double rymax ) { if ( rxmax <= rxmin || rymax <= rymin ) { return 0 ; } if ( pi . isDone ( ) ) { return 0 ; } double coords [ ] = new double [ 6 ] ; if ( pi . currentSegment ( coords ) != PathIterator . SEG_MOVETO ) { throw new IllegalPathStateException ( "missing initial moveto " + "in path definition" ) ; } pi . next ( ) ; double curx , cury , movx , movy , endx , endy ; curx = movx = coords [ 0 ] ; cury = movy = coords [ 1 ] ; int crossings = 0 ; while ( crossings != RECT_INTERSECTS && ! pi . isDone ( ) ) { switch ( pi . currentSegment ( coords ) ) { case PathIterator . SEG_MOVETO : if ( curx != movx || cury != movy ) { crossings = rectCrossingsForLine ( crossings , rxmin , rymin , rxmax , rymax , curx , cury , movx , movy ) ; } movx = curx = coords [ 0 ] ; movy = cury = coords [ 1 ] ; break ; case PathIterator . SEG_LINETO : endx = coords [ 0 ] ; endy = coords [ 1 ] ; crossings = rectCrossingsForLine ( crossings , rxmin , rymin , rxmax , rymax , curx , cury , endx , endy ) ; curx = endx ; cury = endy ; break ; case PathIterator . SEG_QUADTO : endx = coords [ 2 ] ; endy = coords [ 3 ] ; crossings = rectCrossingsForQuad ( crossings , rxmin , rymin , rxmax , rymax , curx , cury , coords [ 0 ] , coords [ 1 ] , endx , endy , 0 ) ; curx = endx ; cury = endy ; break ; case PathIterator . SEG_CUBICTO : endx = coords [ 4 ] ; endy = coords [ 5 ] ; crossings = rectCrossingsForCubic ( crossings , rxmin , rymin , rxmax , rymax , curx , cury , coords [ 0 ] , coords [ 1 ] , coords [ 2 ] , coords [ 3 ] , endx , endy , 0 ) ; curx = endx ; cury = endy ; break ; case PathIterator . SEG_CLOSE : if ( curx != movx || cury != movy ) { crossings = rectCrossingsForLine ( crossings , rxmin , rymin , rxmax , rymax , curx , cury , movx , movy ) ; } curx = movx ; cury = movy ; break ; } pi . next ( ) ; } if ( crossings != RECT_INTERSECTS && ( curx != movx || cury != movy ) ) { crossings = rectCrossingsForLine ( crossings , rxmin , rymin , rxmax , rymax , curx , cury , movx , movy ) ; } return crossings ; }
target:  Accumulate the number of times the path crosses the shadow extending to the right of the rectangle.  See the comment for the RECT_INTERSECTS constant for more complete details. The return value is the sum of all crossings for both the top and bottom of the shadow for every segment in the path, or the special value RECT_INTERSECTS if the path ever enters the interior of the rectangle. The path must start with a SEG_MOVETO, otherwise an exception is thrown. The caller must check r[xy]{min,max} for NaN values.