diff --git a/Terminal.Gui/Core/Graphs/LineCanvas.cs b/Terminal.Gui/Core/Graphs/LineCanvas.cs index ab45c0264..abb17005c 100644 --- a/Terminal.Gui/Core/Graphs/LineCanvas.cs +++ b/Terminal.Gui/Core/Graphs/LineCanvas.cs @@ -65,7 +65,7 @@ namespace Terminal.Gui.Graphs { for (int x = 0; x < inArea.Width; x++) { var intersects = lines - .Select (l => l.Intersects (x, y)) + .Select (l => l.Intersects (inArea.X + x, inArea.Y + y)) .Where (i => i != null) .ToArray (); diff --git a/UnitTests/Core/LineCanvasTests.cs b/UnitTests/Core/LineCanvasTests.cs index 7e988b0de..a56738c72 100644 --- a/UnitTests/Core/LineCanvasTests.cs +++ b/UnitTests/Core/LineCanvasTests.cs @@ -1,4 +1,7 @@ -using Terminal.Gui.Graphs; +using System; +using System.Collections.Generic; +using System.Text; +using Terminal.Gui.Graphs; using Xunit; using Xunit.Abstractions; @@ -129,6 +132,7 @@ namespace Terminal.Gui.CoreTests { TestHelpers.AssertDriverContentsAre (looksLike, output); } + [Fact,AutoInitShutdown] public void TestLineCanvas_Window () { @@ -280,6 +284,52 @@ namespace Terminal.Gui.CoreTests { TestHelpers.AssertDriverContentsAre (looksLike, output); } + + [Theory, AutoInitShutdown] + [InlineData(0,0,@" +═══ +══ +═══")] + [InlineData (1, 0,@" +══ +═ +══")] + [InlineData (2, 0,@" +═ + +═")] + [InlineData (0, 1,@" +══ +═══")] + [InlineData (0, 2,@" +═══")] + public void TestLineCanvasRenderOffset_NoOffset (int xOffset,int yOffset, string expect) + { + var canvas = new LineCanvas (); + canvas.AddLine (new Point (0, 0), 2, Orientation.Horizontal, BorderStyle.Double); + canvas.AddLine (new Point (0, 1), 1, Orientation.Horizontal, BorderStyle.Double); + canvas.AddLine (new Point (0, 2), 2, Orientation.Horizontal, BorderStyle.Double); + + var bmp = canvas.GenerateImage (new Rect (xOffset, yOffset, 3, 3)); + var actual = BmpToString (bmp); + Assert.Equal (expect.TrimStart (), actual); + + } + + private string BmpToString (System.Rune? [,] bmp) + { + var sb = new StringBuilder (); + for (int y = 0; y < bmp.GetLength (1); y++) { + for (int x = 0; x < bmp.GetLength (0); x++) { + sb.Append (bmp [y, x]); + } + sb.AppendLine (); + } + + return sb.ToString ().TrimEnd (); + } + + private View GetCanvas (out LineCanvas canvas) { var v = new View {