/** * Returns the center of a list of points. * @param points The list of points * @return A new point indicating the center of the given points. */ public static Point centroid(Iterable<Point> points) { int size = 0; Point sumPoint = new Point(0, 0); for (final Point p : points) { sumPoint = Point.add(sumPoint, p); size++; } return divide(sumPoint, size); }
/** * Returns the center of a list of points. * @param points The list of points * @return A new point indicating the center of the given points. */ public static Point centroid(Iterable<Point> points) { int size = 0; Point sumPoint = new Point(0, 0); for (final Point p : points) { sumPoint = Point.add(sumPoint, p); size++; } return divide(sumPoint, size); }
@Test public void testAdd() { final Point p1 = new Point(1, 2); final Point p2 = new Point(3, 4); final Point result = Point.add(p1, p2); assertEquals(new Point(4, 6), result); }