package model.DCEL;

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

    private Node origin;
    private Edge twin;
    private Face incidentFace;
    private Edge next;
    private Edge prev;
    private String id;

    public Edge() {
        new Edge(null, null, null, null, null);
    }

    public Edge(Node origin, Edge twin, Edge next, Edge prev, Face incidentFace) {
        this.origin = origin;
        this.twin = twin;
        this.next = next;
        this.prev = prev;
        this.incidentFace = incidentFace;
    }

    public Node getOrigin() {
        return origin;
    }

    public void setOrigin(Node origin) {
        this.origin = origin;
    }

    public Edge getTwin() {
        return twin;
    }

    public void setTwin(Edge twin) {
        this.twin = twin;
    }

    public Face getIncidentFace() {
        return incidentFace;
    }

    public void setIncidentFace(Face incidentFace) {
        this.incidentFace = incidentFace;
    }

    public Edge getNext() {
        return next;
    }

    public void setNext(Edge next) {
        this.next = next;
    }

    public Edge getPrev() {
        return prev;
    }

    public void setPrev(Edge prev) {
        this.prev = prev;
    }

    public boolean hasNext() {
        if (getNext() == null) {
            return false;
        } else {
            return true;
        }

    }

    public Edge insertNode(Node node) {

        Edge edge = new Edge();
        Edge twin = new Edge();

        edge.setOrigin(node);
        edge.setNext(this.getNext());
        edge.setPrev(this);
        edge.setTwin(twin);
        edge.setIncidentFace(this.getIncidentFace());

        twin.setOrigin(this.getTwin().getOrigin());
        twin.setPrev(this.getTwin().getPrev());
        twin.setNext(this.getTwin());
        twin.setTwin(edge);
        twin.setIncidentFace(this.getTwin().getIncidentFace());

        Node twinOrigin = this.getTwin().getOrigin();
        twinOrigin.setIncidentEdge(twin);
        node.setIncidentEdge(edge);

        this.getTwin().setOrigin(node);
        this.getTwin().getPrev().setNext(twin);
        this.getNext().setPrev(edge);
        this.setNext(edge);
        this.getTwin().setPrev(twin);

        return edge;
    }

    public String getID() {
        return this.id;
    }

    public void setID(String id) {
        this.id = id;
    }
}
