Java Convex Polygon benchmark code
[nit.git] / benchmarks / polygons / java / code / PointDouble.java
1
2 import java.util.ArrayList;
3 import java.util.Random;
4
5 /**
6 * Represents a 2d point with double coordinates
7 *
8 * @author Johan
9 */
10 public class PointDouble {
11
12 double x;
13 double y;
14
15 public PointDouble() {
16 this(0.0d, 0.0d);
17 }
18
19 public PointDouble(double x, double y) {
20 this.x = x;
21 this.y = y;
22 }
23
24 public double getX() {
25 return this.x;
26 }
27
28 public double getY() {
29 return this.y;
30 }
31
32 @Override
33 public boolean equals(Object obj) {
34 if (obj == null || getClass() != obj.getClass()) {
35 return false;
36 }
37 final PointDouble other = (PointDouble) obj;
38 if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) {
39 return false;
40 }
41 if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) {
42 return false;
43 }
44 return true;
45 }
46
47 /**
48 * returns a array of n points on a circle
49 */
50 public static ArrayList<PointDouble> getNPointsOnCircle(double radius, int n) {
51 ArrayList<PointDouble> points = new ArrayList<>();
52 Random generator = new Random(0);
53 for(int i = 0; i < n; i++){
54 double angle = generator.nextFloat() * Math.PI * 2;
55 PointDouble p = new PointDouble(Math.cos(angle) * radius, Math.sin(angle) * radius);
56 points.add(p);
57 }
58 return points;
59 }
60 }