private double distanceSq ( Point2D pt , int indexX , int indexY ) { if ( ( indexX < 0 ) || ( indexX >= countX ) || ( indexY < 0 ) || ( indexY >= countY ) ) // outside bounding box return MAX_DOUBLE ; GridCell gtest = gridArray [ indexY ] [ indexX ] ; if ( ! gtest . used ) // nothing in this cell return MAX_DOUBLE ; // get distance from center of cell Rectangle2D rect = gtest . objectBB ; double dx = rect . getX ( ) + rect . getWidth ( ) / 2 - pt . getX ( ) ; double dy = rect . getY ( ) + rect . getHeight ( ) / 2 - pt . getY ( ) ; return ( dx * dx + dy * dy ) ; }
if out of bbox or cell not marked return MAX_DOUBLE