Esempio n. 1
0
    private static void BaseCaseQuad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, ref UnmanagedValueList <Vector3> vertices, ref UnmanagedValueList <uint> indices)
    {
        //
        //  a-------b    y          in this setup
        //  | \     |    ^     z    the origin o
        //  |   \   |    |   /      is in the middle
        //  |     \ |    | /        of the rendered scene
        //  d-------c    o------>x  (z is into the page, so xyz is left-handed)
        //

        // Clockwise when looking at the triangle from the outside.
        // Replicate vertices in order for normals be different.
        // In spite of normal interpolation we want a flat surface shading effect

        vertices.EnsureCapacity(vertices.Count + 12);

        // Add both windings so we can rotate 360 degrees and still see it

        vertices.Add(a);
        vertices.Add(b);
        vertices.Add(c);

        vertices.Add(a);
        vertices.Add(c);
        vertices.Add(b);

        vertices.Add(a);
        vertices.Add(c);
        vertices.Add(d);

        vertices.Add(a);
        vertices.Add(d);
        vertices.Add(c);

        var i = indices.Count;

        for (nuint j = 0; j < 12; j++)
        {
            indices.Add((uint)(i + j));
        }
    }
        public static void RemoveTest()
        {
            var array = new UnmanagedArray <int>(3);

            array[0] = 1;
            array[1] = 2;
            array[2] = 3;

            using (var valueList = new UnmanagedValueList <int>(array, takeOwnership: true))
            {
                Assert.That(() => valueList.Remove(1),
                            Is.True
                            );

                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)3)
                            .And.Count.EqualTo((nuint)2)
                            );

                Assert.That(() => valueList[0],
                            Is.EqualTo(2)
                            );

                Assert.That(() => valueList[1],
                            Is.EqualTo(3)
                            );

                Assert.That(() => valueList.Remove(0),
                            Is.False
                            );
            }

            using (var valueList = new UnmanagedValueList <int>())
            {
                Assert.That(() => valueList.Remove(0),
                            Is.False
                            );
            }
        }
        public static void CtorNUIntNUIntTest()
        {
            using (var valueList = new UnmanagedValueList <int>(5))
            {
                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)5)
                            .And.Count.EqualTo((nuint)0)
                            );
            }

            using (var valueList = new UnmanagedValueList <int>(5, 2))
            {
                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)5)
                            .And.Count.EqualTo((nuint)0)
                            );
            }

            Assert.That(() => new UnmanagedValueList <int>(5, 3),
                        Throws.InstanceOf <ArgumentOutOfRangeException>()
                        .And.Property("ActualValue").EqualTo((nuint)3)
                        .And.Property("ParamName").EqualTo("alignment")
                        );

            using (var valueList = new UnmanagedValueList <int>(0, 2))
            {
                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)0)
                            .And.Count.EqualTo((nuint)0)
                            );
            }

            Assert.That(() => new UnmanagedValueList <int>(0, 3),
                        Throws.InstanceOf <ArgumentOutOfRangeException>()
                        .And.Property("ActualValue").EqualTo((nuint)3)
                        .And.Property("ParamName").EqualTo("alignment")
                        );
        }
        public static void EnsureCapacityTest()
        {
            var array = new UnmanagedArray <int>(3);

            array[0] = 1;
            array[1] = 2;
            array[2] = 3;

            using var valueList = new UnmanagedValueList <int>(array);
            valueList.EnsureCapacity(0);

            Assert.That(() => valueList,
                        Has.Property("Capacity").EqualTo((nuint)3)
                        .And.Count.EqualTo((nuint)3)
                        );

            valueList.EnsureCapacity(3);

            Assert.That(() => valueList,
                        Has.Property("Capacity").EqualTo((nuint)3)
                        .And.Count.EqualTo((nuint)3)
                        );

            valueList.EnsureCapacity(4);

            Assert.That(() => valueList,
                        Has.Property("Capacity").EqualTo((nuint)6)
                        .And.Count.EqualTo((nuint)3)
                        );

            valueList.EnsureCapacity(16);

            Assert.That(() => valueList,
                        Has.Property("Capacity").EqualTo((nuint)16)
                        .And.Count.EqualTo((nuint)3)
                        );
        }
Esempio n. 5
0
    internal static (UnmanagedValueList <Vector3> vertices, UnmanagedValueList <uint> indices) CreateMeshQuad(int recursionDepth)
    {
        var r = 0.99f;

        var vertices = new UnmanagedValueList <Vector3>();
        var indices  = new UnmanagedValueList <uint>();

        //
        //  a-------b    y          in this setup
        //  | \     |    ^     z    the origin o
        //  |   \   |    |   /      is in the middle
        //  |     \ |    | /        of the rendered scene
        //  d-------c    o------>x  (z is into the page, so xyz is left-handed)
        //

        var a = Vector3.Create(-r, +r, 0f);
        var b = Vector3.Create(+r, +r, 0f);
        var c = Vector3.Create(+r, -r, 0f);
        var d = Vector3.Create(-r, -r, 0f);

        QuadRecursion(recursionDepth, a, b, c, d, ref vertices, ref indices);

        return(vertices, indices);
    }
        public static void CtorUnmanagedReadOnlySpanNUIntTest()
        {
            using var array = new UnmanagedArray <int>(3);

            array[0] = 1;
            array[1] = 2;
            array[2] = 3;

            using (var valueList = new UnmanagedValueList <int>(array.AsSpan()))
            {
                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)3)
                            .And.Count.EqualTo((nuint)3)
                            );
            }

            using (var valueList = new UnmanagedValueList <int>(array.AsSpan(), 2))
            {
                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)3)
                            .And.Count.EqualTo((nuint)3)
                            );
            }

            Assert.That(() => new UnmanagedValueList <int>(array.AsSpan(), 3),
                        Throws.InstanceOf <ArgumentOutOfRangeException>()
                        .And.Property("ActualValue").EqualTo((nuint)3)
                        .And.Property("ParamName").EqualTo("alignment")
                        );

            using (var valueList = new UnmanagedValueList <int>(UnmanagedArray <int> .Empty.AsSpan()))
            {
                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)0)
                            .And.Count.EqualTo((nuint)0)
                            );
            }

            using (var valueList = new UnmanagedValueList <int>(UnmanagedArray <int> .Empty.AsSpan(), 2))
            {
                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)0)
                            .And.Count.EqualTo((nuint)0)
                            );
            }

            Assert.That(() => new UnmanagedValueList <int>(UnmanagedArray <int> .Empty.AsSpan(), 3),
                        Throws.InstanceOf <ArgumentOutOfRangeException>()
                        .And.Property("ActualValue").EqualTo((nuint)3)
                        .And.Property("ParamName").EqualTo("alignment")
                        );

            using (var valueList = new UnmanagedValueList <int>(new UnmanagedArray <int>().AsSpan()))
            {
                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)0)
                            .And.Count.EqualTo((nuint)0)
                            );
            }

            using (var valueList = new UnmanagedValueList <int>(new UnmanagedArray <int>().AsSpan(), 2))
            {
                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)0)
                            .And.Count.EqualTo((nuint)0)
                            );
            }

            Assert.That(() => new UnmanagedValueList <int>(new UnmanagedArray <int>().AsSpan(), 3),
                        Throws.InstanceOf <ArgumentOutOfRangeException>()
                        .And.Property("ActualValue").EqualTo((nuint)3)
                        .And.Property("ParamName").EqualTo("alignment")
                        );
        }
        public static void CopyToUnmanagedSpanTest()
        {
            var array = new UnmanagedArray <int>(3);

            array[0] = 1;
            array[1] = 2;
            array[2] = 3;

            using (var valueList = new UnmanagedValueList <int>(array, takeOwnership: true))
            {
                using (var destination = new UnmanagedArray <int>(3))
                {
                    valueList.CopyTo(destination);

                    Assert.That(() => destination[0],
                                Is.EqualTo(1)
                                );

                    Assert.That(() => destination[1],
                                Is.EqualTo(2)
                                );

                    Assert.That(() => destination[2],
                                Is.EqualTo(3)
                                );
                }

                using (var destination = new UnmanagedArray <int>(6))
                {
                    valueList.CopyTo(destination);

                    Assert.That(() => destination[0],
                                Is.EqualTo(1)
                                );

                    Assert.That(() => destination[1],
                                Is.EqualTo(2)
                                );

                    Assert.That(() => destination[2],
                                Is.EqualTo(3)
                                );

                    Assert.That(() => destination[3],
                                Is.EqualTo(0)
                                );

                    Assert.That(() => destination[4],
                                Is.EqualTo(0)
                                );

                    Assert.That(() => destination[5],
                                Is.EqualTo(0)
                                );
                }

                Assert.That(() => valueList.CopyTo(UnmanagedArray <int> .Empty),
                            Throws.InstanceOf <ArgumentOutOfRangeException>()
                            .And.Property("ActualValue").EqualTo((nuint)3)
                            .And.Property("ParamName").EqualTo("Count")
                            );
            }

            using (var valueList = new UnmanagedValueList <int>())
            {
                Assert.That(() => valueList.CopyTo(UnmanagedArray <int> .Empty),
                            Throws.Nothing
                            );
            }
        }
 internal ItemsEnumerator(UnmanagedValuePool <T> pool)
 {
     _enumerator = pool._items.GetEnumerator();
 }
Esempio n. 9
0
 public DebugView(UnmanagedValueList <T> list)
 {
     _list = list;
 }
Esempio n. 10
0
    private static void BaseCaseTetrahedron(Vector3 a, Vector3 b, Vector3 c, Vector3 d, ref UnmanagedValueList <Vector3> vertices, ref UnmanagedValueList <uint> indices)
    {
        //         d
        //         .
        //        /|\
        //       / | \        y          in this setup
        //      /  |  \       ^     z    the origin o
        //     /   |   \      |   /      is in the middle
        //    /    |    \     | /        of the rendered scene
        //  a'\''''|''''/'b   o------>x  (z is into the page, so xyz is left-handed)
        //      \  |  /
        //        \|/
        //         '
        //         c

        // Clockwise when looking at the triangle from the outside.
        // Replicate vertices in order for normals be different.
        // In spite of normal interpolation we want a flat surface shading effect

        vertices.EnsureCapacity(vertices.Count + 12);

        // bottom
        vertices.Add(a);
        vertices.Add(b);
        vertices.Add(c);

        // left
        vertices.Add(a);
        vertices.Add(c);
        vertices.Add(d);

        // right
        vertices.Add(b);
        vertices.Add(d);
        vertices.Add(c);

        // back
        vertices.Add(a);
        vertices.Add(d);
        vertices.Add(b);

        var i = indices.Count;

        for (nuint j = 0; j < 12; j++)
        {
            indices.Add((uint)(i + j));
        }
    }
Esempio n. 11
0
 private static void TetrahedronRecursion(int recursionDepth, Vector3 a, Vector3 b, Vector3 c, Vector3 d, ref UnmanagedValueList <Vector3> vertices, ref UnmanagedValueList <uint> indices)
 {
     //         d
     //         .
     //        /|\         y          in this setup
     //       / | \        ^     z    the origin o
     //      /h |  \i      |   /      is in the middle
     //     /   |   \      | /        of the rendered scene
     //    /    |j    \    o------>x  (z is into the page, so xyz is left-handed)
     //  a'\'''e|''''/'b
     //     f\  |  /g
     //        \|/
     //         '
     //         c
     if (recursionDepth == 0)
     {
         BaseCaseTetrahedron(a, b, c, d, ref vertices, ref indices);
     }
     else
     {
         // subdivide all tetrahedron edges at their midpoints
         // and form four new tetrahedrons from them
         var e = (a + b) / 2;
         var f = (a + c) / 2;
         var g = (b + c) / 2;
         var h = (a + d) / 2;
         var i = (b + d) / 2;
         var j = (c + d) / 2;
         TetrahedronRecursion(recursionDepth - 1, a, e, f, h, ref vertices, ref indices);
         TetrahedronRecursion(recursionDepth - 1, e, b, g, i, ref vertices, ref indices);
         TetrahedronRecursion(recursionDepth - 1, f, g, c, j, ref vertices, ref indices);
         TetrahedronRecursion(recursionDepth - 1, h, i, j, d, ref vertices, ref indices);
     }
 }
Esempio n. 12
0
 private static void QuadRecursion(int recursionDepth, Vector3 a, Vector3 b, Vector3 c, Vector3 d, ref UnmanagedValueList <Vector3> vertices, ref UnmanagedValueList <uint> indices)
 {
     //
     //  a-e---f-b    y          in this setup
     //  l m   n g    ^     z    the origin o
     //  |   \   |    |   /      is in the middle
     //  k p   o h    | /        of the rendered scene
     //  d-j---i-c    o------>x  (z is into the page, so xyz is left-handed)
     //
     if (recursionDepth == 0)
     {
         BaseCaseQuad(a, b, c, d, ref vertices, ref indices);
     }
     else
     {
         // subdivide all tetrahedron edges at their midpoints
         // and form four new tetrahedrons from them
         var s = 5 / 11f;
         var t = 1 - s;
         var e = (a * t) + (b * s);
         var f = (a * s) + (b * t);
         var g = (b * t) + (c * s);
         var h = (b * s) + (c * t);
         var i = (c * t) + (d * s);
         var j = (c * s) + (d * t);
         var k = (d * t) + (a * s);
         var l = (d * s) + (a * t);
         var m = (a * t) + (c * s);
         var o = (a * s) + (c * t);
         var n = (b * t) + (d * s);
         var p = (b * s) + (d * t);
         QuadRecursion(recursionDepth - 1, a, e, m, l, ref vertices, ref indices);
         QuadRecursion(recursionDepth - 1, f, b, g, n, ref vertices, ref indices);
         QuadRecursion(recursionDepth - 1, o, h, c, i, ref vertices, ref indices);
         QuadRecursion(recursionDepth - 1, k, p, j, d, ref vertices, ref indices);
     }
 }
 /// <summary>Initializes a new instance of the <see cref="UnmanagedValuePool{T}" /> struct.</summary>
 /// <param name="capacity">The initial capacity of the pool.</param>
 public UnmanagedValuePool(nuint capacity)
 {
     _availableItems = new UnmanagedValueQueue <T>(capacity);
     _items          = new UnmanagedValueList <T>(capacity);
 }
 internal ItemsEnumerator(UnmanagedValueList <T> list)
 {
     _list  = list;
     _index = nuint.MaxValue;
 }