[Mono] Basis/Transforms Array operator comments and improvements

The behavior for Basis and Transform2D is unchanged, and Transform gets new behavior. All of the behavior is identical to GDScript's behavior. 

(cherry picked from commit 0a39c7b354)
This commit is contained in:
Aaron Franke 2019-11-29 02:20:31 -05:00 committed by Rémi Verschelde
parent ca6ac71cdf
commit 9a396a4e07
5 changed files with 109 additions and 74 deletions

View File

@ -93,11 +93,15 @@ namespace Godot
}
}
public Vector3 this[int columnIndex]
/// <summary>
/// Access whole columns in the form of Vector3.
/// </summary>
/// <param name="column">Which column vector.</param>
public Vector3 this[int column]
{
get
{
switch (columnIndex)
switch (column)
{
case 0:
return Column0;
@ -111,7 +115,7 @@ namespace Godot
}
set
{
switch (columnIndex)
switch (column)
{
case 0:
Column0 = value;
@ -128,50 +132,22 @@ namespace Godot
}
}
public real_t this[int columnIndex, int rowIndex]
/// <summary>
/// Access matrix elements in column-major order.
/// </summary>
/// <param name="column">Which column, the matrix horizontal position.</param>
/// <param name="row">Which row, the matrix vertical position.</param>
public real_t this[int column, int row]
{
get
{
switch (columnIndex)
{
case 0:
return Column0[rowIndex];
case 1:
return Column1[rowIndex];
case 2:
return Column2[rowIndex];
default:
throw new IndexOutOfRangeException();
}
return this[column][row];
}
set
{
switch (columnIndex)
{
case 0:
{
var column0 = Column0;
column0[rowIndex] = value;
Column0 = column0;
return;
}
case 1:
{
var column1 = Column1;
column1[rowIndex] = value;
Column1 = column1;
return;
}
case 2:
{
var column2 = Column2;
column2[rowIndex] = value;
Column2 = column2;
return;
}
default:
throw new IndexOutOfRangeException();
}
Vector3 columnVector = this[column];
columnVector[row] = value;
this[column] = columnVector;
}
}

View File

@ -264,7 +264,8 @@ namespace Godot
instanceIndex++;
toIndex++;
}
} else
}
else
{
while (true)
{

View File

@ -15,6 +15,76 @@ namespace Godot
public Basis basis;
public Vector3 origin;
/// <summary>
/// Access whole columns in the form of Vector3. The fourth column is the origin vector.
/// </summary>
/// <param name="column">Which column vector.</param>
public Vector3 this[int column]
{
get
{
switch (column)
{
case 0:
return basis.Column0;
case 1:
return basis.Column1;
case 2:
return basis.Column2;
case 3:
return origin;
default:
throw new IndexOutOfRangeException();
}
}
set
{
switch (column)
{
case 0:
basis.Column0 = value;
return;
case 1:
basis.Column1 = value;
return;
case 2:
basis.Column2 = value;
return;
case 3:
origin = value;
return;
default:
throw new IndexOutOfRangeException();
}
}
}
/// <summary>
/// Access matrix elements in column-major order. The fourth column is the origin vector.
/// </summary>
/// <param name="column">Which column, the matrix horizontal position.</param>
/// <param name="row">Which row, the matrix vertical position.</param>
public real_t this[int column, int row]
{
get
{
if (column == 3)
{
return origin[row];
}
return basis[column, row];
}
set
{
if (column == 3)
{
origin[row] = value;
return;
}
basis[column, row] = value;
}
}
public Transform AffineInverse()
{
Basis basisInv = basis.Inverse();

View File

@ -54,11 +54,15 @@ namespace Godot
}
}
public Vector2 this[int rowIndex]
/// <summary>
/// Access whole columns in the form of Vector2. The third column is the origin vector.
/// </summary>
/// <param name="column">Which column vector.</param>
public Vector2 this[int column]
{
get
{
switch (rowIndex)
switch (column)
{
case 0:
return x;
@ -72,7 +76,7 @@ namespace Godot
}
set
{
switch (rowIndex)
switch (column)
{
case 0:
x = value;
@ -89,38 +93,22 @@ namespace Godot
}
}
public real_t this[int rowIndex, int columnIndex]
/// <summary>
/// Access matrix elements in column-major order. The third column is the origin vector.
/// </summary>
/// <param name="column">Which column, the matrix horizontal position.</param>
/// <param name="row">Which row, the matrix vertical position.</param>
public real_t this[int column, int row]
{
get
{
switch (rowIndex)
{
case 0:
return x[columnIndex];
case 1:
return y[columnIndex];
case 2:
return origin[columnIndex];
default:
throw new IndexOutOfRangeException();
}
return this[column][row];
}
set
{
switch (rowIndex)
{
case 0:
x[columnIndex] = value;
return;
case 1:
y[columnIndex] = value;
return;
case 2:
origin[columnIndex] = value;
return;
default:
throw new IndexOutOfRangeException();
}
Vector2 columnVector = this[column];
columnVector[row] = value;
this[column] = columnVector;
}
}