clamp method

Vec clamp(
  1. Vec vec
)

Returns a new Vec that is as near to vec as possible while being in bounds.

Implementation

Vec clamp(Vec vec) {
  var x = vec.x.clamp(left, right).toInt();
  var y = vec.y.clamp(top, bottom).toInt();
  return Vec(x, y);
}