From 65c6b29918dd610e6fbc6ba0c69cbc6da56e698b Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Tue, 6 Oct 2009 09:42:21 +0000 Subject: [PATCH] Added vector overloads to Multiply and Divide methods. Renamed Sub to Subtract, Mult to Multiply and Div to Divide (reason: conform with the class library design guidelines). Obsoleted instance Add, Sub, Mult and Div methods in favor of static ones (reason: reduce API bloat, they are completely redudant). Improved documentation for new methods. --- Source/OpenTK/Math/Vector2.cs | 198 +++++++++++++++++++++++++++----- Source/OpenTK/Math/Vector2d.cs | 197 +++++++++++++++++++++++++++----- Source/OpenTK/Math/Vector3.cs | 199 +++++++++++++++++++++++++++----- Source/OpenTK/Math/Vector3d.cs | 199 +++++++++++++++++++++++++++----- Source/OpenTK/Math/Vector4.cs | 195 ++++++++++++++++++++++++++------ Source/OpenTK/Math/Vector4d.cs | 201 +++++++++++++++++++++++++++------ 6 files changed, 1008 insertions(+), 181 deletions(-) diff --git a/Source/OpenTK/Math/Vector2.cs b/Source/OpenTK/Math/Vector2.cs index f2fbc672..dcf492fe 100644 --- a/Source/OpenTK/Math/Vector2.cs +++ b/Source/OpenTK/Math/Vector2.cs @@ -104,6 +104,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Add() method instead.")] public void Add(Vector2 right) { this.X += right.X; @@ -113,6 +114,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Add() method instead.")] public void Add(ref Vector2 right) { this.X += right.X; @@ -125,6 +127,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Subtract() method instead.")] public void Sub(Vector2 right) { this.X -= right.X; @@ -134,6 +137,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Subtract() method instead.")] public void Sub(ref Vector2 right) { this.X -= right.X; @@ -144,9 +148,9 @@ namespace OpenTK #region public void Mult() - [Obsolete] /// Multiply this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Multiply() method instead.")] public void Mult(float f) { this.X *= f; @@ -159,6 +163,7 @@ namespace OpenTK /// Divide this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Divide() method instead.")] public void Div(float f) { float mult = 1.0f / f; @@ -350,34 +355,7 @@ namespace OpenTK #endregion - #region Add - - /// - /// Add the specified instances - /// - /// First operand - /// Second operand - /// Result of addition - public static Vector2 Add(Vector2 a, Vector2 b) - { - a.X += b.X; - a.Y += b.Y; - return a; - } - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static void Add(ref Vector2 a, ref Vector2 b, out Vector2 result) - { - result.X = a.X + b.X; - result.Y = a.Y + b.Y; - } - - #endregion + #region Obsolete #region Sub @@ -387,6 +365,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static Vector2 Sub(Vector2 a, Vector2 b) { a.X -= b.X; @@ -400,6 +379,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static void Sub(ref Vector2 a, ref Vector2 b, out Vector2 result) { result.X = a.X - b.X; @@ -416,6 +396,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static Vector2 Mult(Vector2 a, float f) { a.X *= f; @@ -429,6 +410,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static void Mult(ref Vector2 a, float f, out Vector2 result) { result.X = a.X * f; @@ -445,6 +427,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static Vector2 Div(Vector2 a, float f) { float mult = 1.0f / f; @@ -459,6 +442,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static void Div(ref Vector2 a, float f, out Vector2 result) { float mult = 1.0f / f; @@ -468,6 +452,162 @@ namespace OpenTK #endregion + #endregion + + #region Add + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static Vector2 Add(Vector2 a, Vector2 b) + { + Add(ref a, ref b, out a); + return a; + } + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static void Add(ref Vector2 a, ref Vector2 b, out Vector2 result) + { + result = new Vector2(a.X + b.X, a.Y + b.Y); + } + + #endregion + + #region Subtract + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static Vector2 Subtract(Vector2 a, Vector2 b) + { + Subtract(ref a, ref b, out a); + return a; + } + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static void Subtract(ref Vector2 a, ref Vector2 b, out Vector2 result) + { + result = new Vector2(a.X - b.X, a.Y - b.Y); + } + + #endregion + + #region Multiply + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector2 Multiply(Vector2 vector, float scale) + { + Multiply(ref vector, scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector2 vector, float scale, out Vector2 result) + { + result = new Vector2(vector.X * scale, vector.Y * scale); + } + + /// + /// Multiplies a vector by the components a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector2 Multiply(Vector2 vector, Vector2 scale) + { + Multiply(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector2 vector, ref Vector2 scale, out Vector2 result) + { + result = new Vector2(vector.X * scale.X, vector.Y * scale.Y); + } + + #endregion + + #region Divide + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector2 Divide(Vector2 vector, float scale) + { + Divide(ref vector, scale, out vector); + return vector; + } + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector2 vector, float scale, out Vector2 result) + { + Multiply(ref vector, 1 / scale, out result); + } + + /// + /// Divides a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector2 Divide(Vector2 vector, Vector2 scale) + { + Divide(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Divide a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector2 vector, ref Vector2 scale, out Vector2 result) + { + result = new Vector2(vector.X / scale.X, vector.Y / scale.Y); + } + + #endregion + #region ComponentMin /// diff --git a/Source/OpenTK/Math/Vector2d.cs b/Source/OpenTK/Math/Vector2d.cs index 1e799cf8..51cdd719 100644 --- a/Source/OpenTK/Math/Vector2d.cs +++ b/Source/OpenTK/Math/Vector2d.cs @@ -88,6 +88,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Add() method instead.")] public void Add(Vector2d right) { this.X += right.X; @@ -97,6 +98,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Add() method instead.")] public void Add(ref Vector2d right) { this.X += right.X; @@ -109,6 +111,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Subtract() method instead.")] public void Sub(Vector2d right) { this.X -= right.X; @@ -118,6 +121,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Subtract() method instead.")] public void Sub(ref Vector2d right) { this.X -= right.X; @@ -130,6 +134,7 @@ namespace OpenTK /// Multiply this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Multiply() method instead.")] public void Mult(double f) { this.X *= f; @@ -142,6 +147,7 @@ namespace OpenTK /// Divide this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Divide() method instead.")] public void Div(double f) { double mult = 1.0 / f; @@ -267,34 +273,7 @@ namespace OpenTK #region Static - #region Add - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static Vector2d Add(Vector2d a, Vector2d b) - { - a.X += b.X; - a.Y += b.Y; - return a; - } - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static void Add(ref Vector2d a, ref Vector2d b, out Vector2d result) - { - result.X = a.X + b.X; - result.Y = a.Y + b.Y; - } - - #endregion + #region Obsolete #region Sub @@ -304,6 +283,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static Vector2d Sub(Vector2d a, Vector2d b) { a.X -= b.X; @@ -317,6 +297,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static void Sub(ref Vector2d a, ref Vector2d b, out Vector2d result) { result.X = a.X - b.X; @@ -333,6 +314,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static Vector2d Mult(Vector2d a, double d) { a.X *= d; @@ -346,6 +328,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static void Mult(ref Vector2d a, double d, out Vector2d result) { result.X = a.X * d; @@ -362,6 +345,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static Vector2d Div(Vector2d a, double d) { double mult = 1.0 / d; @@ -376,6 +360,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static void Div(ref Vector2d a, double d, out Vector2d result) { double mult = 1.0 / d; @@ -385,6 +370,162 @@ namespace OpenTK #endregion + #endregion + + #region Add + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static Vector2d Add(Vector2d a, Vector2d b) + { + Add(ref a, ref b, out a); + return a; + } + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static void Add(ref Vector2d a, ref Vector2d b, out Vector2d result) + { + result = new Vector2d(a.X + b.X, a.Y + b.Y); + } + + #endregion + + #region Subtract + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static Vector2d Subtract(Vector2d a, Vector2d b) + { + Subtract(ref a, ref b, out a); + return a; + } + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static void Subtract(ref Vector2d a, ref Vector2d b, out Vector2d result) + { + result = new Vector2d(a.X - b.X, a.Y - b.Y); + } + + #endregion + + #region Multiply + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector2d Multiply(Vector2d vector, double scale) + { + Multiply(ref vector, scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector2d vector, double scale, out Vector2d result) + { + result = new Vector2d(vector.X * scale, vector.Y * scale); + } + + /// + /// Multiplies a vector by the components a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector2d Multiply(Vector2d vector, Vector2d scale) + { + Multiply(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector2d vector, ref Vector2d scale, out Vector2d result) + { + result = new Vector2d(vector.X * scale.X, vector.Y * scale.Y); + } + + #endregion + + #region Divide + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector2d Divide(Vector2d vector, double scale) + { + Divide(ref vector, scale, out vector); + return vector; + } + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector2d vector, double scale, out Vector2d result) + { + Multiply(ref vector, 1 / scale, out result); + } + + /// + /// Divides a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector2d Divide(Vector2d vector, Vector2d scale) + { + Divide(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Divide a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector2d vector, ref Vector2d scale, out Vector2d result) + { + result = new Vector2d(vector.X / scale.X, vector.Y / scale.Y); + } + + #endregion + #region Min /// diff --git a/Source/OpenTK/Math/Vector3.cs b/Source/OpenTK/Math/Vector3.cs index 819fa2de..fe6f55e1 100644 --- a/Source/OpenTK/Math/Vector3.cs +++ b/Source/OpenTK/Math/Vector3.cs @@ -114,6 +114,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Add() method instead.")] public void Add(Vector3 right) { this.X += right.X; @@ -124,6 +125,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Add() method instead.")] public void Add(ref Vector3 right) { this.X += right.X; @@ -137,6 +139,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Subtract() method instead.")] public void Sub(Vector3 right) { this.X -= right.X; @@ -147,6 +150,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Subtract() method instead.")] public void Sub(ref Vector3 right) { this.X -= right.X; @@ -160,6 +164,7 @@ namespace OpenTK /// Multiply this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Multiply() method instead.")] public void Mult(float f) { this.X *= f; @@ -173,6 +178,7 @@ namespace OpenTK /// Divide this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Divide() method instead.")] public void Div(float f) { float mult = 1.0f / f; @@ -346,36 +352,7 @@ namespace OpenTK #endregion - #region Add - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static Vector3 Add(Vector3 a, Vector3 b) - { - a.X += b.X; - a.Y += b.Y; - a.Z += b.Z; - return a; - } - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static void Add(ref Vector3 a, ref Vector3 b, out Vector3 result) - { - result.X = a.X + b.X; - result.Y = a.Y + b.Y; - result.Z = a.Z + b.Z; - } - - #endregion + #region Obsolete #region Sub @@ -385,6 +362,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static Vector3 Sub(Vector3 a, Vector3 b) { a.X -= b.X; @@ -399,6 +377,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static void Sub(ref Vector3 a, ref Vector3 b, out Vector3 result) { result.X = a.X - b.X; @@ -416,6 +395,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static Vector3 Mult(Vector3 a, float f) { a.X *= f; @@ -430,6 +410,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static void Mult(ref Vector3 a, float f, out Vector3 result) { result.X = a.X * f; @@ -447,6 +428,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static Vector3 Div(Vector3 a, float f) { float mult = 1.0f / f; @@ -462,6 +444,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static void Div(ref Vector3 a, float f, out Vector3 result) { float mult = 1.0f / f; @@ -472,6 +455,162 @@ namespace OpenTK #endregion + #endregion + + #region Add + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static Vector3 Add(Vector3 a, Vector3 b) + { + Add(ref a, ref b, out a); + return a; + } + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static void Add(ref Vector3 a, ref Vector3 b, out Vector3 result) + { + result = new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z); + } + + #endregion + + #region Subtract + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static Vector3 Subtract(Vector3 a, Vector3 b) + { + Subtract(ref a, ref b, out a); + return a; + } + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static void Subtract(ref Vector3 a, ref Vector3 b, out Vector3 result) + { + result = new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z); + } + + #endregion + + #region Multiply + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector3 Multiply(Vector3 vector, float scale) + { + Multiply(ref vector, scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector3 vector, float scale, out Vector3 result) + { + result = new Vector3(vector.X * scale, vector.Y * scale, vector.Z * scale); + } + + /// + /// Multiplies a vector by the components a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector3 Multiply(Vector3 vector, Vector3 scale) + { + Multiply(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector3 vector, ref Vector3 scale, out Vector3 result) + { + result = new Vector3(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z); + } + + #endregion + + #region Divide + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector3 Divide(Vector3 vector, float scale) + { + Divide(ref vector, scale, out vector); + return vector; + } + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector3 vector, float scale, out Vector3 result) + { + Multiply(ref vector, 1 / scale, out result); + } + + /// + /// Divides a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector3 Divide(Vector3 vector, Vector3 scale) + { + Divide(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Divide a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector3 vector, ref Vector3 scale, out Vector3 result) + { + result = new Vector3(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z); + } + + #endregion + #region ComponentMin /// diff --git a/Source/OpenTK/Math/Vector3d.cs b/Source/OpenTK/Math/Vector3d.cs index 66e33b82..7ba673b7 100644 --- a/Source/OpenTK/Math/Vector3d.cs +++ b/Source/OpenTK/Math/Vector3d.cs @@ -113,6 +113,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Add() method instead.")] public void Add(Vector3d right) { this.X += right.X; @@ -123,6 +124,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Add() method instead.")] public void Add(ref Vector3d right) { this.X += right.X; @@ -136,6 +138,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Subtract() method instead.")] public void Sub(Vector3d right) { this.X -= right.X; @@ -146,6 +149,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Subtract() method instead.")] public void Sub(ref Vector3d right) { this.X -= right.X; @@ -159,6 +163,7 @@ namespace OpenTK /// Multiply this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Multiply() method instead.")] public void Mult(double f) { this.X *= f; @@ -172,6 +177,7 @@ namespace OpenTK /// Divide this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Divide() method instead.")] public void Div(double f) { double mult = 1.0 / f; @@ -345,36 +351,7 @@ namespace OpenTK #endregion - #region Add - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static Vector3d Add(Vector3d a, Vector3d b) - { - a.X += b.X; - a.Y += b.Y; - a.Z += b.Z; - return a; - } - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static void Add(ref Vector3d a, ref Vector3d b, out Vector3d result) - { - result.X = a.X + b.X; - result.Y = a.Y + b.Y; - result.Z = a.Z + b.Z; - } - - #endregion + #region Obsolete #region Sub @@ -384,6 +361,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static Vector3d Sub(Vector3d a, Vector3d b) { a.X -= b.X; @@ -398,6 +376,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static void Sub(ref Vector3d a, ref Vector3d b, out Vector3d result) { result.X = a.X - b.X; @@ -415,6 +394,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static Vector3d Mult(Vector3d a, double f) { a.X *= f; @@ -429,6 +409,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static void Mult(ref Vector3d a, double f, out Vector3d result) { result.X = a.X * f; @@ -446,6 +427,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static Vector3d Div(Vector3d a, double f) { double mult = 1.0f / f; @@ -461,6 +443,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static void Div(ref Vector3d a, double f, out Vector3d result) { double mult = 1.0f / f; @@ -471,6 +454,162 @@ namespace OpenTK #endregion + #endregion + + #region Add + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static Vector3d Add(Vector3d a, Vector3d b) + { + Add(ref a, ref b, out a); + return a; + } + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static void Add(ref Vector3d a, ref Vector3d b, out Vector3d result) + { + result = new Vector3d(a.X + b.X, a.Y + b.Y, a.Z + b.Z); + } + + #endregion + + #region Subtract + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static Vector3d Subtract(Vector3d a, Vector3d b) + { + Subtract(ref a, ref b, out a); + return a; + } + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static void Subtract(ref Vector3d a, ref Vector3d b, out Vector3d result) + { + result = new Vector3d(a.X - b.X, a.Y - b.Y, a.Z - b.Z); + } + + #endregion + + #region Multiply + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector3d Multiply(Vector3d vector, double scale) + { + Multiply(ref vector, scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector3d vector, double scale, out Vector3d result) + { + result = new Vector3d(vector.X * scale, vector.Y * scale, vector.Z * scale); + } + + /// + /// Multiplies a vector by the components a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector3d Multiply(Vector3d vector, Vector3d scale) + { + Multiply(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector3d vector, ref Vector3d scale, out Vector3d result) + { + result = new Vector3d(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z); + } + + #endregion + + #region Divide + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector3d Divide(Vector3d vector, double scale) + { + Divide(ref vector, scale, out vector); + return vector; + } + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector3d vector, double scale, out Vector3d result) + { + Multiply(ref vector, 1 / scale, out result); + } + + /// + /// Divides a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector3d Divide(Vector3d vector, Vector3d scale) + { + Divide(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Divide a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector3d vector, ref Vector3d scale, out Vector3d result) + { + result = new Vector3d(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z); + } + + #endregion + #region ComponentMin /// diff --git a/Source/OpenTK/Math/Vector4.cs b/Source/OpenTK/Math/Vector4.cs index 0183c217..8191d99a 100644 --- a/Source/OpenTK/Math/Vector4.cs +++ b/Source/OpenTK/Math/Vector4.cs @@ -170,6 +170,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Add() method instead.")] public void Add(Vector4 right) { this.X += right.X; @@ -181,6 +182,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Add() method instead.")] public void Add(ref Vector4 right) { this.X += right.X; @@ -195,6 +197,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Subtract() method instead.")] public void Sub(Vector4 right) { this.X -= right.X; @@ -206,6 +209,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Subtract() method instead.")] public void Sub(ref Vector4 right) { this.X -= right.X; @@ -220,6 +224,7 @@ namespace OpenTK /// Multiply this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Multiply() method instead.")] public void Mult(float f) { this.X *= f; @@ -234,6 +239,7 @@ namespace OpenTK /// Divide this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Divide() method instead.")] public void Div(float f) { float mult = 1.0f / f; @@ -380,38 +386,7 @@ namespace OpenTK #region Static - #region Add - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static Vector4 Add(Vector4 a, Vector4 b) - { - a.X += b.X; - a.Y += b.Y; - a.Z += b.Z; - a.W += b.W; - return a; - } - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static void Add(ref Vector4 a, ref Vector4 b, out Vector4 result) - { - result.X = a.X + b.X; - result.Y = a.Y + b.Y; - result.Z = a.Z + b.Z; - result.W = a.W + b.W; - } - - #endregion + #region Obsolete #region Sub @@ -514,6 +489,162 @@ namespace OpenTK #endregion + #endregion + + #region Add + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static Vector4 Add(Vector4 a, Vector4 b) + { + Add(ref a, ref b, out a); + return a; + } + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static void Add(ref Vector4 a, ref Vector4 b, out Vector4 result) + { + result = new Vector4(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W); + } + + #endregion + + #region Subtract + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static Vector4 Subtract(Vector4 a, Vector4 b) + { + Subtract(ref a, ref b, out a); + return a; + } + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static void Subtract(ref Vector4 a, ref Vector4 b, out Vector4 result) + { + result = new Vector4(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W); + } + + #endregion + + #region Multiply + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector4 Multiply(Vector4 vector, float scale) + { + Multiply(ref vector, scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector4 vector, float scale, out Vector4 result) + { + result = new Vector4(vector.X * scale, vector.Y * scale, vector.Z * scale, vector.W * scale); + } + + /// + /// Multiplies a vector by the components a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector4 Multiply(Vector4 vector, Vector4 scale) + { + Multiply(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector4 vector, ref Vector4 scale, out Vector4 result) + { + result = new Vector4(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z, vector.W * scale.W); + } + + #endregion + + #region Divide + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector4 Divide(Vector4 vector, float scale) + { + Divide(ref vector, scale, out vector); + return vector; + } + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector4 vector, float scale, out Vector4 result) + { + Multiply(ref vector, 1 / scale, out result); + } + + /// + /// Divides a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector4 Divide(Vector4 vector, Vector4 scale) + { + Divide(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Divide a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector4 vector, ref Vector4 scale, out Vector4 result) + { + result = new Vector4(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z, vector.W / scale.W); + } + + #endregion + #region Min /// diff --git a/Source/OpenTK/Math/Vector4d.cs b/Source/OpenTK/Math/Vector4d.cs index 9edea219..ee018da8 100644 --- a/Source/OpenTK/Math/Vector4d.cs +++ b/Source/OpenTK/Math/Vector4d.cs @@ -168,6 +168,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Add() method instead.")] public void Add(Vector4d right) { this.X += right.X; @@ -179,6 +180,7 @@ namespace OpenTK /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Add() method instead.")] public void Add(ref Vector4d right) { this.X += right.X; @@ -193,6 +195,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. + [Obsolete("Use static Subtract() method instead.")] public void Sub(Vector4d right) { this.X -= right.X; @@ -204,6 +207,7 @@ namespace OpenTK /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] + [Obsolete("Use static Subtract() method instead.")] public void Sub(ref Vector4d right) { this.X -= right.X; @@ -218,6 +222,7 @@ namespace OpenTK /// Multiply this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Multiply() method instead.")] public void Mult(double f) { this.X *= f; @@ -232,6 +237,7 @@ namespace OpenTK /// Divide this instance by a scalar. /// Scalar operand. + [Obsolete("Use static Divide() method instead.")] public void Div(double f) { double mult = 1.0 / f; @@ -377,38 +383,7 @@ namespace OpenTK #region Static - #region Add - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static Vector4d Add(Vector4d a, Vector4d b) - { - a.X += b.X; - a.Y += b.Y; - a.Z += b.Z; - a.W += b.W; - return a; - } - - /// - /// Add two Vectors - /// - /// First operand - /// Second operand - /// Result of addition - public static void Add(ref Vector4d a, ref Vector4d b, out Vector4d result) - { - result.X = a.X + b.X; - result.Y = a.Y + b.Y; - result.Z = a.Z + b.Z; - result.W = a.W + b.W; - } - - #endregion + #region Obsolete #region Sub @@ -418,6 +393,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static Vector4d Sub(Vector4d a, Vector4d b) { a.X -= b.X; @@ -433,6 +409,7 @@ namespace OpenTK /// First operand /// Second operand /// Result of subtraction + [Obsolete("Use static Subtract() method instead.")] public static void Sub(ref Vector4d a, ref Vector4d b, out Vector4d result) { result.X = a.X - b.X; @@ -451,6 +428,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static Vector4d Mult(Vector4d a, double f) { a.X *= f; @@ -466,6 +444,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the multiplication + [Obsolete("Use static Multiply() method instead.")] public static void Mult(ref Vector4d a, double f, out Vector4d result) { result.X = a.X * f; @@ -484,6 +463,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static Vector4d Div(Vector4d a, double f) { double mult = 1.0f / f; @@ -500,6 +480,7 @@ namespace OpenTK /// Vector operand /// Scalar operand /// Result of the division + [Obsolete("Use static Divide() method instead.")] public static void Div(ref Vector4d a, double f, out Vector4d result) { double mult = 1.0f / f; @@ -511,6 +492,162 @@ namespace OpenTK #endregion + #endregion + + #region Add + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static Vector4d Add(Vector4d a, Vector4d b) + { + Add(ref a, ref b, out a); + return a; + } + + /// + /// Adds two vectors. + /// + /// Left operand. + /// Right operand. + /// Result of operation. + public static void Add(ref Vector4d a, ref Vector4d b, out Vector4d result) + { + result = new Vector4d(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W); + } + + #endregion + + #region Subtract + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static Vector4d Subtract(Vector4d a, Vector4d b) + { + Subtract(ref a, ref b, out a); + return a; + } + + /// + /// Subtract one Vector from another + /// + /// First operand + /// Second operand + /// Result of subtraction + public static void Subtract(ref Vector4d a, ref Vector4d b, out Vector4d result) + { + result = new Vector4d(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W); + } + + #endregion + + #region Multiply + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector4d Multiply(Vector4d vector, double scale) + { + Multiply(ref vector, scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector4d vector, double scale, out Vector4d result) + { + result = new Vector4d(vector.X * scale, vector.Y * scale, vector.Z * scale, vector.W * scale); + } + + /// + /// Multiplies a vector by the components a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector4d Multiply(Vector4d vector, Vector4d scale) + { + Multiply(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Multiplies a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Multiply(ref Vector4d vector, ref Vector4d scale, out Vector4d result) + { + result = new Vector4d(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z, vector.W * scale.W); + } + + #endregion + + #region Divide + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector4d Divide(Vector4d vector, double scale) + { + Divide(ref vector, scale, out vector); + return vector; + } + + /// + /// Divides a vector by a scalar. + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector4d vector, double scale, out Vector4d result) + { + Multiply(ref vector, 1 / scale, out result); + } + + /// + /// Divides a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static Vector4d Divide(Vector4d vector, Vector4d scale) + { + Divide(ref vector, ref scale, out vector); + return vector; + } + + /// + /// Divide a vector by the components of a vector (scale). + /// + /// Left operand. + /// Right operand. + /// Result of the operation. + public static void Divide(ref Vector4d vector, ref Vector4d scale, out Vector4d result) + { + result = new Vector4d(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z, vector.W / scale.W); + } + + #endregion + #region Min ///