private void updateCurve(final double posX, final double posY, final double minX, final double maxX, final double step) {
// The algorithm follows this definition:
//https://stackoverflow.com/questions/15864441/how-to-make-a-line-curve-through-points
final double scale = 0.33;
final IBezierCurve bc = ShapeFactory.createBezierCurve();
if(curveView!=null) curveView.flush();
curveView = new LBezierCurveView(bc);
fillPoints(bc, posX, posY, minX, maxX, step);
if(shape.getPlotStyle()==IPlotProp.PlotStyle.CCURVE)
bc.setIsClosed(true);
else bc.setIsClosed(false);
bc.copy(shape);
int i=0;
final int last = bc.getPoints().size()-1;
for(IPoint pt : bc.getPoints()) {
final IPoint p1 = pt;
if(i==0) {
final IPoint p2 = bc.getPtAt(i+1);
final IPoint tangent = p2.substract(p1);
final IPoint q1 = p1.add(tangent.zoom(scale));
bc.setXFirstCtrlPt(q1.getX(), i);
bc.setYFirstCtrlPt(q1.getY(), i);
}else if(i==last) {
final IPoint p0 = bc.getPtAt(i-1);
final IPoint tangent = p1.substract(p0);
final IPoint q0 = p1.substract(tangent.zoom(scale));
bc.setXFirstCtrlPt(q0.getX(), i);
bc.setYFirstCtrlPt(q0.getY(), i);
}else {
final IPoint p0 = bc.getPtAt(i-1);
final IPoint p2 = bc.getPtAt(i+1);
final IPoint tangent = p2.substract(p0).normalise();
final IPoint q0 = p1.substract(tangent.zoom(scale*p1.substract(p0).magnitude()));
// val q1 = p1.substract(tangent.zoom(scale*p2.substract(p1).magnitude))
bc.setXFirstCtrlPt(q0.getX(), i);
bc.setYFirstCtrlPt(q0.getY(), i);
// shape.setXSecondCtrlPt(q1.getX, i)
// shape.setYSecondCtrlPt(q1.getY, i)
}
i++;
}
bc.updateSecondControlPoints();
curveView.update();
}