MCPcopy
hub / github.com/EngoEngine/engo / Normalize

Method Normalize

math.go:153–162  ·  view source on GitHub ↗

Normalize returns the unit vector from p, and its magnitude. if you try to normalize the null vector, the return value will be null values

()

Source from the content-addressed store, hash-verified

151// Normalize returns the unit vector from p, and its magnitude.
152// if you try to normalize the null vector, the return value will be null values
153func (p *Point) Normalize() (Point, float32) {
154 if p.X == 0 && p.Y == 0 {
155 return *p, 0
156 }
157
158 mag := math.Sqrt(p.X*p.X + p.Y*p.Y)
159 unit := Point{p.X / mag, p.Y / mag}
160
161 return unit, mag
162}
163
164// Within reports whether the point is contained within the given container.
165func (p Point) Within(c Container) bool {

Callers 6

NormalMethod · 0.95
separationOfAxesFunction · 0.95
UpdateMethod · 0.95
TestPointNormalizeFunction · 0.80
UpdateMethod · 0.80
UpdateMethod · 0.80

Calls 1

SqrtFunction · 0.92

Tested by 1

TestPointNormalizeFunction · 0.64