From d39787c9de3ee900102928ac5e388ba702b9bbc6 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Mon, 24 Sep 2007 20:18:51 +0000 Subject: [PATCH] Added length, normal and scale calculations. --- Source/OpenTK/Math/Vector2.cs | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Source/OpenTK/Math/Vector2.cs b/Source/OpenTK/Math/Vector2.cs index da775bae..9ab160ee 100644 --- a/Source/OpenTK/Math/Vector2.cs +++ b/Source/OpenTK/Math/Vector2.cs @@ -187,5 +187,48 @@ namespace OpenTK.Math } #endregion + + /// + /// Returns the length of the vector. + /// + public float Length + { + get + { + return System.Math.Sqrt(this.LengthSquared); + } + } + + /// + /// Returns the square of the vector length. + /// + public float LengthSquared + { + get + { + return X * X + Y * Y; + } + } + + /// + /// Scales the Vector2 to unit length. + /// + /// The normalized version of the current vector. + public Vector2 Normalize() + { + float length = this.Length; + return new Vector2(X / length, Y / Length); + } + + /// + /// Scales the current Vector2 by the given amounts. + /// + /// The scale of the X component. + /// The scale of the Y component. + /// A new, scaled Vector2. + public Vector2 Scale(float sx, float sy) + { + return new Vector2(X * x, Y * y); + } } }