@Test public void testMatchingNaiveAlgorithm() { final int TRIALS = 1000; for (int i = 0; i < TRIALS; i++) { List<Point> points = makeRandomPoints(rand.nextInt(30) + 1); Circle reference = smallestEnclosingCircleNaive(points); Circle actual = SmallestEnclosingCircle.makeCircle(points); assertEquals(reference.c.x, actual.c.x, EPSILON); assertEquals(reference.c.y, actual.c.y, EPSILON); assertEquals(reference.r , actual.r , EPSILON); } }
public static Circle makeCircle(List<Point> points) { List<Point> shuffled = new ArrayList<>(points); Collections.shuffle(shuffled, new Random()); Circle c = null; for (int i = 0; i < shuffled.size(); i++) { Point p = shuffled.get(i); if (c == null || !c.contains(p)) c = makeCircleOnePoint(shuffled.subList(0, i + 1), p); } return c; }
SmallestEnclosingCircle { public static Circle makeCircle(List<Point> points) { List<Point> shuffled = new ArrayList<>(points); Collections.shuffle(shuffled, new Random()); Circle c = null; for (int i = 0; i < shuffled.size(); i++) { Point p = shuffled.get(i); if (c == null || !c.contains(p)) c = makeCircleOnePoint(shuffled.subList(0, i + 1), p); } return c; } }
SmallestEnclosingCircle { public static Circle makeCircle(List<Point> points) { List<Point> shuffled = new ArrayList<>(points); Collections.shuffle(shuffled, new Random()); Circle c = null; for (int i = 0; i < shuffled.size(); i++) { Point p = shuffled.get(i); if (c == null || !c.contains(p)) c = makeCircleOnePoint(shuffled.subList(0, i + 1), p); } return c; }  }
SmallestEnclosingCircle { public static Circle makeCircle(List<Point> points) { List<Point> shuffled = new ArrayList<>(points); Collections.shuffle(shuffled, new Random()); Circle c = null; for (int i = 0; i < shuffled.size(); i++) { Point p = shuffled.get(i); if (c == null || !c.contains(p)) c = makeCircleOnePoint(shuffled.subList(0, i + 1), p); } return c; }  static Circle makeCircle(List<Point> points); }
SmallestEnclosingCircle { public static Circle makeCircle(List<Point> points) { List<Point> shuffled = new ArrayList<>(points); Collections.shuffle(shuffled, new Random()); Circle c = null; for (int i = 0; i < shuffled.size(); i++) { Point p = shuffled.get(i); if (c == null || !c.contains(p)) c = makeCircleOnePoint(shuffled.subList(0, i + 1), p); } return c; }  static Circle makeCircle(List<Point> points);  }