package model;

import sun.awt.image.ImageWatched;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

/**
 * Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
 *
 * @Author: Armin Wolf
 * @Email: a_wolf28@uni-muenster.de
 * @Date: 28.05.2017.
 */
public class LineModel {

    private ArrayList<Point> nodes;
    private LinkedList<Line> lines;
    private Double xMinimum;
    private Double xMaximum;
    private Double yMinimum;
    private Double yMaximum;

    public LineModel() {
        nodes = new ArrayList<>();
        lines = new LinkedList<>();

        xMinimum = Double.MAX_VALUE;
        xMaximum = Double.MIN_VALUE;
        yMinimum = Double.MAX_VALUE;
        yMaximum = Double.MIN_VALUE;

    }

    public void setXbounds() {
        LinkedList<Double> xlist = new LinkedList<>();
        for (Point p : nodes) {
            xlist.add(p.getX());
        }

        xMaximum = Collections.max(xlist);
        xMinimum = Collections.min(xlist);
    }

    public void setYbounds() {
        LinkedList<Double> ylist = new LinkedList<>();
        for (Point p : nodes) {
            ylist.add(p.getY());
        }

        yMaximum = Collections.max(ylist);
        yMinimum = Collections.min(ylist);
    }

    public void addNode(Point node) {
        this.nodes.add(node);
        xMaximum = (node.getX() > xMaximum) ? node.getX() : xMinimum;
        xMinimum = (node.getX() <= xMinimum) ? node.getX() : xMinimum;
        yMaximum = (node.getY() > yMaximum) ? node.getY() : yMaximum;
        yMaximum = (node.getY() <= yMaximum) ? node.getY() : yMaximum;

    }

    public void addLine(Line line) {
        this.lines.add(line);
    }

    public ArrayList<Point> getNodes() {
        return nodes;
    }

    public void setNodes(ArrayList<Point> nodes) {
        this.nodes = nodes;
    }

    public LinkedList<Line> getLines() {
        return lines;
    }

    public void setLines(LinkedList<Line> lines) {
        this.lines = lines;
    }

    public Double getxMinimum() {
        return xMinimum;
    }

    public void setxMinimum(Double xMinimum) {
        this.xMinimum = xMinimum;
    }

    public Double getxMaximum() {
        return xMaximum;
    }

    public void setxMaximum(Double xMaximum) {
        this.xMaximum = xMaximum;
    }

    public Double getyMinimum() {
        return yMinimum;
    }

    public void setyMinimum(Double yMinimum) {
        this.yMinimum = yMinimum;
    }

    public Double getyMaximum() {
        return yMaximum;
    }

    public void setyMaximum(Double yMaximum) {
        this.yMaximum = yMaximum;
    }

    public void resetRanges(){
        xMinimum = Double.MAX_VALUE;
        xMaximum = Double.MIN_VALUE;
        yMinimum = Double.MAX_VALUE;
        yMaximum = Double.MIN_VALUE;
    }
}
