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) ); }
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)); } }
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) ); } }
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)); } }