@Test public void testOffCenter() { Point2D actual = PieChart.calculateEndPoint(150, 150, 100, 0.5); Point2D expected = new Point2D.Double(150, 250); Assert.assertEquals(expected.getX(), actual.getX(), TOLERANCE); Assert.assertEquals(expected.getY(), actual.getY(), TOLERANCE); }
static Point2D calculateEndPoint(double radius, double centerX, double centerY, double ratio) { if (ratio > 1) { ratio = 1.0; } double radians = ratio * 2 * Math.PI; double x = radius * (1 + Math.sin(radians)); double y = radius * (1 - Math.cos(radians)); return new Point2D.Double(x + centerX - radius, y + centerY - radius); }
PieChart { static Point2D calculateEndPoint(double radius, double centerX, double centerY, double ratio) { if (ratio > 1) { ratio = 1.0; } double radians = ratio * 2 * Math.PI; double x = radius * (1 + Math.sin(radians)); double y = radius * (1 - Math.cos(radians)); return new Point2D.Double(x + centerX - radius, y + centerY - radius); } }
PieChart { static Point2D calculateEndPoint(double radius, double centerX, double centerY, double ratio) { if (ratio > 1) { ratio = 1.0; } double radians = ratio * 2 * Math.PI; double x = radius * (1 + Math.sin(radians)); double y = radius * (1 - Math.cos(radians)); return new Point2D.Double(x + centerX - radius, y + centerY - radius); }  }
PieChart { static Point2D calculateEndPoint(double radius, double centerX, double centerY, double ratio) { if (ratio > 1) { ratio = 1.0; } double radians = ratio * 2 * Math.PI; double x = radius * (1 + Math.sin(radians)); double y = radius * (1 - Math.cos(radians)); return new Point2D.Double(x + centerX - radius, y + centerY - radius); }  static double calculateEndPointX(
      double radius, double centerX, double centerY, double ratio); static double calculateEndPointY(
      double radius, double centerX, double centerY, double ratio); }
PieChart { static Point2D calculateEndPoint(double radius, double centerX, double centerY, double ratio) { if (ratio > 1) { ratio = 1.0; } double radians = ratio * 2 * Math.PI; double x = radius * (1 + Math.sin(radians)); double y = radius * (1 - Math.cos(radians)); return new Point2D.Double(x + centerX - radius, y + centerY - radius); }  static double calculateEndPointX(
      double radius, double centerX, double centerY, double ratio); static double calculateEndPointY(
      double radius, double centerX, double centerY, double ratio);  }