int (int count, int margin, int value, int min, int max) { int offset = Math.min(count * margin, (max - min) / 2); if (value < (min += offset)) { double delta = (min - value) / (double)margin; return count < delta ? 0 : -(int)Math.floor(delta * delta); } if (value > (max -= offset)) { double delta = (value - max) / (double)margin; return count < delta ? 0 : (int)Math.floor(delta * delta); } return 0; }