Skip to content

Commit 91df2bc

Browse files
committed
Fix
1 parent d19db33 commit 91df2bc

File tree

2 files changed

+1
-91
lines changed

2 files changed

+1
-91
lines changed

src/main/java/com/thealgorithms/geometry/GrahamScan.java

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.ArrayList;
44
import java.util.Arrays;
5-
import java.util.Comparator;
65
import java.util.Stack;
76

87
/**
@@ -66,93 +65,4 @@ public GrahamScan(Point[] points) {
6665
public Iterable<Point> hull() {
6766
return new ArrayList<>(hull);
6867
}
69-
70-
public record Point(int x, int y) implements Comparable<Point> {
71-
72-
/**
73-
* Default constructor
74-
* @param x x-coordinate
75-
* @param y y-coordinate
76-
*/
77-
public Point {
78-
}
79-
80-
/**
81-
* @return the x-coordinate
82-
*/
83-
@Override
84-
public int x() {
85-
return x;
86-
}
87-
88-
/**
89-
* @return the y-coordinate
90-
*/
91-
@Override
92-
public int y() {
93-
return y;
94-
}
95-
96-
/**
97-
* Determines the orientation of the triplet (a, b, c).
98-
*
99-
* @param a The first point
100-
* @param b The second point
101-
* @param c The third point
102-
* @return -1 if (a, b, c) is clockwise, 0 if collinear, +1 if counterclockwise
103-
*/
104-
public static int orientation(Point a, Point b, Point c) {
105-
int val = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
106-
return Integer.compare(val, 0);
107-
}
108-
109-
/**
110-
* Compares this point with another point.
111-
*
112-
* @param p2 The point to compare to
113-
* @return A positive integer if this point is greater, a negative integer if less, or 0 if equal
114-
*/
115-
@Override
116-
public int compareTo(Point p2) {
117-
int cmpY = Integer.compare(this.y, p2.y);
118-
return cmpY != 0 ? cmpY : Integer.compare(this.x, p2.x);
119-
}
120-
121-
/**
122-
* Returns a comparator to sort points by their polar order relative to this point.
123-
*
124-
* @return A polar order comparator
125-
*/
126-
public Comparator<Point> polarOrder() {
127-
return new PolarOrder();
128-
}
129-
130-
private final class PolarOrder implements Comparator<Point> {
131-
@Override
132-
public int compare(Point p1, Point p2) {
133-
int dx1 = p1.x - x;
134-
int dy1 = p1.y - y;
135-
int dx2 = p2.x - x;
136-
int dy2 = p2.y - y;
137-
138-
if (dy1 >= 0 && dy2 < 0) {
139-
return -1; // p1 above p2
140-
} else if (dy2 >= 0 && dy1 < 0) {
141-
return 1; // p1 below p2
142-
} else if (dy1 == 0 && dy2 == 0) { // Collinear and horizontal
143-
return Integer.compare(dx2, dx1);
144-
} else {
145-
return -orientation(Point.this, p1, p2); // Compare orientation
146-
}
147-
}
148-
}
149-
150-
/**
151-
* @return A string representation of this point in the format (x, y)
152-
*/
153-
@Override
154-
public String toString() {
155-
return String.format("(%d, %d)", x, y);
156-
}
157-
}
15868
}

src/test/java/com/thealgorithms/geometry/GrahamScanTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class GrahamScanTest {
88
@Test
99
void testGrahamScan() {
10-
GrahamScan.Point[] points = {new GrahamScan.Point(0, 3), new GrahamScan.Point(1, 1), new GrahamScan.Point(2, 2), new GrahamScan.Point(4, 4), new GrahamScan.Point(0, 0), new GrahamScan.Point(1, 2), new GrahamScan.Point(3, 1), new GrahamScan.Point(3, 3)};
10+
Point[] points = {new Point(0, 3), new Point(1, 1), new Point(2, 2), new Point(4, 4), new Point(0, 0), new Point(1, 2), new Point(3, 1), new Point(3, 3)};
1111
String expectedResult = "[(0, 0), (3, 1), (4, 4), (0, 3)]";
1212

1313
GrahamScan graham = new GrahamScan(points);

0 commit comments

Comments
 (0)