clamp method

Vector2 clamp(
  1. Vector2 min,
  2. Vector2 max
)

Implementation

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;
}