APL/APL2.1/TP04/Segment/Segment.java

42 lines
836 B
Java
Raw Normal View History

2022-02-15 11:26:26 +01:00
import java.awt.Point;
public class Segment {
private Point start;
private Point end;
public Segment(Point p1, Point p2) {
start = p1;
end = p2;
}
public Segment(int x1, int y1, int x2, int y2) {
start = new Point(x1, y1);
end = new Point(x2, y2);
}
public double length() {
return Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
}
public void setStart(Point p) {
start = p;
}
public void setStart(int x, int y) {
start.x = x;
start.y = y;
}
public void setEnd(Point p) {
end = p;
}
public void setEnd(int x, int y) {
end.x = x;
end.y = y;
}
public boolean equals(Segment s2) {
return this.start == s2.start && this.end == s2.end;
}
}