fix FaceSpaceCenter requirement

This commit is contained in:
2022-12-05 12:04:00 +01:00
parent 4e95765d98
commit 28e6f346f0
2 changed files with 60 additions and 16 deletions

View File

@@ -30,24 +30,48 @@ namespace EscapeRoomEngine.Engine.Runtime
};
}
}
/// <summary>
/// Get the geometric center of this placement taking into account its orientation.
/// </summary>
public Vector3 GeometricCenter
{
get
{
var sizeMinusOne = size - Vector2Int.one;
var half = new Vector2(sizeMinusOne.x/2f, sizeMinusOne.y/2f);
var horizontal = new Vector3(half.x, 0, half.y);
var vertical = new Vector3(half.y, 0, -half.x);
var geometricPosition = position + new Vector3(0.5f, 0, 0.5f);
#pragma warning disable CS8524
return orientation switch
#pragma warning restore CS8524
{
Orientation.North => geometricPosition + horizontal,
Orientation.East => geometricPosition + vertical,
Orientation.South => geometricPosition - horizontal,
Orientation.West => geometricPosition - vertical
};
}
}
/// <summary>
/// Get the positions of the two back corners. The first one is just the position of the placement.
/// Get the integer positions of the two back corners. The first one is just the position of the placement.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public (Vector3Int, Vector3Int) BackCorners {
get
{
var width = size.x - 1;
var horizontal = new Vector3Int(width, 0, 0);
var vertical = new Vector3Int(0, 0, width);
#pragma warning disable CS8524
var otherCorner = orientation switch
#pragma warning restore CS8524
{
Orientation.North => position + horizontal,
Orientation.East => position - vertical,
Orientation.South => position - horizontal,
Orientation.West => position + vertical,
_ => throw new ArgumentOutOfRangeException()
Orientation.West => position + vertical
};
return (position, otherCorner);
}