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


C# GridVector2.CopyTo方法代码示例

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


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

示例1: Triangulate

        /// <summary>
        /// Generates the delaunay triangulation for a list of points. 
        /// Requires the points to be sorted on the X-axis coordinate!
        /// Every the integers in the returned array are the indicies in the passes array of triangles. 
        /// Implemented based upon: http://local.wasp.uwa.edu.au/~pbourke/papers/triangulate/
        /// "Triangulate: Efficient Triangulation Algorithm Suitable for Terrain Modelling"
        /// by Paul Bourke
        /// </summary>
        public static int[] Triangulate(GridVector2[] points, GridVector2[] BoundingPoints)
        {
            if (BoundingPoints == null)
            {
                throw new ArgumentNullException("BoundingPoints");
            }

            if (points == null)
            {
                throw new ArgumentNullException("points");
            }

            if (points.Length < 3)
                return new int[0];

            #if DEBUG

            //Check to ensure the input is really sorted on the X-Axis
            for (int iDebug = 1; iDebug < points.Length; iDebug++)
            {
                Debug.Assert(points[iDebug - 1].X <= points[iDebug].X);
                Debug.Assert(GridVector2.Distance(points[iDebug - 1], points[iDebug]) >= Global.Epsilon);
            }

            #endif

            List<GridIndexTriangle> triangles = new List<GridIndexTriangle>(points.Length);

            //Safe triangles have a circle with a center.X+radius which is less than the current point.
            //This means they can never intersect with a new point and we never need to test them again.
            List<GridIndexTriangle> safeTriangles = new List<GridIndexTriangle>();

            int iNumPoints = points.Length;
            GridVector2[] allpoints = new GridVector2[iNumPoints + 4];

            points.CopyTo(allpoints, 0);
            BoundingPoints.CopyTo(allpoints, iNumPoints);

            //Initialize bounding triangles
            triangles.AddRange(new GridIndexTriangle[] { new GridIndexTriangle(iNumPoints, iNumPoints + 1, iNumPoints + 2, ref allpoints),
                                                         new GridIndexTriangle(iNumPoints + 1, iNumPoints + 2, iNumPoints + 3, ref allpoints) });

            IndexEdge[] Edges = new IndexEdge[(triangles.Count * 3) * 2];
            for(int iPoint = 0; iPoint < points.Length; iPoint++)
            {
                GridVector2 P = points[iPoint];

                //Use preallocated buffer if we can, otherwise expand it
                int maxEdges = triangles.Count * 3;
                if (Edges.Length < maxEdges)
                    Edges = new IndexEdge[maxEdges * 2];

                int iTri = 0;
                int iEdge = 0;
                while(iTri < triangles.Count)
                {
                    GridIndexTriangle tri = triangles[iTri];
                    GridCircle circle = tri.Circle;
                    if (circle.Contains(P))
                    {
                        Edges[iEdge++] = new IndexEdge(tri.i1, tri.i2);
                        Edges[iEdge++] = new IndexEdge(tri.i2, tri.i3);
                        Edges[iEdge++] = new IndexEdge(tri.i3, tri.i1);

            /*                        Edges.AddRange(new IndexEdge[] {new IndexEdge(tri.i1, tri.i2),
                                                               new IndexEdge(tri.i2, tri.i3),
                                                               new IndexEdge(tri.i3, tri.i1)});
                        */
                        triangles.RemoveAt(iTri);
                    }
                    //Check if the triangle is safe from ever intersecting with a new point again
                    else if (circle.Center.X + circle.Radius + Global.Epsilon < P.X)
                    {
                        safeTriangles.Add(tri);
                        triangles.RemoveAt(iTri);
                    }
                    else
                    {
                        iTri++;
                    }
                }

                //Record how many edges there are
                int numEdges = iEdge;

                //Remove duplicates from edge buffer
                //This is easier with a list, but arrays were faster
                for (int iA = 0; iA < numEdges; iA++)
                {
                    if (Edges[iA].IsValid == false)
                        continue;

//.........这里部分代码省略.........
开发者ID:abordt,项目名称:Viking,代码行数:101,代码来源:Delaunay.cs


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