Esempio n. 1
0
        private static void MatrixCycle(int rowFromInclusive, int rowToInclusive, int columnFromInclusive, int columnToInclusive, int yStride, int xStride, int maxDegreeOfParallelism, InnerCycle innerCycle, CancellationToken cancellationToken = default)
        {
            OutOfRangeException.Check(nameof(maxDegreeOfParallelism), maxDegreeOfParallelism, 0);

            var iRows = new List <int>();

            for (var iRow = rowFromInclusive; iRow <= rowToInclusive; iRow += yStride)
            {
                iRows.Add(iRow);
            }

            if (maxDegreeOfParallelism > 1)
            {
                Parallel.ForEach(iRows,
                                 new ParallelOptions
                {
                    MaxDegreeOfParallelism = maxDegreeOfParallelism,
                    CancellationToken      = cancellationToken
                },
                                 iRow =>
                {
                    var row = (iRow - rowFromInclusive) / yStride;
                    ColumnCycle(columnFromInclusive, columnToInclusive, iRow, row, xStride, innerCycle);
                });
            }
            else
            {
                var row = 0;
                foreach (var iRow in iRows)
                {
                    ColumnCycle(columnFromInclusive, columnToInclusive, iRow, row, xStride, innerCycle);
                    row++;
                }
            }
Esempio n. 2
0
        /// <summary>
        ///     Create rectangle from center coordinates and height / width
        /// </summary>
        /// <param name="y">center row</param>
        /// <param name="x">center column</param>
        /// <param name="rows">total height</param>
        /// <param name="columns">total width</param>
        /// <returns>a new rectangle</returns>
        public static Rectangle FromCenter(int y, int x, int rows, int columns)
        {
            EvenException.Check(nameof(rows), rows);
            EvenException.Check(nameof(columns), columns);

            OutOfRangeException.Check(nameof(rows), rows, 1);
            OutOfRangeException.Check(nameof(columns), columns, 1);

            var relHeight = (rows - 1) / 2;
            var relWidth  = (columns - 1) / 2;

            var top  = y - relHeight;
            var left = x - relWidth;

            var region = new Rectangle(left, top, columns, rows);

            return(region);
        }
Esempio n. 3
0
 public void OutOfRange_Exception_ToBig1()
 {
     Assert.Catch <OutOfRangeException>(() => OutOfRangeException.Check("", 11, max: 10));
 }
Esempio n. 4
0
 public void OutOfRange()
 {
     OutOfRangeException.Check("", 1, 0, 10);
     Assert.Pass();
 }
Esempio n. 5
0
 public void OutOfRange_Exception_ToSmall1()
 {
     Assert.Catch <OutOfRangeException>(() => OutOfRangeException.Check("", 1, 5));
 }