code: public void refine() {
          for (int i = 1; i <= MAX_ITERATIONS; i++) {
              final List<AtomPair> pairs = findCongestedPairs();
  
              if (pairs.isEmpty())
                  break;
  
              final double min = congestion.score();
  
              // rotation: flipping around sigma bonds
              rotate(pairs);
  
              // rotation improved, so try more rotation, we may have caused
              // new conflicts that can be resolved through more rotations
              if (congestion.score() < min)
                  continue;
  
              // inversion: terminal atoms can be placed inside rings
              // which is preferable to bending or stretching
              invert(pairs);
  
              if (congestion.score() < min)
                  continue;
  
              // bending or stretching: least favourable but sometimes
              // the only way. We try either and use the best
              bendOrStretch(pairs);
  
              if (congestion.score() < min)
                  continue;
  
              break;
          }
      }
docs: Refine the 2D coordinates of a layout to reduce overlap and congestion.