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