
Indexed accessor for Vector3
Posted Wednesday, 11 January, 2012 - 06:54 by franz_1960| Project: | The Open Toolkit library |
| Version: | 1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | open |
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>

