MCPcopy
hub / github.com/g3n/engine / ClampPoint

Method ClampPoint

math32/sphere.go:98–115  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

96// nearest of the specified point.
97// The clamped point is stored in optionalTarget, if not nil, and returned.
98func (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.

Callers

nothing calls this directly

Calls 7

CopyMethod · 0.95
SubMethod · 0.95
MultiplyScalarMethod · 0.95
NewVector3Function · 0.85
DistanceToSquaredMethod · 0.45
NormalizeMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected