From 1939bc789da44d635a525dfd8e37634bacbb1d00 Mon Sep 17 00:00:00 2001 From: Andy Korth Date: Thu, 3 Jan 2013 10:39:15 -0600 Subject: [PATCH] Added index getters and settors for Vector and Matrix classes --- Source/OpenTK/Math/Matrix4.cs | 18 ++++++++++++++++++ Source/OpenTK/Math/Matrix4d.cs | 18 ++++++++++++++++++ Source/OpenTK/Math/Vector2.cs | 15 +++++++++++++++ Source/OpenTK/Math/Vector2d.cs | 15 +++++++++++++++ Source/OpenTK/Math/Vector3.cs | 18 ++++++++++++++++++ Source/OpenTK/Math/Vector3d.cs | 17 +++++++++++++++++ Source/OpenTK/Math/Vector4.cs | 19 +++++++++++++++++++ Source/OpenTK/Math/Vector4d.cs | 19 +++++++++++++++++++ 8 files changed, 139 insertions(+) diff --git a/Source/OpenTK/Math/Matrix4.cs b/Source/OpenTK/Math/Matrix4.cs index 45011f6d..4a77dee4 100644 --- a/Source/OpenTK/Math/Matrix4.cs +++ b/Source/OpenTK/Math/Matrix4.cs @@ -114,6 +114,24 @@ namespace OpenTK #region Properties + /// + /// Gets or sets the value at a specified row and column. + /// + public float this[int rowIndex, int columnIndex] { get{ + if(rowIndex == 0) return Row0[columnIndex]; + else if(rowIndex == 1) return Row1[columnIndex]; + else if(rowIndex == 2) return Row2[columnIndex]; + else if(rowIndex == 3) return Row3[columnIndex]; + throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } set{ + if(rowIndex == 0) Row0[columnIndex] = value; + else if(rowIndex == 1) Row1[columnIndex] = value; + else if(rowIndex == 2) Row2[columnIndex] = value; + else if(rowIndex == 3) Row3[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } + /// /// The determinant of this matrix /// diff --git a/Source/OpenTK/Math/Matrix4d.cs b/Source/OpenTK/Math/Matrix4d.cs index f8b6e7b3..7653f016 100644 --- a/Source/OpenTK/Math/Matrix4d.cs +++ b/Source/OpenTK/Math/Matrix4d.cs @@ -114,6 +114,24 @@ namespace OpenTK #region Properties + /// + /// Gets or sets the value at a specified row and column. + /// + public double this[int rowIndex, int columnIndex] { get{ + if(rowIndex == 0) return Row0[columnIndex]; + else if(rowIndex == 1) return Row1[columnIndex]; + else if(rowIndex == 2) return Row2[columnIndex]; + else if(rowIndex == 3) return Row3[columnIndex]; + throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } set{ + if(rowIndex == 0) Row0[columnIndex] = value; + else if(rowIndex == 1) Row1[columnIndex] = value; + else if(rowIndex == 2) Row2[columnIndex] = value; + else if(rowIndex == 3) Row3[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } + /// /// The determinant of this matrix /// diff --git a/Source/OpenTK/Math/Vector2.cs b/Source/OpenTK/Math/Vector2.cs index 9b232069..df5a86ac 100644 --- a/Source/OpenTK/Math/Vector2.cs +++ b/Source/OpenTK/Math/Vector2.cs @@ -108,6 +108,21 @@ namespace OpenTK #region Public Members + /// + /// Gets or sets the value at the index of the Vector. + /// + public float this[int index] { + get{ + if(index == 0) return X; + else if(index == 1) return Y; + throw new IndexOutOfRangeException("You tried to access this vector at index: " + index); + } set{ + if(index == 0) X = value; + else if(index == 1) Y = value; + throw new IndexOutOfRangeException("You tried to set this vector at index: " + index); + } + } + #region Instance #region public void Add() diff --git a/Source/OpenTK/Math/Vector2d.cs b/Source/OpenTK/Math/Vector2d.cs index 6da4b78f..9e3c557f 100644 --- a/Source/OpenTK/Math/Vector2d.cs +++ b/Source/OpenTK/Math/Vector2d.cs @@ -92,6 +92,21 @@ namespace OpenTK #region Public Members + /// + /// Gets or sets the value at the index of the Vector. + /// + public double this[int index] { + get{ + if(index == 0) return X; + else if(index == 1) return Y; + throw new IndexOutOfRangeException("You tried to access this vector at index: " + index); + } set{ + if(index == 0) X = value; + else if(index == 1) Y = value; + throw new IndexOutOfRangeException("You tried to set this vector at index: " + index); + } + } + #region Instance #region public void Add() diff --git a/Source/OpenTK/Math/Vector3.cs b/Source/OpenTK/Math/Vector3.cs index 75e1573d..4470b884 100644 --- a/Source/OpenTK/Math/Vector3.cs +++ b/Source/OpenTK/Math/Vector3.cs @@ -119,6 +119,24 @@ namespace OpenTK #region Public Members + + /// + /// Gets or sets the value at the index of the Vector. + /// + public float this[int index] { + get{ + if(index == 0) return X; + else if(index == 1) return Y; + else if(index == 2) return Z; + throw new IndexOutOfRangeException("You tried to access this vector at index: " + index); + } set{ + if(index == 0) X = value; + else if(index == 1) Y = value; + else if(index == 2) Z = value; + throw new IndexOutOfRangeException("You tried to set this vector at index: " + index); + } + } + #region Instance #region public void Add() diff --git a/Source/OpenTK/Math/Vector3d.cs b/Source/OpenTK/Math/Vector3d.cs index 264c126e..f269cf18 100644 --- a/Source/OpenTK/Math/Vector3d.cs +++ b/Source/OpenTK/Math/Vector3d.cs @@ -118,6 +118,23 @@ namespace OpenTK #region Public Members + /// + /// Gets or sets the value at the index of the Vector. + /// + public double this[int index] { + get{ + if(index == 0) return X; + else if(index == 1) return Y; + else if(index == 2) return Z; + throw new IndexOutOfRangeException("You tried to access this vector at index: " + index); + } set{ + if(index == 0) X = value; + else if(index == 1) Y = value; + else if(index == 2) Z = value; + throw new IndexOutOfRangeException("You tried to set this vector at index: " + index); + } + } + #region Instance #region public void Add() diff --git a/Source/OpenTK/Math/Vector4.cs b/Source/OpenTK/Math/Vector4.cs index b2c40e73..7bf41bd8 100644 --- a/Source/OpenTK/Math/Vector4.cs +++ b/Source/OpenTK/Math/Vector4.cs @@ -178,6 +178,25 @@ namespace OpenTK #region Public Members + /// + /// Gets or sets the value at the index of the Vector. + /// + public float this[int index] { + get{ + if(index == 0) return X; + else if(index == 1) return Y; + else if(index == 2) return Z; + else if(index == 3) return W; + throw new IndexOutOfRangeException("You tried to access this vector at index: " + index); + } set{ + if(index == 0) X = value; + else if(index == 1) Y = value; + else if(index == 2) Z = value; + else if(index == 3) W = value; + throw new IndexOutOfRangeException("You tried to set this vector at index: " + index); + } + } + #region Instance #region public void Add() diff --git a/Source/OpenTK/Math/Vector4d.cs b/Source/OpenTK/Math/Vector4d.cs index aa507d6a..10eb9770 100644 --- a/Source/OpenTK/Math/Vector4d.cs +++ b/Source/OpenTK/Math/Vector4d.cs @@ -175,6 +175,25 @@ namespace OpenTK #endregion #region Public Members + + /// + /// Gets or sets the value at the index of the Vector. + /// + public double this[int index] { + get{ + if(index == 0) return X; + else if(index == 1) return Y; + else if(index == 2) return Z; + else if(index == 3) return W; + throw new IndexOutOfRangeException("You tried to access this vector at index: " + index); + } set{ + if(index == 0) X = value; + else if(index == 1) Y = value; + else if(index == 2) Z = value; + else if(index == 3) W = value; + throw new IndexOutOfRangeException("You tried to set this vector at index: " + index); + } + } #region Instance