From ab135a49658e5ab05b00e94396fa5fd311599fa8 Mon Sep 17 00:00:00 2001 From: Marc Brun Date: Thu, 9 Mar 2023 22:43:37 +0100 Subject: [PATCH] feat(Vec): add squared len method --- vector.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vector.go b/vector.go index d9081b3..42318b0 100644 --- a/vector.go +++ b/vector.go @@ -128,6 +128,11 @@ func (u Vec) Len() float64 { return math.Hypot(u.X, u.Y) } +// SqLen returns the squared length of the vector u (faster to compute than Len). +func (u Vec) SqLen() float64 { + return u.X*u.X + u.Y*u.Y +} + // Angle returns the angle between the vector u and the x-axis. The result is in range [-Pi, Pi]. func (u Vec) Angle() float64 { return math.Atan2(u.Y, u.X)