예제 #1
0
        static void EnsureListSize <T>(ref List <T> attribute,
                                       int expectedVertexCount,
                                       AttributeValidationStrategy strategy = AttributeValidationStrategy.Nullify,
                                       T fill = default)
        {
            if (attribute == null || attribute.Count == expectedVertexCount)
            {
                return;
            }

            if (strategy == AttributeValidationStrategy.Nullify)
            {
                attribute = null;
                return;
            }

            var prev = attribute.Count;
            var copy = new List <T>(expectedVertexCount);

            for (int i = 0, c = Mathf.Min(prev, expectedVertexCount); i < c; i++)
            {
                copy.Add(attribute[i]);
            }
            for (int i = copy.Count - 1; i < expectedVertexCount; i++)
            {
                copy.Add(fill);
            }
            attribute = copy;
        }
예제 #2
0
        static void EnsureArraySize <T>(ref T[] attribute,
                                        int expectedVertexCount,
                                        AttributeValidationStrategy strategy = AttributeValidationStrategy.Nullify,
                                        T fill = default)
        {
            if (attribute == null || attribute.Length == expectedVertexCount)
            {
                return;
            }
            if (strategy == AttributeValidationStrategy.Nullify)
            {
                attribute = null;
                return;
            }

            int previous = attribute.Length;

            Array.Resize(ref attribute, expectedVertexCount);
            for (int i = previous - 1; i < expectedVertexCount; i++)
            {
                attribute[i] = fill;
            }
        }