public void Decorate(Canvas embroidery, Canvas pattern, Settings settings) { int squareWidth = embroidery.Width / settings.CellsCount; if (embroidery.Height < pattern.Height * squareWidth) throw new WrongResolutionException("Resolution.Height has to be higher"); for (int squareY = 0; squareY <= embroidery.Height - squareWidth; squareY += squareWidth) for (int squareX = 0; squareX <= embroidery.Width - squareWidth; squareX += squareWidth) { embroidery.SetBorder(squareX, squareY, squareWidth, squareWidth, Color.Black, Aligns.Right, settings.GridType); embroidery.SetBorder(squareX, squareY, squareWidth, squareWidth, Color.Black, Aligns.Buttom, settings.GridType); } /* * LONGER THAN SIMPLE FOR var loopsHeight = Enumerable.Range(0, embroidery.Height - squareWidth + 1).Where(i => i % squareWidth == 0); var loopsWidth = Enumerable.Range(0, embroidery.Width - squareWidth + 1).Where(i => i % squareWidth == 0); Parallel.ForEach(loopsHeight, squareY => { Parallel.ForEach(loopsWidth, squareX => { embroidery.SetBorder(squareX, squareY, squareWidth, squareWidth, Color.Black, Aligns.Right, settings.GridType); embroidery.SetBorder(squareX, squareY, squareWidth, squareWidth, Color.Black, Aligns.Buttom, settings.GridType); }); }); */ }
public void Test_Canvas_SetBorderTop() { Canvas canvas = new Canvas(4, 3); Canvas expectedCanvas = new Canvas(4, 3); expectedCanvas.SetColor(0, 0, Color.Black); expectedCanvas.SetColor(1, 0, Color.Black); expectedCanvas.SetColor(2, 0, Color.Black); expectedCanvas.SetColor(3, 0, Color.Black); canvas.SetBorder(0, 0, 4, 3, Color.Black, Aligns.Top, GridType.SolidLine); Assert.IsTrue(canvas.Width == expectedCanvas.Width && canvas.Height == expectedCanvas.Height); for (int y = 0; y < canvas.Height; y++) for (int x = 0; x < canvas.Width; x++) { Color actualColor = canvas.GetColor(x, y); Color expectedColor = expectedCanvas.GetColor(x, y); Assert.IsTrue(actualColor == expectedColor); } }
public void Test_Canvas_SetBorderPointsLeft() { Canvas canvas = new Canvas(4, 4); Canvas expectedCanvas = new Canvas(4, 4); expectedCanvas.SetColor(0, 0, Color.Black); expectedCanvas.SetColor(0, 3, Color.Black); canvas.SetBorder(0, 0, 4, 4, Color.Black, Aligns.Left, GridType.Points); Assert.IsTrue(canvas.Width == expectedCanvas.Width && canvas.Height == expectedCanvas.Height); for (int y = 0; y < canvas.Height; y++) for (int x = 0; x < canvas.Width; x++) { Color actualColor = canvas.GetColor(x, y); Color expectedColor = expectedCanvas.GetColor(x, y); Assert.IsTrue(actualColor == expectedColor); } }