2020-03-21 00:37:09 +00:00
|
|
|
package de.wwwu.awolf.model;
|
2017-09-10 15:45:47 +00:00
|
|
|
|
2020-04-05 17:28:38 +00:00
|
|
|
import java.util.Objects;
|
2020-04-05 18:53:52 +00:00
|
|
|
import org.apache.commons.math3.util.Precision;
|
2020-04-05 17:28:38 +00:00
|
|
|
|
2017-09-10 15:45:47 +00:00
|
|
|
/**
|
|
|
|
* 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<Point> {
|
|
|
|
|
2020-04-05 17:59:10 +00:00
|
|
|
private static final double EPSILON = 0.00001;
|
2020-04-05 17:28:38 +00:00
|
|
|
|
2017-09-10 15:45:47 +00:00
|
|
|
private Double x;
|
|
|
|
private Double y;
|
|
|
|
private String id;
|
|
|
|
|
2017-10-13 09:53:45 +00:00
|
|
|
/**
|
|
|
|
* Konstruktor
|
2020-03-20 17:08:18 +00:00
|
|
|
*
|
2017-10-13 09:53:45 +00:00
|
|
|
* @param x x-Koordiante
|
|
|
|
* @param y y-Koordiante
|
|
|
|
*/
|
2017-09-10 15:45:47 +00:00
|
|
|
public Point(Double x, Double y) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
}
|
|
|
|
|
2017-10-13 09:53:45 +00:00
|
|
|
/**
|
|
|
|
* Konstruktor
|
2020-03-20 17:08:18 +00:00
|
|
|
*
|
|
|
|
* @param x x-Koordiante
|
|
|
|
* @param y y-Koordiante
|
2017-10-13 09:53:45 +00:00
|
|
|
* @param id id des Punkts
|
|
|
|
*/
|
2017-09-10 15:45:47 +00:00
|
|
|
public Point(Double x, Double y, String id) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2017-10-13 09:53:45 +00:00
|
|
|
/**
|
|
|
|
* @return x-Koordinate des Punkts
|
|
|
|
*/
|
2017-09-10 15:45:47 +00:00
|
|
|
public Double getX() {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2017-10-13 09:53:45 +00:00
|
|
|
/**
|
|
|
|
* @param x x-Koordinate des Punkts
|
|
|
|
*/
|
2017-09-10 15:45:47 +00:00
|
|
|
public void setX(Double x) {
|
|
|
|
this.x = x;
|
|
|
|
}
|
|
|
|
|
2017-10-13 09:53:45 +00:00
|
|
|
/**
|
|
|
|
* @return y-Koordinate des Punkts
|
|
|
|
*/
|
2017-09-10 15:45:47 +00:00
|
|
|
public Double getY() {
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2017-10-13 09:53:45 +00:00
|
|
|
/**
|
|
|
|
* @param y y-Koordinate des Punkts
|
|
|
|
*/
|
2017-09-10 15:45:47 +00:00
|
|
|
public void setY(Double y) {
|
|
|
|
this.y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(Point o) {
|
2020-04-05 17:59:10 +00:00
|
|
|
if (Precision.compareTo(this.getX(), o.getX(), EPSILON) == 0) {
|
2020-04-05 17:28:38 +00:00
|
|
|
return this.getY().compareTo(o.getY());
|
2017-09-10 15:45:47 +00:00
|
|
|
} else {
|
2020-04-05 17:28:38 +00:00
|
|
|
return this.getX().compareTo(o.getX());
|
2017-09-10 15:45:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-13 09:53:45 +00:00
|
|
|
/**
|
|
|
|
* Vergleich zweier Punkte
|
2020-03-20 17:08:18 +00:00
|
|
|
*
|
2020-03-21 00:37:09 +00:00
|
|
|
* @param obj zu vergleichernder Punkt
|
2017-10-13 09:53:45 +00:00
|
|
|
* @return <code>true</code> falls die Punkte gleich sind
|
|
|
|
*/
|
2020-03-21 00:37:09 +00:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj instanceof Point) {
|
|
|
|
Point other = (Point) obj;
|
2020-04-05 18:53:52 +00:00
|
|
|
return Precision.equals(other.getX(), this.getX(), EPSILON) && Precision
|
|
|
|
.equals(other.getY(), this.getY(), EPSILON);
|
2020-03-21 00:37:09 +00:00
|
|
|
} else {
|
|
|
|
return super.equals(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2020-04-05 17:28:38 +00:00
|
|
|
return Objects.hash(Precision.round(x, 5), Precision.round(y, 5));
|
2017-09-18 21:16:18 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 09:53:45 +00:00
|
|
|
/**
|
|
|
|
* @return id des Punkts
|
|
|
|
*/
|
2017-09-10 15:45:47 +00:00
|
|
|
public String getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2017-10-13 09:53:45 +00:00
|
|
|
/**
|
|
|
|
* @param id id des Punkts
|
|
|
|
*/
|
2017-09-10 15:45:47 +00:00
|
|
|
public void setId(String id) {
|
|
|
|
this.id = id;
|
|
|
|
}
|
2020-03-23 06:58:40 +00:00
|
|
|
|
|
|
|
|
2017-09-10 15:45:47 +00:00
|
|
|
}
|