package de.wwwu.awolf.model; import org.apache.commons.math3.util.Precision; import java.util.Objects; /** * Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden. * * @Author: Armin Wolf * @Email: a_wolf28@uni-muenster.de * @Date: 28.05.2017. */ public class Point implements Comparable { private final double epsilon = 0.00001; private Double x; private Double y; private String id; /** * Konstruktor * * @param x x-Koordiante * @param y y-Koordiante */ public Point(Double x, Double y) { this.x = x; this.y = y; } /** * Konstruktor * * @param x x-Koordiante * @param y y-Koordiante * @param id id des Punkts */ public Point(Double x, Double y, String id) { this.x = x; this.y = y; this.id = id; } /** * @return x-Koordinate des Punkts */ public Double getX() { return x; } /** * @param x x-Koordinate des Punkts */ public void setX(Double x) { this.x = x; } /** * @return y-Koordinate des Punkts */ public Double getY() { return y; } /** * @param y y-Koordinate des Punkts */ public void setY(Double y) { this.y = y; } @Override public int compareTo(Point o) { if (Precision.compareTo(this.getX(), o.getX(), epsilon) == 0) { return this.getY().compareTo(o.getY()); } else { return this.getX().compareTo(o.getX()); } } /** * Vergleich zweier Punkte * * @param obj zu vergleichernder Punkt * @return true falls die Punkte gleich sind */ @Override public boolean equals(Object obj) { if (obj instanceof Point) { Point other = (Point) obj; return Precision.equals(other.getX(), this.getX(), epsilon) && Precision.equals(other.getY(), this.getY(), epsilon); } else { return super.equals(obj); } } @Override public int hashCode() { return Objects.hash(Precision.round(x, 5), Precision.round(y, 5)); } /** * @return id des Punkts */ public String getId() { return id; } /** * @param id id des Punkts */ public void setId(String id) { this.id = id; } }