private boolean isClear ( float x1 , float y1 , float x2 , float y2 , float step ) { float dx = ( x2 - x1 ) ; float dy = ( y2 - y1 ) ; float len = ( float ) Math . sqrt ( ( dx * dx ) + ( dy * dy ) ) ; dx *= step ; dx /= len ; dy *= step ; dy /= len ; int steps = ( int ) ( len / step ) ; for ( int i = 0 ; i < steps ; i ++ ) { float x = x1 + ( dx * i ) ; float y = y1 + ( dy * i ) ; if ( findSpace ( x , y ) == null ) { return false ; } } return true ; }
Check if a particular path is clear