Vector2 clamp(Vector2 min, Vector2 max) { // assumes min < max, componentwise x = math.max(min.x, math.min(max.x, x)); y = math.max(min.y, math.min(max.y, y)); return this; }