@Test public void approximationWithEqualSecondAndEndTest() { List<Point> controlPoints = Arrays.asList(new Point(0f, 0f), new Point(20f, 5f), new Point(7f, -15f), new Point(20f, 5f)); BezierCurve curve = new BezierCurve(controlPoints); List<Point> approximation = curve.getPiecewiseLinearApproximation(); List<Point> expectedApproximation = Arrays.asList(new Point(0f, 0f), new Point(1.780121f, 0.397491f), new Point(4.803497f, 0.800629f), new Point(7.183075f, 0.760651f), new Point(9.005280f, 0.372772f), new Point(10.356537f, -0.267792f), new Point(11.323273f, -1.065826f), new Point(12.241455f, -2.349854f), new Point(12.780609f, -3.452606f), new Point(13.073517f, -3.928375f), new Point(13.414032f, -4.085541f), new Point(13.888580f, -3.828888f), new Point(15.040771f, -2.459717f), new Point(17.852783f, 1.702881f), new Point(20f, 5f)); Assert.assertEquals(expectedApproximation.size(), approximation.size()); for (int i = 0; i < expectedApproximation.size(); ++i) { Assert.assertEquals(expectedApproximation.get(i).getX(), approximation.get(i).getX(), 0.001f); Assert.assertEquals(expectedApproximation.get(i).getY(), approximation.get(i).getY(), 0.001f); } }
public List<Point> getPiecewiseLinearApproximation() { List<Point> points = new ArrayList<>(); points.add(controlPoints.get(0)); recursiveApproximation(controlPoints.get(0).getX(), controlPoints.get(0).getY(), controlPoints.get(1).getX(), controlPoints.get(1).getY(), controlPoints.get(2).getX(), controlPoints.get(2).getY(), controlPoints.get(3).getX(), controlPoints.get(3).getY(), points); points.add(controlPoints.get(controlPoints.size() - 1)); return points; }
BezierCurve implements IShape { public List<Point> getPiecewiseLinearApproximation() { List<Point> points = new ArrayList<>(); points.add(controlPoints.get(0)); recursiveApproximation(controlPoints.get(0).getX(), controlPoints.get(0).getY(), controlPoints.get(1).getX(), controlPoints.get(1).getY(), controlPoints.get(2).getX(), controlPoints.get(2).getY(), controlPoints.get(3).getX(), controlPoints.get(3).getY(), points); points.add(controlPoints.get(controlPoints.size() - 1)); return points; } }
BezierCurve implements IShape { public List<Point> getPiecewiseLinearApproximation() { List<Point> points = new ArrayList<>(); points.add(controlPoints.get(0)); recursiveApproximation(controlPoints.get(0).getX(), controlPoints.get(0).getY(), controlPoints.get(1).getX(), controlPoints.get(1).getY(), controlPoints.get(2).getX(), controlPoints.get(2).getY(), controlPoints.get(3).getX(), controlPoints.get(3).getY(), points); points.add(controlPoints.get(controlPoints.size() - 1)); return points; } BezierCurve(List<Point> controlPoints); }
BezierCurve implements IShape { public List<Point> getPiecewiseLinearApproximation() { List<Point> points = new ArrayList<>(); points.add(controlPoints.get(0)); recursiveApproximation(controlPoints.get(0).getX(), controlPoints.get(0).getY(), controlPoints.get(1).getX(), controlPoints.get(1).getY(), controlPoints.get(2).getX(), controlPoints.get(2).getY(), controlPoints.get(3).getX(), controlPoints.get(3).getY(), points); points.add(controlPoints.get(controlPoints.size() - 1)); return points; } BezierCurve(List<Point> controlPoints); List<Point> getBasePoints(); List<Point> getPiecewiseLinearApproximation(); }
BezierCurve implements IShape { public List<Point> getPiecewiseLinearApproximation() { List<Point> points = new ArrayList<>(); points.add(controlPoints.get(0)); recursiveApproximation(controlPoints.get(0).getX(), controlPoints.get(0).getY(), controlPoints.get(1).getX(), controlPoints.get(1).getY(), controlPoints.get(2).getX(), controlPoints.get(2).getY(), controlPoints.get(3).getX(), controlPoints.get(3).getY(), points); points.add(controlPoints.get(controlPoints.size() - 1)); return points; } BezierCurve(List<Point> controlPoints); List<Point> getBasePoints(); List<Point> getPiecewiseLinearApproximation(); static double curveCollinearityEpsilon; static double distanceToleranceSquare; static double distanceToleranceManhattan; }