fix PlaceAlongSpaceEdges requirement

This commit is contained in:
2022-12-05 10:14:00 +01:00
parent edf9ccab0b
commit 1afe589bcd
2 changed files with 29 additions and 14 deletions

View File

@@ -10,7 +10,7 @@ namespace EscapeRoomEngine.Engine.Runtime
/// <summary> /// <summary>
/// The placement position is always considered to be at <c>(0.5, 0.5)</c> relative to the placement. /// The placement position is always considered to be at <c>(0.5, 0.5)</c> relative to the placement.
/// ///
/// <example>In a placement of size <c>(1, 1)</c>, the position is at the center of the placement. In a larger placement, the position is in the center of the bottom left square meter.</example> /// <example>In a placement of size <c>(1, 1)</c>, the position is at the center of the placement. In a larger placement, the position is in the center of the bottom left square.</example>
/// </summary> /// </summary>
public Vector3Int position; public Vector3Int position;
public Vector2Int size; public Vector2Int size;
@@ -31,6 +31,28 @@ namespace EscapeRoomEngine.Engine.Runtime
} }
} }
/// <summary>
/// Get the 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);
var otherCorner = orientation switch
{
Orientation.North => position + horizontal,
Orientation.East => position - vertical,
Orientation.South => position - horizontal,
Orientation.West => position + vertical,
_ => throw new ArgumentOutOfRangeException()
};
return (position, otherCorner);
}
}
/// <summary> /// <summary>
/// Create a set with every possible combination of position and orientation of placements that fit in a given space. /// Create a set with every possible combination of position and orientation of placements that fit in a given space.
/// The size of the placements are given by this placement. /// The size of the placements are given by this placement.

View File

@@ -9,22 +9,15 @@ namespace EscapeRoomEngine.Engine.Runtime.Requirements
{ {
protected override List<Placement> FilterCandidates(List<Placement> candidates, Module module, Space space) protected override List<Placement> FilterCandidates(List<Placement> candidates, Module module, Space space)
{ {
var right = space.rrPlacement.size.x - 1; var sizeMinusOne = space.rrPlacement.size - Vector2Int.one;
var top = space.rrPlacement.size.y - 1;
candidates.RemoveAll(candidate => candidates.RemoveAll(candidate =>
{ {
var keep = false; var (left, right) = candidate.BackCorners;
return !(left.x == 0 && right.x == 0 ||
candidate.ForEachPosition(position => left.z == 0 && right.z == 0 ||
{ left.x == sizeMinusOne.x && right.x == sizeMinusOne.x ||
if (!keep) left.z == sizeMinusOne.y && right.z == sizeMinusOne.y);
{
keep = position.x == 0 || position.x == right || position.z == 0 || position.z == top;
}
});
return !keep;
}); });
return candidates; return candidates;