clampPoint method

Vector3 clampPoint(
  1. Vector3 point,
  2. Vector3 target
)

Implementation

Vector3 clampPoint(Vector3 point, Vector3 target) {
  var deltaLengthSq = center.distanceToSquared(point);

  target.copy(point);

  if (deltaLengthSq > (radius * radius)) {
    target.sub(center).normalize();
    target.multiplyScalar(radius).add(center);
  }

  return target;
}