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


C# Point2D.TakeWhile方法代码示例

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


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

示例1: ConvexHull

        /// <summary>
        /// Implementation of Convex Hull using the Monotone Chain Convex Hull Algorithm.
        /// The algorithm was chosen for implementation due to its simplicity. Chan's
        /// Convex Hull algorithm is a tad more efficient when the output point set
        /// is smaller than the input set.
        /// 
        /// based on http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
        /// </summary>
        /// <param name="input"></param>
        /// <returns>
        /// The convex hull of the points in counterclockwise order (starting from the
        /// rightmost point)
        /// </returns>
        public static Point2D[] ConvexHull(Point2D[] input)
        {
            // sort input by x, then y
             Array.Sort(
            input,
            new LambdaComparer<Point2D>(
               (a, b) => {
                  if (a.X < b.X)
                     return -1;
                  if (a.X > b.X)
                     return 1;

                  return a.Y.CompareTo(b.Y);
               }
            )
             );

             // Initialize upper and lower hull lists
             var h = new Point2D[2 * input.Length];
             int k = 0;

             // build lower hull
             for (int i = 0; i < input.Length; i++)
             {
            while (k >= 2 && Cross(h[k - 2], h[k - 1], input[i]) <= 0)
               k--;
            h[k++] = input[i];
             }

             // build upper hull
             for (int i = input.Length - 2, t = k + 1; i >= 0; i--)
             {
            while (k >= t && Cross(h[k - 2], h[k - 1], input[i]) <= 0)
               k--;
            h[k++] = input[i];
             }
             return h.TakeWhile(x => x != null).ToArray();
        }
开发者ID:ItzWarty,项目名称:AdventuresInShade,代码行数:51,代码来源:GeometryUtilities.cs


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