void update ( boolean [ ] visit , int [ ] vs , int n ) { int len = atoms . length ; double subtract = 0 ; for ( int i = 0 ; i < n ; i ++ ) { final int v = vs [ i ] ; final Point2d p1 = atoms [ v ] . getPoint2d ( ) ; for ( int w = 0 ; w < len ; w ++ ) { if ( visit [ w ] || contribution [ v ] [ w ] < 0 ) continue ; subtract += contribution [ v ] [ w ] ; final Point2d p2 = atoms [ w ] . getPoint2d ( ) ; final double x = p1 . x - p2 . x ; final double y = p1 . y - p2 . y ; final double len2 = x * x + y * y ; score += contribution [ w ] [ v ] = contribution [ v ] [ w ] = 1 / Math . max ( len2 , MIN_SCORE ) ; } } score -= subtract ; }
Update the score considering that some atoms have moved . We only need to update the score of atom that have moved vs those that haven t since all those that moved did so together .