public static final List<Vector2> cleanse(List<Vector2> points){
  if (points == null)   throw new NullPointerException(Messages.getString("geometry.nullPointList"));
  int size=points.size();
  if (size == 0)   return points;
  List<Vector2> result=new ArrayList<Vector2>(size);
  double winding=0.0;
  for (int i=0; i < size; i++) {
    Vector2 point=points.get(i);
    Vector2 prev=points.get(i - 1 < 0 ? size - 1 : i - 1);
    Vector2 next=points.get(i + 1 == size ? 0 : i + 1);
    if (point == null || prev == null || next == null)     throw new NullPointerException(Messages.getString("geometry.nullPointListElements"));
    Vector2 diff=point.difference(next);
    if (diff.isZero()) {
      continue;
    }
    Vector2 prevToPoint=prev.to(point);
    Vector2 pointToNext=point.to(next);
    if (!prevToPoint.isZero()) {
      double cross=prevToPoint.cross(pointToNext);
      if (Math.abs(cross) <= Epsilon.E) {
        continue;
      }
    }
    winding+=point.cross(next);
    result.add(point);
  }
  if (winding < 0.0) {
    Geometry.reverseWinding(result);
  }
  return result;
}

public static final List < Vector2 > cleanse ( List < Vector2 > points ) { if ( points == null ) throw new NullPointerException ( Messages . getString ( "geometry.nullPointList" ) ) ; int size = points . size ( ) ; if ( size == 0 ) return points ; List < Vector2 > result = new ArrayList < Vector2 > ( size ) ; double winding = 0.0 ; for ( int i = 0 ; i < size ; i ++ ) { Vector2 point = points . get ( i ) ; Vector2 prev = points . get ( i - 1 < 0 ? size - 1 : i - 1 ) ; Vector2 next = points . get ( i + 1 == size ? 0 : i + 1 ) ; if ( point == null || prev == null || next == null ) throw new NullPointerException ( Messages . getString ( "geometry.nullPointListElements" ) ) ; Vector2 diff = point . difference ( next ) ; if ( diff . isZero ( ) ) { continue ; } Vector2 prevToPoint = prev . to ( point ) ; Vector2 pointToNext = point . to ( next ) ; if ( ! prevToPoint . isZero ( ) ) { double cross = prevToPoint . cross ( pointToNext ) ; if ( Math . abs ( cross ) <= Epsilon . E ) { continue ; } } winding += point . cross ( next ) ; result . add ( point ) ; } if ( winding < 0.0 ) { Geometry . reverseWinding ( result ) ; } return result ; }
returns a new list containing the ' cleansed ' version of the given listing of polygon points . < p > this method ensures the polygon has ccw winding , removes colinear vertices , and removes coincident vertices . < p > if the given list is empty , the list is returned .
