@Test public void approximationWithEqualStartAndEndTest() { List<Point> controlPoints = Arrays.asList(new Point(0f, 0f), new Point(-5f, 20f), new Point(7f, -15f), new Point(0f, 0f)); BezierCurve curve = new BezierCurve(controlPoints); List<Point> approximation = curve.getPiecewiseLinearApproximation(); List<Point> expectedApproximation = Arrays.asList(new Point(0f, 0f), new Point(-0.747070f, 3.131104f), new Point(-1.235962f, 5.747223f), new Point(-1.244339f, 6.259632f), new Point(-1.177597f, 6.350613f), new Point(-0.985474f, 6.159210f), new Point(-0.592163f, 5.392914f), new Point(0.184570f, 3.460693f), new Point(1.291992f, 0.230713f), new Point(2.094727f, -2.618408f), new Point(2.243042f, -3.765106f), new Point(2.026978f, -3.769684f), new Point(1.497437f, -2.986908f), new Point(0.601685f, -1.262970f), new Point(0f, 0f)); 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; }