clampLength method

Vector3 clampLength(
  1. double min,
  2. double max
)

If this vector's length is greater than the max value, the vector will be scaled down so its length is the max value.

If this vector's length is less than the min value, the vector will be scaled up so its length is the min value.

  • min - the minimum value the length will be clamped to
  • max - the maximum value the length will be clamped to

Implementation

Vector3 clampLength(double min, double max) {
  var _length = length();
  var _max = math.max(min, math.min(max, _length));
  return divideScalar(_length).multiplyScalar(_max);
}