public Object findIntersection ( Point2D p ) { int indexX = ( int ) ( ( p . getX ( ) - offsetX ) / gridWidth ) ; int indexY = ( int ) ( ( p . getY ( ) - offsetY ) / gridHeight ) ; // outside box if ( ( indexX < 0 ) || ( indexX >= countX ) || ( indexY < 0 ) || ( indexY >= countY ) ) return null ; // check the surrounding points for ( int y = Math . max ( 0 , indexY - 1 ) ; y <= Math . min ( countY - 1 , indexY + 1 ) ; y ++ ) { for ( int x = Math . max ( 0 , indexX - 1 ) ; x <= Math . min ( countX - 1 , indexX + 1 ) ; x ++ ) { GridCell gtest = gridArray [ y ] [ x ] ; if ( ! gtest . used ) continue ; if ( gtest . objectBB . contains ( p . getX ( ) , p . getY ( ) ) ) return gtest . o ; } } return null ; }
Check if the given point is contained in already drawn object