Shape.SetLine writes through the indexer so it invalidates the caches; footprint tests pin refusal Position and a wide shape

Builds: yes (Shared-only; verified on Yggdrasil in the report).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-17 14:33:41 +02:00
commit 1349953500
3 changed files with 43 additions and 1 deletions

View file

@ -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)

View file

@ -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()
{

View file

@ -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);
}
}