code: public static List<PointIndex_I32> fitPolygon(List<Point2D_I32> sequence, boolean loop,
  												  int minimumSideLength , double cornerPenalty ) {
  
  		PolylineSplitMerge alg = new PolylineSplitMerge();
  		alg.setLoops(loop);
  		alg.setMinimumSideLength(minimumSideLength);
  		alg.setCornerScorePenalty(cornerPenalty);
  
  		alg.process(sequence);
  		PolylineSplitMerge.CandidatePolyline best = alg.getBestPolyline();
  
  		FastQueue<PointIndex_I32> output = new FastQueue<>(PointIndex_I32.class, true);
  		if( best != null ) {
  			indexToPointIndex(sequence,best.splits,output);
  		}
  
  		return new ArrayList<>(output.toList());
  	}
docs: <p>Fits a polygon to the provided sequence of connected points.  The found polygon is returned as a list of
  vertices.  Each point in the original sequence is guaranteed to be within "toleranceDist' of a line segment.</p>
  
  <p>Internally a split-and-merge algorithm is used.  See referenced classes for more information. Consider
  using internal algorithms directly if this function is a performance bottleneck.</p>
  
  @see SplitMergeLineFitLoop
  @see SplitMergeLineFitSegment
  
  @param sequence Ordered and connected list of points.
  @param loop If true the sequence is a connected at both ends, otherwise it is assumed to not be.
  @param minimumSideLength The minimum allowed side length in pixels. Try 10
  @param cornerPenalty How much a corner is penalized. Try 0.25
  @return Vertexes in the fit polygon.