diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index 1b4ea1c9f..d921c1227 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -276,7 +276,7 @@ public class Shape { if (x >= 0 && x < Width && y >= 0 && y < Height) { - Cells[steep ? y : x, steep ? x : y] = true; + this[int2(steep ? y : x, steep ? x : y)] = true; } error += derr; if (error >= 0.5f) diff --git a/tests/Aetheria.Shared.Tests/HullFootprintTests.cs b/tests/Aetheria.Shared.Tests/HullFootprintTests.cs index 6d36d50aa..2baa5d422 100644 --- a/tests/Aetheria.Shared.Tests/HullFootprintTests.cs +++ b/tests/Aetheria.Shared.Tests/HullFootprintTests.cs @@ -72,6 +72,33 @@ public sealed class HullFootprintTests Assert.Equal(new[] { new int2(3, 3) }, Hull(hp)); } + [Fact] + public void RefusedClickLeavesPositionWhereItWasWhenTheLastCellIsNotAtPosition() + { + var hp = Hardpoint(new int2(3, 3), new int2(1, 0)); + Assert.Equal(new[] { new int2(4, 3) }, Hull(hp)); + + Assert.False(HullFootprint.Toggle(hp.Shape, hp.Position, new int2(4, 3), out var shape, out var position)); + + Assert.Equal(new int2(3, 3), position); + Assert.Same(hp.Shape, shape); + } + + [Fact] + public void WideFootprintLaysEveryCellAtPositionAndEditsAtItsFarEnd() + { + var hp = Hardpoint(new int2(2, 2), new int2(0, 0), new int2(1, 0), new int2(2, 0), new int2(3, 0), new int2(4, 0)); + Assert.Equal(new[] { new int2(2, 2), new int2(3, 2), new int2(4, 2), new int2(5, 2), new int2(6, 2) }, Hull(hp)); + + var grown = Apply(hp, new int2(7, 2)); + Assert.Equal(new int2(2, 2), grown.Position); + Assert.Equal(new[] { new int2(2, 2), new int2(3, 2), new int2(4, 2), new int2(5, 2), new int2(6, 2), new int2(7, 2) }, Hull(grown)); + + var trimmed = Apply(hp, new int2(6, 2)); + Assert.Equal(new int2(2, 2), trimmed.Position); + Assert.Equal(new[] { new int2(2, 2), new int2(3, 2), new int2(4, 2), new int2(5, 2) }, Hull(trimmed)); + } + [Fact] public void FootprintToggleLeavesItsInputUnchanged() { diff --git a/tests/Aetheria.Shared.Tests/ShapeCacheTests.cs b/tests/Aetheria.Shared.Tests/ShapeCacheTests.cs index f1228d425..21fd6e914 100644 --- a/tests/Aetheria.Shared.Tests/ShapeCacheTests.cs +++ b/tests/Aetheria.Shared.Tests/ShapeCacheTests.cs @@ -50,4 +50,19 @@ public sealed class ShapeCacheTests Assert.False(shape[int2(1, 0)]); Assert.True(shape[int2(2, 0)]); } + + [Fact] + public void SetLineRecountsEveryCoordinateRead() + { + var shape = new Shape(4, 1); + shape[int2(0, 0)] = true; + Assert.Single(shape.Coordinates); + Assert.Equal(0f, shape.CenterOfMass.x); + + shape.SetLine(float2(0f, 0f), float2(3f, 0f)); + + Assert.Equal(4, shape.Coordinates.Length); + Assert.Equal(4, shape.AllCoordinates.Length); + Assert.Equal(1.5f, shape.CenterOfMass.x); + } }