clamp method

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

Implementation

Vector3 clamp(Vector3 min, Vector3 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));

  return this;
}