Made Point immutable

pull/35/head
James Ball 2020-01-30 21:11:48 +00:00
rodzic 0a479d82e7
commit 8f38081ca1
1 zmienionych plików z 8 dodań i 10 usunięć

Wyświetl plik

@ -3,8 +3,8 @@ package shapes;
import java.util.Objects;
public class Point {
private double x;
private double y;
private final double x;
private final double y;
private static final double EPSILON = 0.001;
@ -21,12 +21,12 @@ public class Point {
return y;
}
public void setX(double x) {
this.x = x;
public Point setX(double x) {
return new Point(x, this.y);
}
public void setY(double y) {
this.y = y;
public Point setY(double y) {
return new Point(this.x, y);
}
@Override
@ -56,10 +56,8 @@ public class Point {
}
public Point rotate(double theta) {
Point point = new Point(getX(), getY());
point.setX(getX() * Math.cos(theta) - getY() * Math.sin(theta));
point.setY(getX() * Math.sin(theta) + getY() * Math.cos(theta));
Point point = setX(getX() * Math.cos(theta) - getY() * Math.sin(theta));
point = point.setY(getX() * Math.sin(theta) + getY() * Math.cos(theta));
return point;
}