code: private static int winding(final Point2d[] coords, final int[] winding) {
          int cw = 0, ccw = 0;
  
          Point2d prev = coords[coords.length - 1];
          for (int i = 0; i < coords.length; i++) {
              Point2d curr = coords[i];
              Point2d next = coords[(i + 1) % coords.length];
              winding[i] = winding(prev, curr, next);
  
              if (winding[i] < 0)
                  cw++;
              else if (winding[i] > 0)
                  ccw++;
              else
                  return 0;
  
              prev = curr;
          }
  
          if (cw == ccw)
              return 0;
  
          return cw > ccw ? CW : CCW;
      }
docs: Determine the overall winding and the vertex of a ring template.
  
  @param coords ring coordinates
  @param winding winding result for each atom (cw/ccw)
  @return global winding