@Test public void approximationWithEqualStartAndEndAndHugeDistanceToleranceManhattanTest() { 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); double oldDistanceToleranceManhattan = BezierCurve.distanceToleranceManhattan; try { BezierCurve.distanceToleranceManhattan = 142d; List<Point> approximation = curve.getPiecewiseLinearApproximation(); List<Point> expectedApproximation = Arrays.asList(new Point(0.000000f, 0.000000f), new Point(0.75f, 1.875f), new Point(0.000000f, 0.000000f)); 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); } } finally { BezierCurve.distanceToleranceManhattan = oldDistanceToleranceManhattan; } }
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; }