@@ -18,7 +18,7 @@ public Rectangle(String expression) {
18
18
}
19
19
20
20
if (expression .split (REGEX ).length != 4 ) {
21
- throw new IllegalArgumentException ("좌표는 두개 만 들어가야 합니다." );
21
+ throw new IllegalArgumentException ("좌표는 네 개 만 들어가야 합니다." );
22
22
}
23
23
24
24
List <Coordinate > coordinateList = Arrays .asList (
@@ -28,16 +28,18 @@ public Rectangle(String expression) {
28
28
new Coordinate (expression .split (REGEX )[3 ])
29
29
);
30
30
31
- if (coordinateList .stream ().map (Coordinate ::getX ).distinct ().count () != 2 ) {
32
- throw new IllegalArgumentException ();
33
- }
31
+ List <Double > distanceList = Arrays .asList (
32
+ getDistance (coordinateList .get (0 ), coordinateList .get (1 )),
33
+ getDistance (coordinateList .get (1 ), coordinateList .get (2 )),
34
+ getDistance (coordinateList .get (2 ), coordinateList .get (3 )),
35
+ getDistance (coordinateList .get (3 ), coordinateList .get (0 ))
36
+ );
34
37
35
- if (coordinateList .stream (). map ( Coordinate :: getY ).distinct ().count () != 2 ) {
38
+ if (distanceList .stream ().distinct ().count () != 2 ) {
36
39
throw new IllegalArgumentException ();
37
40
}
38
41
39
42
this .coordinates = coordinateList ;
40
-
41
43
}
42
44
43
45
@ Override
@@ -62,7 +64,7 @@ public List<Coordinate> findCoordinates() {
62
64
return new ArrayList <>(coordinates );
63
65
}
64
66
65
- public double getDistance (Coordinate coordinate , Coordinate otherCoordinate ) {
67
+ private double getDistance (Coordinate coordinate , Coordinate otherCoordinate ) {
66
68
return Math .sqrt (
67
69
abs ((coordinate .getX () - otherCoordinate .getX ()) * (coordinate .getX () - otherCoordinate .getX ())
68
70
+ (coordinate .getY () - otherCoordinate .getY ()) * (coordinate .getY () - otherCoordinate .getY ())));
0 commit comments