当前位置: 首页>>代码示例>>C#>>正文


C# RawList.RemoveAt方法代码示例

本文整理汇总了C#中RawList.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# RawList.RemoveAt方法的具体用法?C# RawList.RemoveAt怎么用?C# RawList.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RawList的用法示例。


在下文中一共展示了RawList.RemoveAt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Basics

		[Test] public void Basics()
		{
			RawList<int> intList = new RawList<int>();
			intList.Add(10);
			intList.AddRange(new int[] { 17, 42, 94 });

			Assert.AreEqual(4, intList.Count);
			Assert.IsTrue(intList.Contains(42));
			Assert.AreEqual(2, intList.IndexOf(42));
			CollectionAssert.AreEqual(new int[] { 10, 17, 42, 94 }, intList);
			CollectionAssert.AreEqual(new int[] { 10, 17, 42, 94 }, intList.Data.Take(intList.Count));

			intList.ShrinkToFit();
			Assert.AreEqual(intList.Count, intList.Capacity);

			intList.Remove(42);
			Assert.AreEqual(3, intList.Count);
			Assert.IsTrue(!intList.Contains(42));
			Assert.AreEqual(-1, intList.IndexOf(42));
			CollectionAssert.AreEqual(new int[] { 10, 17, 94 }, intList);
			CollectionAssert.AreEqual(new int[] { 10, 17, 94 }, intList.Data.Take(intList.Count));

			intList.Insert(1, 100);
			CollectionAssert.AreEqual(new int[] { 10, 100, 17, 94 }, intList);
			CollectionAssert.AreEqual(new int[] { 10, 100, 17, 94 }, intList.Data.Take(intList.Count));

			intList.InsertRange(2, new int[] { 150, 200, 250, 300 });
			CollectionAssert.AreEqual(new int[] { 10, 100, 150, 200, 250, 300, 17, 94 }, intList);
			CollectionAssert.AreEqual(new int[] { 10, 100, 150, 200, 250, 300, 17, 94 }, intList.Data.Take(intList.Count));

			intList.RemoveAt(1);
			CollectionAssert.AreEqual(new int[] { 10, 150, 200, 250, 300, 17, 94 }, intList);
			CollectionAssert.AreEqual(new int[] { 10, 150, 200, 250, 300, 17, 94 }, intList.Data.Take(intList.Count));

			intList.Clear();
			Assert.AreEqual(0, intList.Count);
			Assert.IsTrue(!intList.Contains(94));
		}
开发者ID:Scottyaim,项目名称:duality,代码行数:38,代码来源:RawListTest.cs

示例2: SelectImporter

        protected RawList<ImportInputAssignment> SelectImporter(AssetImportEnvironment env)
        {
            if (!env.IsPrepareStep) throw new ArgumentException(
                "The specified import environment must be configured as a preparation environment.",
                "env");

            // Find an importer to handle some or all of the unhandled input files
            RawList<ImportInputAssignment> candidateMapping = new RawList<ImportInputAssignment>();
            foreach (IAssetImporter importer in AssetManager.Importers)
            {
                env.ResetAcquiredData();

                try
                {
                    importer.PrepareImport(env);
                }
                catch (Exception ex)
                {
                    Log.Editor.WriteError("An error occurred in the preparation step of '{1}': {0}",
                        Log.Exception(ex),
                        Log.Type(importer.GetType()));
                    continue;
                }

                if (env.HandledInput.Any())
                {
                    candidateMapping.Add(new ImportInputAssignment
                    {
                        Importer = importer,
                        HandledInput = env.HandledInput.ToArray(),
                        ExpectedOutput = env.Output.ToArray()
                    });
                }
            }

            // Sort candidate mapping from most files to least files, so we can solve the biggest conflicts first
            candidateMapping.Sort((a, b) => b.HandledInput.Length - a.HandledInput.Length);

            // Determine if multiple importers intend to handle the same files and resolve conflicts
            List<int> conflictingIndices = new List<int>();
            List<string> conflictingFiles = new List<string>();
            for (int mainIndex = 0; mainIndex < candidateMapping.Count; mainIndex++)
            {
                ImportInputAssignment assignment = candidateMapping[mainIndex];

                // Find all conflicts related to this assignment
                conflictingIndices.Clear();
                conflictingFiles.Clear();
                for (int secondIndex = 0; secondIndex < candidateMapping.Count; secondIndex++)
                {
                    if (secondIndex == mainIndex) continue;

                    ImportInputAssignment conflictAssignment = candidateMapping[secondIndex];
                    IEnumerable<string> mainFiles = assignment.HandledInput.Select(item => item.Path);
                    IEnumerable<string> secondFiles = conflictAssignment.HandledInput.Select(item => item.Path);
                    string[] conflicts = mainFiles.Intersect(secondFiles).ToArray();
                    if (conflicts.Length > 0)
                    {
                        if (conflictingIndices.Count == 0) conflictingIndices.Add(mainIndex);
                        conflictingIndices.Add(secondIndex);
                        conflictingFiles.AddRange(conflicts);
                    }
                }

                // Resolve conflicts with this assignment
                if (conflictingIndices.Count > 0)
                {
                    // Determine which importer to prefer for this conflict
                    ImportInputAssignment[] conflictingAssignments = conflictingIndices.Select(i => candidateMapping[i]).ToArray();
                    int keepIndex = this.ResolveMappingConflict(conflictingAssignments);

                    // If we somehow decided that none of the options is viable, abort the operation
                    if (keepIndex == -1)
                    {
                        candidateMapping.Clear();
                        return candidateMapping;
                    }

                    // Sort indices to remove in declining order and remove their mappings
                    conflictingIndices.Remove(keepIndex);
                    conflictingIndices.Sort((a, b) => b - a);
                    foreach (int index in conflictingIndices)
                    {
                        candidateMapping.RemoveAt(index);
                    }

                    // Start over with the conflict search
                    mainIndex = -1;
                    continue;
                }
            }

            return candidateMapping;
        }
开发者ID:SirePi,项目名称:duality,代码行数:94,代码来源:AssetImportOperation.cs

示例3: RemoveResetsReferenceTypesToDefault

		[Test] public void RemoveResetsReferenceTypesToDefault()
		{
			RawList<string> list = new RawList<string>(Enumerable.Range(0, 10).Select(i => i.ToString()));

			// Is the internal array empty if not assigned otherwise?
			if (list.Capacity > list.Count)
				Assert.AreSame(null, list.Data[list.Count]);

			// Adjusting the count shouldn't affect the internal array, just as documented
			list.Count = 0;
			for (int i = 0; i < 10; i++)
			{
				Assert.AreNotSame(null, list.Data[i]);
			}
			list.Count = 10;

			// Check various types of removal and make sure the internal array is reset properly
			{
				// Remove an element
				list.Remove("1");
				Assert.AreSame(null, list.Data[list.Count]);
				list.RemoveAt(5);
				Assert.AreSame(null, list.Data[list.Count]);

				// Remove a range
				list.RemoveRange(0, 5);
				for (int i = list.Count; i < list.Data.Length; i++)
				{
					Assert.AreSame(null, list.Data[i]);
				}

				// Clear the list
				list.Clear();
				for (int i = list.Count; i < list.Data.Length; i++)
				{
					Assert.AreSame(null, list.Data[i]);
				}
			}
		}
开发者ID:Scottyaim,项目名称:duality,代码行数:39,代码来源:RawListTest.cs

示例4: GenerateCollisionShapes

        private static void GenerateCollisionShapes(TileEdgeMap edgeMap, Vector2 origin, Vector2 tileSize, bool roundedCorners, IList<ShapeInfo> shapeList)
        {
            // Traverse the edge map and gradually create chain / loop
            // shapes until all edges have been used.
            RawList<Point2> currentChain = new RawList<Point2>();
            RawList<Vector2> vertexBuffer = new RawList<Vector2>();
            while (true)
            {
                // Begin a new continuous chain of nodes
                currentChain.Clear();

                // Find a starting node for our current chain.
                // If there is none, we found and handled all edges.
                Point2 start = edgeMap.FindNonEmpty();
                if (start == new Point2(-1, -1))
                    break;

                // Traverse the current chain node-by-node from the start we found
                Point2 current = start;
                while (true)
                {
                    // Add the current node to our continuous chain
                    currentChain.Add(current);

                    // Find the next node that connects to the current one.
                    // If there is none, our current chain is done.
                    Point2 next = edgeMap.GetClockwiseNextFrom(current);
                    if (next == new Point2(-1, -1))
                        break;

                    // Remove the edge we used to get to the next node
                    edgeMap.RemoveEdge(current, next);

                    // Use the next node as origin for traversing further
                    current = next;
                }

                // Generate a shape from the current chain
                bool isLoop = (start == currentChain[currentChain.Count - 1]);
                if (isLoop) currentChain.RemoveAt(currentChain.Count - 1);
                vertexBuffer.Clear();

                // Rounded corners
                if (roundedCorners && currentChain.Count >= 3)
                {
                    vertexBuffer.Reserve(currentChain.Count * 2);
                    vertexBuffer.Count = 0;
                    for (int i = 0; i < currentChain.Count; i++)
                    {
                        int prevIndex = (i - 1 + currentChain.Count) % currentChain.Count;
                        int nextIndex = (i + 1) % currentChain.Count;

                        Vector2 currentVert = origin + tileSize * (Vector2)currentChain[i];
                        Vector2 prevVert = origin + tileSize * (Vector2)currentChain[prevIndex];
                        Vector2 nextVert = origin + tileSize * (Vector2)currentChain[nextIndex];

                        if (nextVert - currentVert != currentVert - prevVert)
                        {
                            if (!isLoop && (i == 0 || i == currentChain.Count - 1))
                            {
                                vertexBuffer.Add(currentVert);
                            }
                            else
                            {
                                vertexBuffer.Add(currentVert + (prevVert - currentVert).Normalized * tileSize * 0.2f);
                                vertexBuffer.Add(currentVert + (nextVert - currentVert).Normalized * tileSize * 0.2f);
                            }
                        }
                    }
                }
                // Sharp corners
                else
                {
                    vertexBuffer.Reserve(currentChain.Count);
                    vertexBuffer.Count = 0;
                    for (int i = 0; i < currentChain.Count; i++)
                    {
                        int prevIndex = (i - 1 + currentChain.Count) % currentChain.Count;
                        int nextIndex = (i + 1) % currentChain.Count;

                        Vector2 currentVert = origin + tileSize * (Vector2)currentChain[i];
                        Vector2 prevVert = origin + tileSize * (Vector2)currentChain[prevIndex];
                        Vector2 nextVert = origin + tileSize * (Vector2)currentChain[nextIndex];

                        if (nextVert - currentVert != currentVert - prevVert)
                            vertexBuffer.Add(currentVert);
                    }
                }
                shapeList.Add(isLoop ?
                    (ShapeInfo)new LoopShapeInfo(vertexBuffer) :
                    (ShapeInfo)new ChainShapeInfo(vertexBuffer));
            }
        }
开发者ID:SirePi,项目名称:duality,代码行数:93,代码来源:TilemapCollider.cs

示例5: GetConvexHull

        /// <summary>
        /// Identifies the indices of points in a set which are on the outer convex hull of the set.
        /// </summary>
        /// <param name="points">List of points in the set.</param>
        /// <param name="indices">List of indices composing the triangulated surface of the convex hull.
        /// Each group of 3 indices represents a triangle on the surface of the hull.</param>
        public static void GetConvexHull(RawList<Vector3> points, RawList<int> indices)
        {
            //Points is what will be used as a vertex buffer.
            var outsidePoints = Resources.GetIntList();
            var edges = Resources.GetIntList();

            var toRemove = Resources.GetIntList();
            //Populate the outside points
            for (int k = 0; k < points.Count; k++)
            {
                outsidePoints.Add(k);
            }
            //Find an initial tetrahedron
            var initialTetrahedron = Resources.GetIntList();
            /*float volume = 0;
            Random random = new Random();
            Vector3 dir;
            int count = 0;


            while (initialTetrahedron.Count != 4 && count < 100)
            {
                dir = new Vector3((float)random.NextDouble() - .5f, (float)random.NextDouble() - .5f, (float)random.NextDouble() - .5f);
                getExtremePointOfSet(dir, outsidePoints, points, out maxIndex);
                if(!initialTetrahedron.Contains(maxIndex))
                    initialTetrahedron.Add(maxIndex);
                if (initialTetrahedron.Count == 4)
                {
                    //(a-d) * ((b-d)x(c-d)
                    volume = Vector3.Dot(Vector3.Cross(points[initialTetrahedron[1]] - points[initialTetrahedron[3]], points[initialTetrahedron[2]] - points[initialTetrahedron[3]]), points[initialTetrahedron[0]] - points[initialTetrahedron[3]]);
                    if (Math.Abs(volume) < epsilon)
                        initialTetrahedron.RemoveAt(3);
                }
                count++;

            }*/
            int min, max;
            GetExtremePointsOfSet(Vector3.Up, points, out min, out max);
            if (min == max)
                throw new ArgumentException("Point set is degenerate.");
            initialTetrahedron.Add(min);
            initialTetrahedron.Add(max);
            Vector3 direction = NoVector;
            for (int i = 0; i < points.Count; i++)
            {
                if (i != min && i != max)
                {
                    direction = Vector3.Cross(points[min] - points[i], points[max] - points[i]);
                    if (direction.LengthSquared() > BigEpsilon)
                    {
                        break;
                    }
                }
            }
            float minDistance, maxDistance;
            float lineMin = Vector3.Dot(direction, points[min]);
            GetExtremePointsOfSet(direction, points, out min, out max, out minDistance, out maxDistance);

            if (Math.Abs(minDistance - lineMin) < BigEpsilon)
            {
                if (Math.Abs(maxDistance - lineMin) < BigEpsilon)
                {
                    throw new ArgumentException("Point set is degenerate.");
                }
                initialTetrahedron.Add(max);
            }
            else
            {
                initialTetrahedron.Add(min);
            }

            direction = Vector3.Cross(points[initialTetrahedron[1]] - points[initialTetrahedron[0]], points[initialTetrahedron[2]] - points[initialTetrahedron[0]]);

            lineMin = Vector3.Dot(direction, points[initialTetrahedron[0]]);
            GetExtremePointsOfSet(direction, points, out min, out max, out minDistance, out maxDistance);

            if (Math.Abs(minDistance - lineMin) < BigEpsilon)
            {
                if (Math.Abs(maxDistance - lineMin) < BigEpsilon)
                {
                    throw new ArgumentException("Point set is degenerate.");
                }
                initialTetrahedron.Add(max);
            }
            else
            {
                initialTetrahedron.Add(min);
            }


            //Add initial tetrahedron triangles to indices list, remove from outside points, and remove all interior points from outside points.
            if (initialTetrahedron.Count == 4)
            {
                indices.Add(initialTetrahedron[0]);
//.........这里部分代码省略.........
开发者ID:VICOGameStudio-Ujen,项目名称:igf,代码行数:101,代码来源:Toolbox.cs

示例6: MaintainEdge

 private static void MaintainEdge(int a, int b, RawList<int> edges)
 {
     bool contained = false;
     int index = 0;
     for (int k = 0; k < edges.Count; k += 2)
     {
         if ((edges[k] == a && edges[k + 1] == b) || (edges[k] == b && edges[k + 1] == a))
         {
             contained = true;
             index = k;
         }
     }
     //If it isn't present, add it to the edge list.
     if (!contained)
     {
         edges.Add(a);
         edges.Add(b);
     }
     else
     {
         //If it is present, that means both edge-connected triangles were deleted now, so get rid of it.
         edges.RemoveAt(index);
         edges.RemoveAt(index);
     }
 }
开发者ID:VICOGameStudio-Ujen,项目名称:igf,代码行数:25,代码来源:Toolbox.cs


注:本文中的RawList.RemoveAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。