Make sure pos is between min (default: 0) and the length of this document.
pos
min
int clampPos(int pos, [int min = 0]) { return pos.clamp(min, length); }