clamp method

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

Implementation

Vector4 clamp(Vector4 min, Vector4 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));
  z = math.max(min.z, math.min(max.z, z));
  w = math.max(min.w, math.min(max.w, w));

  return this;
}