[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.
This commit is contained in:
Aaron Franke 2019-11-29 02:20:31 -05:00
parent 2dd73b1ffa
commit 0a39c7b354
No known key found for this signature in database
GPG Key ID: 40A1750B977E56BF
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 get
{ {
switch (columnIndex) switch (column)
{ {
case 0: case 0:
return Column0; return Column0;
@ -111,7 +115,7 @@ namespace Godot
} }
set set
{ {
switch (columnIndex) switch (column)
{ {
case 0: case 0:
Column0 = value; 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 get
{ {
switch (columnIndex) return this[column][row];
{
case 0:
return Column0[rowIndex];
case 1:
return Column1[rowIndex];
case 2:
return Column2[rowIndex];
default:
throw new IndexOutOfRangeException();
}
} }
set set
{ {
switch (columnIndex) Vector3 columnVector = this[column];
{ columnVector[row] = value;
case 0: this[column] = columnVector;
{
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();
}
} }
} }

View File

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

View File

@ -15,6 +15,76 @@ namespace Godot
public Basis basis; public Basis basis;
public Vector3 origin; 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() public Transform AffineInverse()
{ {
Basis basisInv = basis.Inverse(); 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 get
{ {
switch (rowIndex) switch (column)
{ {
case 0: case 0:
return x; return x;
@ -72,7 +76,7 @@ namespace Godot
} }
set set
{ {
switch (rowIndex) switch (column)
{ {
case 0: case 0:
x = value; 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 get
{ {
switch (rowIndex) return this[column][row];
{
case 0:
return x[columnIndex];
case 1:
return y[columnIndex];
case 2:
return origin[columnIndex];
default:
throw new IndexOutOfRangeException();
}
} }
set set
{ {
switch (rowIndex) Vector2 columnVector = this[column];
{ columnVector[row] = value;
case 0: this[column] = columnVector;
x[columnIndex] = value;
return;
case 1:
y[columnIndex] = value;
return;
case 2:
origin[columnIndex] = value;
return;
default:
throw new IndexOutOfRangeException();
}
} }
} }