fix PlaceAlongSpaceEdges requirement
This commit is contained in:
@@ -10,7 +10,7 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
/// <summary>
|
||||
/// 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>
|
||||
public Vector3Int position;
|
||||
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>
|
||||
/// 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.
|
||||
|
||||
@@ -9,22 +9,15 @@ namespace EscapeRoomEngine.Engine.Runtime.Requirements
|
||||
{
|
||||
protected override List<Placement> FilterCandidates(List<Placement> candidates, Module module, Space space)
|
||||
{
|
||||
var right = space.rrPlacement.size.x - 1;
|
||||
var top = space.rrPlacement.size.y - 1;
|
||||
var sizeMinusOne = space.rrPlacement.size - Vector2Int.one;
|
||||
|
||||
candidates.RemoveAll(candidate =>
|
||||
{
|
||||
var keep = false;
|
||||
|
||||
candidate.ForEachPosition(position =>
|
||||
{
|
||||
if (!keep)
|
||||
{
|
||||
keep = position.x == 0 || position.x == right || position.z == 0 || position.z == top;
|
||||
}
|
||||
});
|
||||
|
||||
return !keep;
|
||||
var (left, right) = candidate.BackCorners;
|
||||
return !(left.x == 0 && right.x == 0 ||
|
||||
left.z == 0 && right.z == 0 ||
|
||||
left.x == sizeMinusOne.x && right.x == sizeMinusOne.x ||
|
||||
left.z == sizeMinusOne.y && right.z == sizeMinusOne.y);
|
||||
});
|
||||
|
||||
return candidates;
|
||||
|
||||
Reference in New Issue
Block a user