ConvexHull { static List<Point2D> pointsOf(final Shape shape) { final List<Point2D> points = new ArrayList<Point2D>(); final double[] coordinates = new double[6]; for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) { switch (i.currentSegment(coordinates)) { case PathIterator.SEG_CLOSE: break; case PathIterator.SEG_MOVETO: case PathIterator.SEG_LINETO: points.add(new Point2D.Double(coordinates[0], coordinates[1])); break; case PathIterator.SEG_QUADTO: points.add(new Point2D.Double(coordinates[0], coordinates[1])); points.add(new Point2D.Double(coordinates[2], coordinates[3])); break; case PathIterator.SEG_CUBICTO: points.add(new Point2D.Double(coordinates[0], coordinates[1])); points.add(new Point2D.Double(coordinates[2], coordinates[3])); points.add(new Point2D.Double(coordinates[4], coordinates[5])); break; } } if (!points.isEmpty() && points.get(points.size() - 1).equals(points.get(0))) { points.remove(points.size() - 1); } return points; } private  ConvexHull(final Shape hull); static ConvexHull ofShape(final Shape shape); static ConvexHull ofShapes(final List<Shape> shapes); static Point2D lineLineIntersect(final Line2D lineA, final Line2D lineB);  }
@Test public void testPointsOf() throws Exception { Rectangle2D rect = new Rectangle2D.Double(-5, -5, 10, 10); List<Point2D> points = ConvexHull.pointsOf(rect); assertThat(points.size(), is(4)); assertThat(points.get(0).getX(), closeTo(-5, 0.01)); assertThat(points.get(0).getY(), closeTo(-5, 0.01)); assertThat(points.get(1).getX(), closeTo(5, 0.01)); assertThat(points.get(1).getY(), closeTo(-5, 0.01)); assertThat(points.get(2).getX(), closeTo(5, 0.01)); assertThat(points.get(2).getY(), closeTo(5, 0.01)); assertThat(points.get(3).getX(), closeTo(-5, 0.01)); assertThat(points.get(3).getY(), closeTo(5, 0.01)); }