From 8930c7ba565def87f8c618d7359dfb036eb97ad4 Mon Sep 17 00:00:00 2001 From: Andrej Stojkovikj Date: Tue, 19 Sep 2023 16:09:18 +0200 Subject: [PATCH] Implemented static functions for length and length squared for Vectors --- Source/Engine/Core/Math/Vector2.cs | 18 ++++++++++++++++++ Source/Engine/Core/Math/Vector3.cs | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Source/Engine/Core/Math/Vector2.cs b/Source/Engine/Core/Math/Vector2.cs index 568c51764..e953acfd6 100644 --- a/Source/Engine/Core/Math/Vector2.cs +++ b/Source/Engine/Core/Math/Vector2.cs @@ -821,6 +821,24 @@ namespace FlaxEngine return value; } + /// + /// Returns the length of a vector. + /// + /// The vector to get the length from. + public static Real Length(Vector2 vector) + { + return (Real)Mathf.Sqrt(vector.X * vector.X + vector.Y * vector.Y); + } + + /// + /// Returns the length squared of a vector. + /// + /// The vector to get the length squared from. + public static Real LengthSquared(Vector2 vector) + { + return vector.X * vector.X + vector.Y * vector.Y; + } + /// /// Makes sure that Length of the output vector is always below max and above 0. /// diff --git a/Source/Engine/Core/Math/Vector3.cs b/Source/Engine/Core/Math/Vector3.cs index 0ad557a32..c4bcf6979 100644 --- a/Source/Engine/Core/Math/Vector3.cs +++ b/Source/Engine/Core/Math/Vector3.cs @@ -963,6 +963,24 @@ namespace FlaxEngine return value; } + /// + /// Returns the length of a vector. + /// + /// The vector to get the length from. + public static Real Length(Vector3 vector) + { + return (Real)Mathf.Sqrt(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z); + } + + /// + /// Returns the length squared of a vector. + /// + /// The vector to get the length squared from. + public static Real LengthSquared(Vector3 vector) + { + return vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z; + } + /// /// Makes sure that Length of the output vector is always below max and above 0. ///