package UE02_100924_Collections_TreeSet;

public class Punkt implements Comparable<Punkt> {
    int pointX;
    int pointY;

    public Punkt(int x, int y) {
        this.pointX = x;
        this.pointY = y;
    }

    @Override
    public String toString() {
        return "(" + pointX + "|" + pointY + ")";
    }

    @Override
    public int compareTo(Punkt o) {
        //Origin of the Sorting of the Points is the left lower corner.
        double vector = Math.sqrt(this.pointX * this.pointX + this.pointY * this.pointY);
        double objectVector = Math.sqrt(o.pointX * o.pointX + o.pointY * o.pointY);
        if (vector != objectVector) return Double.compare(vector, objectVector);
        if (this.pointX != o.pointX) return Integer.compare(this.pointX, o.pointX);
        return Integer.compare(this.pointY, o.pointY);
    }
}
