code: static IBond[] cardinalBonds(IAtom focus, IBond[] bonds) {
  
          final Point2d centerXy = focus.getPoint2d();
          final IBond[] cardinal = new IBond[4];
  
          for (final IBond bond : bonds) {
  
              IAtom   other   = bond.getOther(focus);
              Point2d otherXy = other.getPoint2d();
  
              double deltaX = otherXy.x - centerXy.x;
              double deltaY = otherXy.y - centerXy.y;
  
              // normalise vector length so thresholds are independent 
              double mag = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
              deltaX /= mag;
              deltaY /= mag;
  
              double absDeltaX = Math.abs(deltaX);
              double absDeltaY = Math.abs(deltaY);
  
              // assign the bond to the cardinal direction
              if (absDeltaX < CARDINALITY_THRESHOLD
                      && absDeltaY > CARDINALITY_THRESHOLD) {
                  cardinal[deltaY > 0 ? NORTH : SOUTH] = bond;
              }
              else if (absDeltaX > CARDINALITY_THRESHOLD
                      && absDeltaY < CARDINALITY_THRESHOLD) {
                  cardinal[deltaX > 0 ? EAST : WEST] = bond;
              }
              else {
                  return null;
              }
          }
  
          return cardinal;
      }
docs: Arrange the bonds adjacent to an atom (focus) in cardinal direction. The
  cardinal directions are that of a compass. Bonds are checked as to
  whether they are horizontal or vertical within a predefined threshold.
  
  @param focus an atom
  @param bonds bonds adjacent to the atom
  @return array of bonds organised (N,E,S,W), or null if a bond was found
  that exceeded the threshold