Exemplo n.º 1
0
        public static void AddTest()
        {
            var array = new UnmanagedArray <int>(3);

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

            using (var valueList = new UnmanagedValueList <int>(array, takeOwnership: true))
            {
                valueList.Add(4);

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

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

                valueList.Add(5);

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

                Assert.That(() => valueList[4],
                            Is.EqualTo(5)
                            );
            }

            using (var valueList = new UnmanagedValueList <int>())
            {
                valueList.Add(6);

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

                Assert.That(() => valueList[0],
                            Is.EqualTo(6)
                            );
            }
        }
Exemplo n.º 2
0
        public static void TrimExcessTest()
        {
            var array = new UnmanagedArray <int>(3);

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

            using (var valueList = new UnmanagedValueList <int>(array, takeOwnership: true))
            {
                valueList.TrimExcess();

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

                valueList.Add(4);
                valueList.Add(5);

                valueList.TrimExcess();

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

                valueList.EnsureCapacity(15);
                valueList.TrimExcess(0.3f);

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

            using (var valueList = new UnmanagedValueList <int>())
            {
                valueList.TrimExcess();

                Assert.That(() => valueList,
                            Has.Property("Capacity").EqualTo((nuint)0)
                            .And.Count.EqualTo((nuint)0)
                            );
            }
        }
Exemplo n.º 3
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));
        }
    }
Exemplo n.º 4
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));
        }
    }