Java Convex Polygon benchmark code
[nit.git] / benchmarks / polygons / java / code / PolygonSorter.java
1
2 import java.util.Comparator;
3
4 /**
5 * An utility class to sort the polygon vertices, is extended by AntiClockSort
6 * and ClockSort
7 *
8 * @author Johan
9 */
10 public abstract class PolygonSorter implements Comparator<PointDouble> {
11
12 PointDouble center;
13
14 public PolygonSorter(double[][] podoubles) {
15 this.center = calcCenter(podoubles);
16 }
17
18 /**
19 * returns the point representing the center of a polygon
20 */
21 final PointDouble calcCenter(double[][] podoubles) {
22 double sumx = 0;
23 double sumy = 0;
24 for (double[] podouble : podoubles) {
25 sumx += podouble[0];
26 sumy += podouble[1];
27 }
28 return new PointDouble(sumx / podoubles.length, sumy / podoubles.length);
29 }
30
31 @Override
32 public abstract int compare(PointDouble a, PointDouble b);
33 }