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


C# Point.OrderBy方法代码示例

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


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

示例1: Reorder

        public override void Reorder()
        {
            Point[] array = new Point[] { Start, Stop, StartI, StopI };

            array = array.OrderBy (p => p.X).ThenBy (p => p.Y).ToArray ();
            Start = array [0];
            Stop = array [3];
        }
开发者ID:GNOME,项目名称:longomatch,代码行数:8,代码来源:Cross.cs

示例2: Question9_Two_Dimension_Sort

 public void Question9_Two_Dimension_Sort()
 {
     Point[] input = new Point[] {new Point(56, 90), new Point(60, 95),  new Point(65, -10), new Point(68, 99),
         new Point(69, 110), new Point(70, 100), new Point(75, 0), new Point(76, 180)};
     // step 1, sort by X
     input = input.OrderBy(p => p.X).ToArray();
     // step 2, get the longest increasing subsequence (LIS) in the array, compare Y
     int[] L = new int[input.Length]; // L[i] stores the LIS.length, from input[0] to input[i], LIS ends with input[i]
     // L[0] = 1, L[i] = max(L[k] + 1, 1)  when 0 <= k < i, input[k] < input[i]
     L[0] = 1;
     for (int i = 1; i < input.Length; i++)
     {
         L[i] = 1; // if before data[i], all the element is larger than data[i], the LIS ends with data[i]'s length is only 1
         for (int j = 0; j < i; j++)
         {
             if (input[i].Y > input[j].Y)
             {
                 L[i] = Math.Max(L[i], L[j] + 1);
             }
         }
     }
     // output: now we get a L[input.lenght] result, reverse enumerate
     int max = L.Max();
     for (int i = input.Length - 1; i >= 0; i--)
     {
         if (L[i] == max)
         {
             Console.WriteLine(input[i]);
             max--;
         }
     }
 }
开发者ID:xisuogu,项目名称:CareerCup,代码行数:32,代码来源:AppliedMath.cs

示例3: phi

 void phi()
 {
     Point[] points_in_new_coord_where_Q_center = new Point[n];
     int qx = Q.Value.X, qy = Q.Value.Y;
     for (int i = 0; i < n; ++i)
         points_in_new_coord_where_Q_center[i] = new Point(points_arr[i].X - qx, points_arr[i].Y - qy);
     double [] phi_arr = new double[n];
     for (int i = 0; i < n; ++i)
     {
         int x = points_in_new_coord_where_Q_center[i].X, y = points_in_new_coord_where_Q_center[i].Y;
         double r = Math.Sqrt(x*x + y*y);
         phi_arr[i] = Math.Asin(y)/r;
     }
     IEnumerable<Point> sort_enum_phi_arr;//
     Point [] sort_phi_arr = new Point[n];
     sort_enum_phi_arr = points_in_new_coord_where_Q_center.OrderBy(p => acos((p.X)/Math.Sqrt(p.X * p.X + p.Y * p.Y), p));
     sort_phi_arr = sort_enum_phi_arr.ToArray();
 }
开发者ID:junkissa,项目名称:Convex-hull,代码行数:18,代码来源:Form1.cs

示例4: Point

        private void Ендрю_Джавірса_Click(object sender, EventArgs e)
        {
            if (n < 2)
            {
                label1.Text = "Введіть більше точок";
                return;
            }
            label1.Text = "";

            Point[] x_arr = new Point[n];
            IEnumerable<Point> x_sort_enum;
            Point[] x_sort;
            for (int i = 0; i < n; ++i)
                x_arr[i] = new Point(points_arr[i].X, points_arr[i].Y);
            x_sort_enum = x_arr.OrderBy(p => p.X);
            x_sort = x_sort_enum.ToArray();
            Point left = new Point(x_sort[0].X, x_sort[0].Y);
            Point right = new Point(x_sort[n-1].X, x_sort[n-1].Y);
            int n_up = 0, n_down = 0;
            Point[] up = new Point[n];
            Point[] down = new Point[n];
            int iup = 0, idown = 0;

            up[iup++] = new Point(left.X, left.Y);
            down[idown++] = new Point(left.X, left.Y);
            // верхний и нижний массивы
            foreach (Point p in x_sort)
            {
            if(point_is_left_AB(left, right, p))
                up[iup++] = new Point(p.X, p.Y);
            else if(point_is_right_AB(left, right, p))
                down[idown++] = new Point(p.X, p.Y);
            }
            up[iup++] = new Point(right.X, right.Y);
            down[idown++] = new Point(right.X, right.Y);
            bool[] in_ob_up = new bool[iup];
            bool[] in_ob_down = new bool[idown];
            in_ob_up.Initialize();
            in_ob_down.Initialize();
            in_ob_up[0] = true;
            in_ob_up[iup - 1] = true;
            in_ob_down[0] = true;
            in_ob_down[idown - 1] = true;
            // обработка верхнего
            for (int i = 0; i < iup - 1;)
            {
                int index_of_max_angle = index_max_angle_up(iup, up, i);
                in_ob_up[index_of_max_angle] = true;
                i = index_of_max_angle;
            }
             //обработка нижнего массива
            for (int i = 0; i < idown - 1;)
            {
                int index_of_max_angle = index_max_angle_down(idown, down, i);
                in_ob_down[index_of_max_angle] = true;
                i = index_of_max_angle;
            }

            // рисуем
            Draw();
            Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE);
            Gl.glBegin(Gl.GL_POLYGON);
            Gl.glColor3d(1, 0, 0);
            for (int i = 0; i < iup; ++i)
            {
                if(in_ob_up[i])
                    Gl.glVertex2d(up[i].X, up[i].Y);
            }

            Gl.glColor3d(0, 0, 1);
            for (int i = idown - 1; i >= 0; --i)
            {
                if (in_ob_down[i])
                    Gl.glVertex2d(down[i].X, down[i].Y);
            }
            Gl.glEnd();
            AnT.Invalidate();
            Gl.glFlush();
                return;
        }
开发者ID:junkissa,项目名称:Convex-hull,代码行数:80,代码来源:Form1.cs

示例5: button2_Click

        // алгоритм Грехема
        private void button2_Click(object sender, EventArgs e)
        {
            if (n < 2)
            {
                label1.Text = "Введіть більше точок";
                return;
            }
            label1.Text = "";

            if (!Q.HasValue)
            {
                label1.Text = "Задайте внутрішню точку (правою кнопкою миші)";
                return;
            }
            //polar_sort
            // сортировка по полярному углу относительно точки Q
            Point[] points_in_new_coord_where_Q_center = new Point[n];
            int qx = Q.Value.X, qy = Q.Value.Y;
            for (int i = 0; i < n; ++i)
                points_in_new_coord_where_Q_center[i] = new Point(points_arr[i].X - qx, points_arr[i].Y - qy);
            double[] phi_arr = new double[n];
            for (int i = 0; i < n; ++i)
            {
                int x = points_in_new_coord_where_Q_center[i].X, y = points_in_new_coord_where_Q_center[i].Y;
                double r = Math.Sqrt(x*x + y*y);
                phi_arr[i] = Math.Asin(y)/r;
            }
            IEnumerable<Point> sort_enum_phi_arr;//
            Point[] sort_phi_arr = new Point[n];
            sort_enum_phi_arr = points_in_new_coord_where_Q_center.OrderBy(p => acos((p.X)/Math.Sqrt(p.X * p.X + p.Y * p.Y), p));
            sort_phi_arr = sort_enum_phi_arr.ToArray();

            // end_polar_sort
            Point[] sort_points_arr = new Point[n];
            for (int i = 0; i < n; ++i)
                sort_points_arr[i] = new Point(sort_phi_arr[i].X + qx, sort_phi_arr[i].Y + qy);

            bool[] is_ob = new bool[n];
            is_ob.Initialize();
            is_ob[0] = true;
            is_ob[1] = true;
            bool for_exit = false;
            for (int i = 2; i < n; ++i)
            {
                is_ob[i] = true;
                for (int j = i - 1; j > 0; --j)
                    if (is_ob[j])
                    {
                        for (int k = j - 1; k >= 0; --k)
                            if (is_ob[k])
                            {
                                for_exit = false;
                                if (point_is_left_AB(sort_points_arr[k], sort_points_arr[i], sort_points_arr[j]))
                                {
                                    is_ob[j] = false;
                                    for_exit = false;
                                }
                                else
                                    for_exit = true;
                                break;
                            }
                        if (for_exit)
                            break;
                    }
            }
             //для последней точки (замыкающей)
            int last_in_ob = 0;
            for (int i = n - 2; i > 0; --i)
            {
                if (is_ob[i])
                {
                    if (point_is_left_AB(sort_points_arr[i], sort_points_arr[0], sort_points_arr[n-1]))
                        is_ob[n-1] = false;
                    last_in_ob = i;
                    break;
                }
            }

            for (int i = 1; i < n; ++i)
            {
                {
                    if (is_ob[i])
                        if (point_is_left_AB(sort_points_arr[last_in_ob], sort_points_arr[i], sort_points_arr[0]))
                            is_ob[0] = false;
                    break;
                }
            }

                Draw();
            Gl.glColor3d(0, 0, 1);
            Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE);
            Gl.glBegin(Gl.GL_POLYGON);
            for (int i = 0; i < n; ++i)
                if (is_ob[i])
                Gl.glVertex2d(sort_points_arr[i].X, sort_points_arr[i].Y);
            Gl.glEnd();
            for (int i = 0; i < n; ++i)
            {

//.........这里部分代码省略.........
开发者ID:junkissa,项目名称:Convex-hull,代码行数:101,代码来源:Form1.cs


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