franz_1960's picture

Indexed accessor for Vector3

Project:The Open Toolkit library
Version:1.1.0-stable
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi,
I needed an indexed accessor to the Vector3 components, so I extended the code. Below is the SVN patch.
I'm new to OpenTK. Is there a better way to submit changes? I didn't need it right now, but for completeness' sake I will port this extension to the other vector classes if this change is accepted.
Franz

SVN patch:

Index: OpenTK/Math/Vector3.cs
===================================================================
--- OpenTK/Math/Vector3.cs	(revision 3121)
+++ OpenTK/Math/Vector3.cs	(working copy)
@@ -56,6 +56,47 @@
 
         #endregion
 
+        #region Indexed accessor
+      
+        /// <summary>
+        /// Get or set an indexed component of this vector.
+        /// </summary>
+        /// <param name="i">
+        /// The index from 0 to 2. Other values will throw an 
+        /// IndexOutOfRangeException.
+        /// </param>
+        /// <returns>
+        /// The value of the indexed component, say X for i=0, Y for i=1 etc.
+        /// </returns>
+        public float this[int i] {
+          [System.Diagnostics.DebuggerStepThrough()]
+          get {
+            if (i==0) {
+              return this.X;
+            } else if (i==1) {
+              return this.Y;
+            } else if (i==2) {
+              return this.Z;
+            } else {
+              throw new IndexOutOfRangeException();
+            }
+          }
+          [System.Diagnostics.DebuggerStepThrough()]
+          set {
+            if (i==0) {
+              this.X=value;
+            } else if (i==1) {
+              this.Y=value;
+            } else if (i==2) {
+              this.Z=value;
+            } else {
+              throw new IndexOutOfRangeException();
+            }
+          }
+        }
+
+        #endregion
+
         #region Constructors
 
         /// <summary> 

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

#1

Version:1.x-dev» 1.1.0-stable
Status:open» closed

Many thanks, this patch is included in opentk-1.1.0.