@Test(expected = IllegalArgumentException.class) public void interpolate_invalidPointsPerSegment_throwsIllegalArgumentException() { final XYSeries series = mock(XYSeries.class); final CatmullRomInterpolator.Params params = new CatmullRomInterpolator.Params(1, CatmullRomInterpolator.Type.Centripetal); new CatmullRomInterpolator().interpolate(series, params); }
@Override public List<XYCoords> interpolate(XYSeries series, Params params) { if (params.getPointPerSegment() < 2) { throw new IllegalArgumentException( "pointsPerSegment must be greater than 2, since 2 points is just the linear segment."); } if (series.size() < 3) { throw new IllegalArgumentException("Cannot interpolate a series with fewer than 3 vertices."); } double dx = series.getX(1).doubleValue() - series.getX(0).doubleValue(); double dy = series.getY(1).doubleValue() - series.getY(0).doubleValue(); double x1 = series.getX(0).doubleValue() - dx; double y1 = series.getY(0).doubleValue() - dy; XYCoords start = new XYCoords(x1, y1); int n = series.size() -1; dx = series.getX(n).doubleValue() - series.getX(n-1).doubleValue(); dy = series.getY(n).doubleValue() - series.getY(n - 1).doubleValue(); double xn = series.getX(n).doubleValue() + dx; double yn = series.getY(n).doubleValue() + dy; XYCoords end = new XYCoords(xn, yn); ExtrapolatedXYSeries extrapolatedXYSeries = new ExtrapolatedXYSeries(series, start, end); List<XYCoords> result = new ArrayList<>(); for (int i = 0; i < extrapolatedXYSeries.size() - 3; i++) { List<XYCoords> points = interpolate(extrapolatedXYSeries, i, params); if (result.size() > 0) { points.remove(0); } result.addAll(points); } return result; }
CatmullRomInterpolator implements Interpolator<CatmullRomInterpolator.Params> { @Override public List<XYCoords> interpolate(XYSeries series, Params params) { if (params.getPointPerSegment() < 2) { throw new IllegalArgumentException( "pointsPerSegment must be greater than 2, since 2 points is just the linear segment."); } if (series.size() < 3) { throw new IllegalArgumentException("Cannot interpolate a series with fewer than 3 vertices."); } double dx = series.getX(1).doubleValue() - series.getX(0).doubleValue(); double dy = series.getY(1).doubleValue() - series.getY(0).doubleValue(); double x1 = series.getX(0).doubleValue() - dx; double y1 = series.getY(0).doubleValue() - dy; XYCoords start = new XYCoords(x1, y1); int n = series.size() -1; dx = series.getX(n).doubleValue() - series.getX(n-1).doubleValue(); dy = series.getY(n).doubleValue() - series.getY(n - 1).doubleValue(); double xn = series.getX(n).doubleValue() + dx; double yn = series.getY(n).doubleValue() + dy; XYCoords end = new XYCoords(xn, yn); ExtrapolatedXYSeries extrapolatedXYSeries = new ExtrapolatedXYSeries(series, start, end); List<XYCoords> result = new ArrayList<>(); for (int i = 0; i < extrapolatedXYSeries.size() - 3; i++) { List<XYCoords> points = interpolate(extrapolatedXYSeries, i, params); if (result.size() > 0) { points.remove(0); } result.addAll(points); } return result; } }
CatmullRomInterpolator implements Interpolator<CatmullRomInterpolator.Params> { @Override public List<XYCoords> interpolate(XYSeries series, Params params) { if (params.getPointPerSegment() < 2) { throw new IllegalArgumentException( "pointsPerSegment must be greater than 2, since 2 points is just the linear segment."); } if (series.size() < 3) { throw new IllegalArgumentException("Cannot interpolate a series with fewer than 3 vertices."); } double dx = series.getX(1).doubleValue() - series.getX(0).doubleValue(); double dy = series.getY(1).doubleValue() - series.getY(0).doubleValue(); double x1 = series.getX(0).doubleValue() - dx; double y1 = series.getY(0).doubleValue() - dy; XYCoords start = new XYCoords(x1, y1); int n = series.size() -1; dx = series.getX(n).doubleValue() - series.getX(n-1).doubleValue(); dy = series.getY(n).doubleValue() - series.getY(n - 1).doubleValue(); double xn = series.getX(n).doubleValue() + dx; double yn = series.getY(n).doubleValue() + dy; XYCoords end = new XYCoords(xn, yn); ExtrapolatedXYSeries extrapolatedXYSeries = new ExtrapolatedXYSeries(series, start, end); List<XYCoords> result = new ArrayList<>(); for (int i = 0; i < extrapolatedXYSeries.size() - 3; i++) { List<XYCoords> points = interpolate(extrapolatedXYSeries, i, params); if (result.size() > 0) { points.remove(0); } result.addAll(points); } return result; }  }
CatmullRomInterpolator implements Interpolator<CatmullRomInterpolator.Params> { @Override public List<XYCoords> interpolate(XYSeries series, Params params) { if (params.getPointPerSegment() < 2) { throw new IllegalArgumentException( "pointsPerSegment must be greater than 2, since 2 points is just the linear segment."); } if (series.size() < 3) { throw new IllegalArgumentException("Cannot interpolate a series with fewer than 3 vertices."); } double dx = series.getX(1).doubleValue() - series.getX(0).doubleValue(); double dy = series.getY(1).doubleValue() - series.getY(0).doubleValue(); double x1 = series.getX(0).doubleValue() - dx; double y1 = series.getY(0).doubleValue() - dy; XYCoords start = new XYCoords(x1, y1); int n = series.size() -1; dx = series.getX(n).doubleValue() - series.getX(n-1).doubleValue(); dy = series.getY(n).doubleValue() - series.getY(n - 1).doubleValue(); double xn = series.getX(n).doubleValue() + dx; double yn = series.getY(n).doubleValue() + dy; XYCoords end = new XYCoords(xn, yn); ExtrapolatedXYSeries extrapolatedXYSeries = new ExtrapolatedXYSeries(series, start, end); List<XYCoords> result = new ArrayList<>(); for (int i = 0; i < extrapolatedXYSeries.size() - 3; i++) { List<XYCoords> points = interpolate(extrapolatedXYSeries, i, params); if (result.size() > 0) { points.remove(0); } result.addAll(points); } return result; }  @Override List<XYCoords> interpolate(XYSeries series, Params params); }
CatmullRomInterpolator implements Interpolator<CatmullRomInterpolator.Params> { @Override public List<XYCoords> interpolate(XYSeries series, Params params) { if (params.getPointPerSegment() < 2) { throw new IllegalArgumentException( "pointsPerSegment must be greater than 2, since 2 points is just the linear segment."); } if (series.size() < 3) { throw new IllegalArgumentException("Cannot interpolate a series with fewer than 3 vertices."); } double dx = series.getX(1).doubleValue() - series.getX(0).doubleValue(); double dy = series.getY(1).doubleValue() - series.getY(0).doubleValue(); double x1 = series.getX(0).doubleValue() - dx; double y1 = series.getY(0).doubleValue() - dy; XYCoords start = new XYCoords(x1, y1); int n = series.size() -1; dx = series.getX(n).doubleValue() - series.getX(n-1).doubleValue(); dy = series.getY(n).doubleValue() - series.getY(n - 1).doubleValue(); double xn = series.getX(n).doubleValue() + dx; double yn = series.getY(n).doubleValue() + dy; XYCoords end = new XYCoords(xn, yn); ExtrapolatedXYSeries extrapolatedXYSeries = new ExtrapolatedXYSeries(series, start, end); List<XYCoords> result = new ArrayList<>(); for (int i = 0; i < extrapolatedXYSeries.size() - 3; i++) { List<XYCoords> points = interpolate(extrapolatedXYSeries, i, params); if (result.size() > 0) { points.remove(0); } result.addAll(points); } return result; }  @Override List<XYCoords> interpolate(XYSeries series, Params params);  }