-
Notifications
You must be signed in to change notification settings - Fork 0
/
Line.java
81 lines (62 loc) · 1.44 KB
/
Line.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package prg.es5;
import prg.es5.Point2D;
public class Line{
private Point2D p1 = new Point2D();
private Point2D p2 = new Point2D();
//COSTRUTTORI:
public Line(){}
public Line(Point2D p1, Point2D p2){
this.setAllPoints(p1, p2);
}
public Line(int x1, int y1, int x2, int y2){
this.setPositionAllPoints(x1, y1, x2, y2);
}
//METODI:
public Line setP1(Point2D p1){
this.p1.setXY(p1.getX(), p1.getY());
return this;
}
public Line setP2(Point2D p2){
this.p2.setXY(p2.getX(), p2.getY());
return this;
}
public Line setAllPoints(Point2D p1, Point2D p2){
return this.setP1(p1).setP2(p2);
}
public Line setPositionP1(int x, int y){
this.p1.setXY(x, y);
return this;
}
public Line setPositionP2(int x, int y){
this.p2.setXY(x, y);
return this;
}
public Line setPositionAllPoints(int xp1, int yp1, int xp2, int yp2){
return this.setPositionP1(xp1, yp1).setPositionP2(xp2, yp2);
}
public Point2D getP1(){
return this.p1;
}
public Point2D getP2(){
return this.p2;
}
public int getXP1(){
return this.p1.getX();
}
public int getXP2(){
return this.p2.getX();
}
public int getYP1(){
return this.p1.getY();
}
public int getYP2(){
return this.p2.getY();
}
public String toString(){
return "Line: " + p1.toString() + " " + p2.toString();
}
public Line toPrint(){
System.out.println(this.toString());
return this;
}
}