fix dot contamination
This commit is contained in:
parent
6cafe3ac46
commit
99fd7ab61a
3 changed files with 215 additions and 29 deletions
|
|
@ -90,5 +90,73 @@ public static class BrailleCanvasTests
|
|||
Assert.Equal(20, sx1);
|
||||
Assert.Equal(20, sy1);
|
||||
});
|
||||
|
||||
runner.Add("BrailleCanvas: Dot Contamination Prevention", () =>
|
||||
{
|
||||
var canvas = new BrailleCanvas(1, 1);
|
||||
canvas.Clear(ColorRgb.Background);
|
||||
|
||||
// 1. Grid dot at (0, 0)
|
||||
canvas.SetPixel(0, 0, ColorRgb.GridLine, CanvasLayer.Grid);
|
||||
|
||||
// Verify grid alone produces dot 0 in GridLine color
|
||||
var (chGrid, fgGrid, _) = canvas.GetCell(0, 0);
|
||||
Assert.Equal(ColorRgb.GridLine, fgGrid);
|
||||
Assert.Equal((char)(0x2800 | 0x01), chGrid);
|
||||
|
||||
// 2. Add Curve dot at (1, 3) in Cyan
|
||||
canvas.SetPixel(1, 3, ColorRgb.Cyan, CanvasLayer.Curve);
|
||||
|
||||
// The cell must now prioritize the Curve:
|
||||
// - Foreground must be Cyan
|
||||
// - Mask must ONLY contain the curve dot (1, 3) which is 0x80
|
||||
// - The grid dot (0, 0) which is 0x01 must NOT be in the mask (not contaminated)
|
||||
var (chCurve, fgCurve, _) = canvas.GetCell(0, 0);
|
||||
Assert.Equal(ColorRgb.Cyan, fgCurve);
|
||||
Assert.Equal((char)(0x2800 | 0x80), chCurve);
|
||||
Assert.True((chCurve & 0x01) == 0, "Grid dot 0x01 must NOT be contaminated into the curve mask");
|
||||
|
||||
// 3. Add Crosshair Guide dot at (0, 2) in Magenta
|
||||
// Crosshair guide (layer 3) is lower than curve (layer 5), so curve dominates
|
||||
canvas.SetPixel(0, 2, ColorRgb.Magenta, CanvasLayer.CrosshairGuide);
|
||||
var (chAfterGuide, fgAfterGuide, _) = canvas.GetCell(0, 0);
|
||||
Assert.Equal(ColorRgb.Cyan, fgAfterGuide);
|
||||
Assert.Equal((char)(0x2800 | 0x80), chAfterGuide);
|
||||
|
||||
// 4. Center Crosshair (layer 7) at (0, 1) in White dominates
|
||||
canvas.SetPixel(0, 1, ColorRgb.White, CanvasLayer.Crosshair);
|
||||
var (chCenter, fgCenter, _) = canvas.GetCell(0, 0);
|
||||
Assert.Equal(ColorRgb.White, fgCenter);
|
||||
Assert.Equal((char)(0x2800 | 0x02), chCenter);
|
||||
});
|
||||
|
||||
runner.Add("PlotRenderer: Render functions without stray grid contamination", () =>
|
||||
{
|
||||
var canvas = new BrailleCanvas(20, 20);
|
||||
var vp = new Viewport();
|
||||
var fns = new List<GraphFunction>
|
||||
{
|
||||
new(1, "y = x", ColorRgb.Cyan)
|
||||
};
|
||||
|
||||
// Render with grid enabled
|
||||
PlotRenderer.Render(canvas, vp, fns, _ => 0, showGrid: true);
|
||||
|
||||
// Check all cells: any cell with Cyan foreground should only have dots corresponding
|
||||
// to the line, and must NOT contaminate background grid dots.
|
||||
int cyanCells = 0;
|
||||
for (int r = 0; r < canvas.CellHeight; r++)
|
||||
{
|
||||
for (int c = 0; c < canvas.CellWidth; c++)
|
||||
{
|
||||
var (ch, fg, _) = canvas.GetCell(c, r);
|
||||
if (fg == ColorRgb.Cyan && ch != ' ')
|
||||
{
|
||||
cyanCells++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.True(cyanCells > 0, "Expected Cyan cells for line y=x");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue