Example #1
0
                Index2DArrayBounds2DIndex2DInvalidSectorSizeTestCases()
                {
                    var list3x5 = new List2D <byte>(6, 10);

                    list3x5.AddRows(3);
                    list3x5.AddColumns(5);

                    yield return(new TestCaseData(
                                     list3x5,
                                     new Index2D(0, 0),
                                     new Array2D <byte>(4, 5),
                                     new Bounds2D(4, 5),
                                     new Index2D(0, 0)));

                    yield return(new TestCaseData(
                                     list3x5,
                                     new Index2D(0, 0),
                                     new Array2D <byte>(3, 6),
                                     new Bounds2D(3, 6),
                                     new Index2D(0, 0)));

                    yield return(new TestCaseData(
                                     list3x5,
                                     new Index2D(0, 0),
                                     new Array2D <byte>(2, 5),
                                     new Bounds2D(3, 5),
                                     new Index2D(0, 0)));

                    yield return(new TestCaseData(
                                     list3x5,
                                     new Index2D(0, 0),
                                     new Array2D <byte>(3, 4),
                                     new Bounds2D(3, 5),
                                     new Index2D(0, 0)));

                    yield return(new TestCaseData(
                                     list3x5,
                                     new Index2D(1, 0),
                                     new Array2D <byte>(3, 5),
                                     new Bounds2D(3, 5),
                                     new Index2D(0, 0)));

                    yield return(new TestCaseData(
                                     list3x5,
                                     new Index2D(0, 1),
                                     new Array2D <byte>(3, 5),
                                     new Bounds2D(3, 5),
                                     new Index2D(0, 0)));

                    yield return(new TestCaseData(
                                     list3x5,
                                     new Index2D(0, 0),
                                     new Array2D <byte>(3, 5),
                                     new Bounds2D(3, 5),
                                     new Index2D(1, 0)));

                    yield return(new TestCaseData(
                                     list3x5,
                                     new Index2D(0, 0),
                                     new Array2D <byte>(3, 5),
                                     new Bounds2D(3, 5),
                                     new Index2D(0, 1)));
                }
Example #2
0
 public static ItemRequestResult <Index2D> Test <T>(List2D <T> list, T item)
 => list.LastIndexOf(item);
Example #3
0
 public static void Index2DIntThrowsExceptionIfCountExceedsList2DCount <T>(
     List2D <T> list, Index2D startIndex, int count)
 => Assert.Throws <ArgumentOutOfRangeException>(
     () => list.LastIndexOf(default, startIndex, count));
Example #4
0
        /// <summary>
        /// Helper method for mesh generation
        /// </summary>
        /// <param name="dimensions"></param>
        private void GenerateMeshPartHelper(Dimensions2D dimensions)
        {
            // Create a 2D list that represents if a coordinate has been processed or not
            // Also create a queue that contains all possible voxels to process
            var processed    = new List2D <bool>(dimensions);
            var processQueue = new Queue <Dimensions2D>();

            for (int u = 0; u < dimensions.X; u++)
            {
                for (int v = 0; v < dimensions.Y; v++)
                {
                    processed[u, v] = false;
                    processQueue.Enqueue(new Dimensions2D(u, v));
                }
            }

            // Process the entire queue
            while (processQueue.Count > 0)
            {
                // Find the first voxel that has not been processed and has a visible face
                var currentCoord = processQueue.Dequeue();
                int startU       = currentCoord.X;
                int startV       = currentCoord.Y;
                if (processed[startU, startV] || (_voxelPlaneFaces[startU, startV] & _faceType) != _faceType)
                {
                    processed[startU, startV] = true;
                    continue;
                }

                // Find width
                // Stop when one of the following is found
                //      - an empty voxel
                //      - voxel that doesn't have a visible face
                //      - voxel that doesn't match the starting voxel
                //      - voxel that has already been processed
                int width = 0;
                for (int u = startU; u < dimensions.X; u++)
                {
                    if (GetVoxel(u, startV).Empty ||
                        (_voxelPlaneFaces[u, startV] & _faceType) != _faceType ||
                        !GetVoxel(startU, startV).Equals(GetVoxel(u, startV)) ||
                        processed[u, startV])
                    {
                        break;
                    }
                    processed[u, startV] = true;
                    width++;
                }

                // Find height
                // Stop when one of the following is found
                //      - an empty voxel
                //      - voxel that doesn't have a visible face
                //      - voxel that doesn't match the starting voxel
                //      - voxel that has already been processed
                int height = 1;
                for (int v = startV + 1; v < dimensions.Y + 1; v++)
                {
                    bool fullHeight = true;
                    // The entire width will be looped over even if the height is not full..
                    // This is done so the previous full height can be marked as processed
                    for (int u = startU; u < startU + width; u++)
                    {
                        if (v != dimensions.Y &&
                            (GetVoxel(u, v).Empty ||
                             (_voxelPlaneFaces[u, v] & _faceType) != _faceType ||
                             !GetVoxel(startU, startV).Equals(GetVoxel(u, v)) ||
                             processed[u, v]))
                        {
                            fullHeight = false;
                        }


                        processed[u, v - 1] = true;
                    }

                    if (!fullHeight)
                    {
                        break;
                    }

                    if (v != dimensions.Y)
                    {
                        height++;
                    }
                }

                AddFace(startU, startV, width, height);
            }
        }
 public static void TestFindAll <T, Index2DCollection, TPredicate>(
     List2D <T> list, TPredicate match, Index2DCollection expected)
     where Index2DCollection : ICollection <Index2D>, new()
     where TPredicate : struct, IPredicate <T>
 => CollectionAssert.AreEqual(
     expected, list.FindAllIndices <Index2DCollection, TPredicate>(match));
 public static bool Test <T>(List2D <T> list, Predicate <T> match)
 => list.TrueForAll(match);
 public static void GetColumnThrowExceptionIfIndexExceedsColumns <T>(
     List2D <T> list, int index)
 => Assert.Throws <ArgumentOutOfRangeException>(() => list.GetColumn(index));
Example #8
0
 public static ItemRequestResult <Index2D> Test <T>(
     List2D <T> list, Index2D startIndex, int count, Predicate <T> match)
 => list.FindIndex(startIndex, count, match);
Example #9
0
 public static void Index2DBounds2DThrowsExceptionIfSectorIsOutOfBounds <T>(
     List2D <T> list, Index2D startIndex, Bounds2D sector)
 => Assert.Throws <ArgumentOutOfRangeException>(
     () => list.FindIndex(startIndex, sector, o => true));
Example #10
0
 public static ItemRequestResult <Index2D> Test <T>(
     List2D <T> list, Predicate <T> match)
 => list.FindIndex(match);
Example #11
0
 public static void Index2DIntThrowsExceptionIfStartIndexIsOutOfBounds <T>(
     List2D <T> list, Index2D startIndex)
 => Assert.Throws <ArgumentOutOfRangeException>(
     () => list.FindIndex(startIndex, 0, o => true));
Example #12
0
 public static void ThrowsExceptionIfCountIsInvalid <T>(
     List2D <T> list, int startIndex, int count)
 => Assert.Throws <ArgumentOutOfRangeException>(
     () => list.RemoveColumns(startIndex, count));
Example #13
0
            private static IEnumerable <TestCaseData> ColumnsTestCases()
            {
                var list1 = List2D <int> .FromSystem2DArray(
                    new int[, ] {
                    { 2, 3, 5 },
                    { 4, 9, 1 },
                    { 8, 2, 3 }
                });

                list1.IncreaseCapacity(list1.Boundaries);

                var list2 = List2D <int> .FromSystem2DArray(
                    new int[, ] {
                    { 2, 3, 5 },
                    { 4, 9, 1 },
                    { 8, 2, 3 }
                });

                var list3 = List2D <string> .FromSystem2DArray(
                    new string[, ] {
                    { "2", "0", "3", "1" },
                    { "4", "2", "8", "7" }
                });

                list3.IncreaseCapacity(list3.Boundaries);

                var list4 = List2D <int> .FromSystem2DArray(
                    new int[, ] {
                    { 1, 2 },
                    { 3, 4 }
                });

                list4.IncreaseCapacity(list4.Boundaries);

                var list5 = List2D <int> .FromSystem2DArray(
                    new int[, ] {
                    { 1, 2 },
                    { 3, 4 }
                });

                list5.IncreaseCapacity(list5.Boundaries);

                yield return(new TestCaseData(
                                 list1, 1, 1, List2D <int> .FromSystem2DArray(
                                     new int[, ] {
                    { 2, 5 },
                    { 4, 1 },
                    { 8, 3 }
                })));

                yield return(new TestCaseData(
                                 list2, 1, 1, List2D <int> .FromSystem2DArray(
                                     new int[, ] {
                    { 2, 5 },
                    { 4, 1 },
                    { 8, 3 }
                })));

                yield return(new TestCaseData(
                                 list3, 0, 2, List2D <string> .FromSystem2DArray(
                                     new string[, ] {
                    { "3", "1" },
                    { "8", "7" }
                })));

                yield return(new TestCaseData(
                                 list4, 0, 0, List2D <int> .FromSystem2DArray(
                                     new int[, ] {
                    { 1, 2 },
                    { 3, 4 }
                })));

                yield return(new TestCaseData(list5, 0, 2, new List2D <int>()));
            }
 public static void ThrowsExceptionIfIndexIsOutOfBounds <T>(
     List2D <T> list, Index2D index)
 => Assert.Throws <IndexOutOfRangeException>(
     () => { ref readonly T value = ref list[index]; });
Example #15
0
 public static void ThrowsExceptionIfSizeIsInvalid <T>(
     List2D <T> list, int rows, int columns)
 => Assert.Throws <ArgumentOutOfRangeException>(
     () => list.IncreaseCapacity(rows, columns));
Example #16
0
 public static ItemRequestResult <Index2D> Test <T>(
     List2D <T> list, Index2D startIndex, Bounds2D sector, Predicate <T> match)
 => list.FindIndex(startIndex, sector, match);
 public static void IsEmptyReturnsTrueWhenListIsCleared <T>(List2D <T> list)
 {
     list.Clear();
     Assert.That(list.IsEmpty);
 }
Example #18
0
 public static void Index2DIntThrowsExceptionIfStartIndexIsOutOfBounds
 <T>(List2D <T> list, Index2D startIndex)
 => Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(
                                                    startIndex, 0, new AlwaysTruePredicate <T>()));
 public static bool Test <T, TPredicate>(List2D <T> list, TPredicate match)
     where TPredicate : struct, IPredicate <T>
 => list.TrueForAll(match);
Example #20
0
 public static void Index2DIntThrowsExceptionIfCountExceedsList2DCount
 <T>(List2D <T> list, Index2D startIndex, int count)
 => Assert.Throws <ArgumentOutOfRangeException>(() => list.FindIndex(
                                                    startIndex, count, new AlwaysTruePredicate <T>()));
 public static void GetColumnTest <T>(
     List2D <T> list, int index, RefColumn <T, List2D <T> > expected)
 => CollectionAssert.AreEqual(expected, list.GetColumn(index));
Example #22
0
 public static ItemRequestResult <Index2D> Test <T, TPredicate>(
     List2D <T> list, Index2D startIndex, int count, TPredicate match)
     where TPredicate : struct, IPredicate <T>
 => list.FindIndex(startIndex, count, match);
 public static void TestFindAll <T, TCollection>(
     List2D <T> list, Predicate <T> match, TCollection expected)
     where TCollection : ICollection <T>, new()
 => CollectionAssert.AreEqual(expected, list.FindAll <TCollection>(match));
Example #24
0
 public static void CountEqualsCollectionLength2 <T>(
     List2D <T> collection, RefRow <T, List2D <T> > row)
 => RefRowTests.CountEqualsCollectionLength2(collection, row);
Example #25
0
 public static ItemRequestResult <Index2D> Test <T>(
     List2D <T> list, T item)
     where T : IComparable <T>
 => list.LastIndexOfComparable(item);
 public static ItemRequestResult <T> Test <T>(List2D <T> list, Predicate <T> match)
 => list.FindLast(match);
Example #27
0
 public static void Index2DIntThrowsExceptionIfStartIndexIsOutOfBounds <T>(
     List2D <T> list, Index2D startIndex)
 => Assert.Throws <ArgumentOutOfRangeException>(
     () => list.LastIndexOf(default, startIndex, 0));
 public static ItemRequestResult <T> Test <T, TPredicate>(
     List2D <T> list, TPredicate match)
     where TPredicate : struct, IPredicate <T>
 => list.FindLast(match);
Example #29
0
 public static ItemRequestResult <Index2D> Test <T>(
     List2D <T> list, T item, Index2D startIndex, int count)
 => list.LastIndexOf(item, startIndex, count);
Example #30
0
 public static void Test <T>(
     List2D <T> src, Array2D <T> dest, Array2D <T> expected)
 {
     src.CopyTo(dest);
     CollectionAssert.AreEqual(expected, dest);
 }