public boolean contains ( float x , float y ) { checkPoints ( ) ; if ( points . length == 0 ) { return false ; } boolean result = false ; float xnew , ynew ; float xold , yold ; float x1 , y1 ; float x2 , y2 ; int npoints = points . length ; xold = points [ npoints - 2 ] ; yold = points [ npoints - 1 ] ; for ( int i = 0 ; i < npoints ; i += 2 ) { xnew = points [ i ] ; ynew = points [ i + 1 ] ; if ( xnew > xold ) { x1 = xold ; x2 = xnew ; y1 = yold ; y2 = ynew ; } else { x1 = xnew ; x2 = xold ; y1 = ynew ; y2 = yold ; } if ( ( xnew < x ) == ( x <= xold ) /* edge "open" at one end */ && ( ( double ) y - ( double ) y1 ) * ( x2 - x1 ) < ( ( double ) y2 - ( double ) y1 ) * ( x - x1 ) ) { result = ! result ; } xold = xnew ; yold = ynew ; } return result ; }
Check if this polygon contains the given point