/*
 *  Alex Mathews, amathews@jhu.edu
 *  Pranav Lakshminarayanan, plakshm1@jhu.edu
 *  Computer Integrated Surgery I - Fall 2014
 */
package iterativeclosestpoint;

import java.util.ArrayList;

/**
 * Converges after running for a set number of iterations.
 * @author Alex
 */
public class IterationConvergence implements Convergence {
    
    /**
     * Desired number of iterations to be run.
     */
    private final int numIter;
    
    /**
     * Number of iterations completed.
     */
    private int iter = 0;
    
    /**
     * List of errors from each iteration.
     */
    private final ArrayList<Double> errors = new ArrayList<>();
        
    /**
     * Iteration Convergence Object.
     * @param ni number of iterations to complete.
     */
    public IterationConvergence(int ni) {
        this.numIter = ni;
    }
    
    
    @Override
    public ArrayList<Double> getErrors() {
        return this.errors;
    }
    
    @Override
    public boolean isConverged(double err) {
        this.errors.add(err);
        if (this.iter <= this.numIter) {
            this.iter++;
            return false;
        }
        return true;
    }
    
}
