diff --git a/Assets/Engine/Runtime/Placement.cs b/Assets/Engine/Runtime/Placement.cs
index 4d0d6ba..6fe2e56 100644
--- a/Assets/Engine/Runtime/Placement.cs
+++ b/Assets/Engine/Runtime/Placement.cs
@@ -10,7 +10,7 @@ namespace EscapeRoomEngine.Engine.Runtime
///
/// The placement position is always considered to be at (0.5, 0.5) relative to the placement.
///
- /// In a placement of size (1, 1), 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.
+ /// In a placement of size (1, 1), the position is at the center of the placement. In a larger placement, the position is in the center of the bottom left square.
///
public Vector3Int position;
public Vector2Int size;
@@ -31,6 +31,28 @@ namespace EscapeRoomEngine.Engine.Runtime
}
}
+ ///
+ /// Get the positions of the two back corners. The first one is just the position of the placement.
+ ///
+ ///
+ 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);
+ }
+ }
+
///
/// 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.
diff --git a/Assets/Engine/Runtime/Requirements/PlaceAlongSpaceEdges.cs b/Assets/Engine/Runtime/Requirements/PlaceAlongSpaceEdges.cs
index 9cfa686..82bf129 100644
--- a/Assets/Engine/Runtime/Requirements/PlaceAlongSpaceEdges.cs
+++ b/Assets/Engine/Runtime/Requirements/PlaceAlongSpaceEdges.cs
@@ -9,22 +9,15 @@ namespace EscapeRoomEngine.Engine.Runtime.Requirements
{
protected override List FilterCandidates(List 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;