ClampPoint clamps the specified point inside the sphere. If the specified point is inside the sphere, it is the clamped point. Otherwise the clamped point is the the point in the sphere surface in the nearest of the specified point. The clamped point is stored in optionalTarget, if not nil, and retu
(point *Vector3, optionalTarget *Vector3)
| 96 | // nearest of the specified point. |
| 97 | // The clamped point is stored in optionalTarget, if not nil, and returned. |
| 98 | func (s *Sphere) ClampPoint(point *Vector3, optionalTarget *Vector3) *Vector3 { |
| 99 | |
| 100 | deltaLengthSq := s.Center.DistanceToSquared(point) |
| 101 | |
| 102 | var result *Vector3 |
| 103 | if optionalTarget != nil { |
| 104 | result = optionalTarget |
| 105 | } else { |
| 106 | result = NewVector3(0, 0, 0) |
| 107 | } |
| 108 | result.Copy(point) |
| 109 | |
| 110 | if deltaLengthSq > (s.Radius * s.Radius) { |
| 111 | result.Sub(&s.Center).Normalize() |
| 112 | result.MultiplyScalar(s.Radius).Add(&s.Center) |
| 113 | } |
| 114 | return result |
| 115 | } |
| 116 | |
| 117 | // GetBoundingBox calculates a Box3 which bounds this sphere. |
| 118 | // Update optionalTarget with the calculated Box3, if not nil, and also returns it. |
nothing calls this directly
no test coverage detected