assert(trajectory.getEndPosition() != null);
double beginPosition = trajectory.getBeginPosition();
double endPosition = trajectory.getEndPosition();
IRangeEnergy range = ((ITrajectoryEnergy) trajectory).getRange();
if(endPosition == 0){
endPosition = beginPosition;
trajectory.setEndPosition(endPosition);
trajectory.setDelta(0.0);
}
else if(range != null){
if(deltaLock) {
double delta = trajectory.getDelta();
if(delta != 0) {
double steps = Math.abs((endPosition - beginPosition) / delta);
int stepsNumber = (int) Math.round(steps);
range.setStepsNumber(stepsNumber);
delta = Math.abs((beginPosition - endPosition) / stepsNumber);
trajectory.setDelta(delta);
}
}
else {
int stepsNumber = range.getStepsNumber();
double delta = Math.abs((beginPosition - endPosition) / stepsNumber);
trajectory.setDelta(delta);
}