Beispiel #1
0
        public static Gesture_Event_Sorting_Group Detect(List <My_Point> points, Gesture_Controler controler)
        {
            List <My_Point>             result            = new List <My_Point>();
            Gesture_Event_Grouping      resturedCluster   = null;
            Gesture_Event_Sorting_Group sortingGroupEvent = null;

            foreach (My_Point p in points)
            {
                if (p.Sender is Menu_Sort_Box)
                {
                    foreach (Gesture_Event gesture in Gesture_List.GestureList)
                    {
                        if (gesture is Gesture_Event_Grouping)
                        {
                            Gesture_Event_Grouping cluster = gesture as Gesture_Event_Grouping;
                            if (cluster.IsGrouping())
                            {
                                My_Point[] clusterPoints = cluster.Points;
                                if (Enclose_Helper.PNPoly(clusterPoints, p.CurrentPoint.Position.X, p.CurrentPoint.Position.Y))
                                {
                                    resturedCluster = cluster;
                                    result.Add(p);
                                    foreach (My_Point clusterPoint in clusterPoints)
                                    {
                                        result.Add(clusterPoint);
                                    }
                                    My_Point[] argPoints = result.ToArray();
                                    object[]   objects   = new object[cluster.Senders.Length + 1];
                                    objects[0] = cluster.Points[0].Sender;
                                    for (int i = 0; i < cluster.Senders.Length; i++)
                                    {
                                        objects[i + 1] = cluster.Senders[i];
                                    }
                                    sortingGroupEvent        = new Gesture_Event_Sorting_Group();
                                    sortingGroupEvent.Points = cluster.Points;
                                    Gesture_List.addGesture(sortingGroupEvent);
                                    Gesture_SortingGroup_Listener listener = new Gesture_SortingGroup_Listener(controler, sortingGroupEvent);
                                    sortingGroupEvent.Register(objects, argPoints);
                                }
                            }
                        }
                    }
                }
            }
            if (resturedCluster != null)
            {
                Gesture_List.removeGesture(resturedCluster);
                controler.Control.MainWindow.GroupingGestureLayer.Remove(resturedCluster);
                foreach (My_Point p in result)
                {
                    points.Remove(p);
                }
                return(sortingGroupEvent);
            }
            return(null);
        }
        public static Gesture_Event_Grouping Detect(List <My_Point> points, Gesture_Controler controler)
        {
            List <My_Point> result = new List <My_Point>();

            if (points.Count == 4)
            {
                foreach (My_Point p in points)
                {
                    if (p.Sender is Card_Layer)
                    {
                        result.Add(p);
                    }
                }
            }
            if (result.Count == 4)
            {
                My_Point[] argPoints = result.ToArray();
                Card[]     cards     = Card_List.CardList.ToArray();
                My_Point[] Newpoint  = new My_Point[4];
                for (int i = 0; i < 4; i++)
                {
                    Newpoint[i] = argPoints[i];
                }
                double maxX_1 = Math.Max(Math.Min(Newpoint[0].CurrentPoint.Position.X, Newpoint[1].CurrentPoint.Position.X), Math.Min(Newpoint[2].CurrentPoint.Position.X, Newpoint[3].CurrentPoint.Position.X));
                double maxX_2 = Math.Min(Math.Max(Newpoint[0].CurrentPoint.Position.X, Newpoint[1].CurrentPoint.Position.X), Math.Max(Newpoint[2].CurrentPoint.Position.X, Newpoint[3].CurrentPoint.Position.X));
                double maxY_1 = Math.Max(Math.Min(Newpoint[0].CurrentPoint.Position.Y, Newpoint[1].CurrentPoint.Position.Y), Math.Min(Newpoint[2].CurrentPoint.Position.Y, Newpoint[3].CurrentPoint.Position.Y));
                double maxY_2 = Math.Min(Math.Max(Newpoint[0].CurrentPoint.Position.Y, Newpoint[1].CurrentPoint.Position.Y), Math.Max(Newpoint[2].CurrentPoint.Position.Y, Newpoint[3].CurrentPoint.Position.Y));
                double midX   = (maxX_1 + maxX_2) / 2;
                double midY   = (maxY_1 + maxY_2) / 2;

                My_Point[] orderedPoints = new My_Point[4];
                int        count1        = 0;
                int        count2        = 0;
                int        count3        = 0;
                int        count4        = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (Newpoint[i].CurrentPoint.Position.X > midX && Newpoint[i].CurrentPoint.Position.Y <= midY)
                    {
                        count1++;
                    }
                    if (Newpoint[i].CurrentPoint.Position.X <= midX && Newpoint[i].CurrentPoint.Position.Y < midY)
                    {
                        count2++;
                    }
                    if (Newpoint[i].CurrentPoint.Position.X < midX && Newpoint[i].CurrentPoint.Position.Y >= midY)
                    {
                        count3++;
                    }
                    if (Newpoint[i].CurrentPoint.Position.X >= midX && Newpoint[i].CurrentPoint.Position.Y > midY)
                    {
                        count4++;
                    }
                }
                if (count1 > 1 || count2 > 1 || count3 > 1 || count4 > 1)
                {
                    if (count1 > 1)
                    {
                        int countIndexRight1 = 0;
                        int countIndexRight2 = 0;
                        for (int i = 0; i < 4; i++)
                        {
                            if (Newpoint[i].CurrentPoint.Position.X > midX && Newpoint[i].CurrentPoint.Position.Y <= midY)
                            {
                                countIndexRight1++;
                                if (countIndexRight1 > 1)
                                {
                                    if (Newpoint[i].CurrentPoint.Position.X < orderedPoints[0].CurrentPoint.Position.X)
                                    {
                                        orderedPoints[1] = argPoints[i];
                                    }
                                    else
                                    {
                                        orderedPoints[1] = orderedPoints[0];
                                        orderedPoints[0] = argPoints[i];
                                    }
                                    break;
                                }
                                orderedPoints[0] = argPoints[i];
                            }
                        }
                        double disRight = 0;
                        for (int i = 0; i < 4; i++)
                        {
                            if (Newpoint[i].CurrentPoint.Position.X < midX && Newpoint[i].CurrentPoint.Position.Y >= midY)
                            {
                                countIndexRight2++;
                                if (countIndexRight2 > 1)
                                {
                                    double temp = Math.Pow((Newpoint[i].CurrentPoint.Position.X - orderedPoints[1].CurrentPoint.Position.X), 2) + Math.Pow((Newpoint[i].CurrentPoint.Position.Y - orderedPoints[1].CurrentPoint.Position.Y), 2);
                                    if (temp > disRight)
                                    {
                                        orderedPoints[3] = argPoints[i];
                                    }
                                    else
                                    {
                                        orderedPoints[3] = orderedPoints[2];
                                        orderedPoints[2] = argPoints[i];
                                    }
                                    break;
                                }
                                orderedPoints[2] = argPoints[i];
                                disRight         = Math.Pow((Newpoint[i].CurrentPoint.Position.X - orderedPoints[1].CurrentPoint.Position.X), 2) + Math.Pow((Newpoint[i].CurrentPoint.Position.Y - orderedPoints[1].CurrentPoint.Position.Y), 2);
                            }
                        }
                    }
                    else if (count2 > 1)
                    {
                        int countIndexLeft1 = 0;
                        int countIndexLeft2 = 0;
                        for (int i = 0; i < 4; i++)
                        {
                            if (Newpoint[i].CurrentPoint.Position.X <= midX && Newpoint[i].CurrentPoint.Position.Y < midY)
                            {
                                countIndexLeft1++;
                                if (countIndexLeft1 > 1)
                                {
                                    if (Newpoint[i].CurrentPoint.Position.X < orderedPoints[0].CurrentPoint.Position.X)
                                    {
                                        orderedPoints[1] = argPoints[i];
                                    }
                                    else
                                    {
                                        orderedPoints[1] = orderedPoints[0];
                                        orderedPoints[0] = argPoints[i];
                                    }
                                    break;
                                }
                                orderedPoints[0] = argPoints[i];
                            }
                        }
                        double disLeft = 0;
                        for (int i = 0; i < 4; i++)
                        {
                            if (Newpoint[i].CurrentPoint.Position.X >= midX && Newpoint[i].CurrentPoint.Position.Y > midY)
                            {
                                countIndexLeft2++;
                                if (countIndexLeft2 > 1)
                                {
                                    double temp = Math.Pow((Newpoint[i].CurrentPoint.Position.X - orderedPoints[1].CurrentPoint.Position.X), 2) + Math.Pow((Newpoint[i].CurrentPoint.Position.Y - orderedPoints[1].CurrentPoint.Position.Y), 2);
                                    if (temp > disLeft)
                                    {
                                        orderedPoints[3] = argPoints[i];
                                    }
                                    else
                                    {
                                        orderedPoints[3] = orderedPoints[2];
                                        orderedPoints[2] = argPoints[i];
                                    }
                                    break;
                                }
                                orderedPoints[2] = argPoints[i];
                                disLeft          = Math.Pow((Newpoint[i].CurrentPoint.Position.X - orderedPoints[1].CurrentPoint.Position.X), 2) + Math.Pow((Newpoint[i].CurrentPoint.Position.Y - orderedPoints[1].CurrentPoint.Position.Y), 2);
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (Newpoint[i].CurrentPoint.Position.X > midX && Newpoint[i].CurrentPoint.Position.Y < midY)
                        {
                            orderedPoints[0] = argPoints[i];
                        }
                        else if (Newpoint[i].CurrentPoint.Position.X < midX && Newpoint[i].CurrentPoint.Position.Y < midY)
                        {
                            orderedPoints[1] = argPoints[i];
                        }
                        else if (Newpoint[i].CurrentPoint.Position.X <midX && Newpoint[i].CurrentPoint.Position.Y> midY)
                        {
                            orderedPoints[2] = argPoints[i];
                        }
                        else if (Newpoint[i].CurrentPoint.Position.X > midX && Newpoint[i].CurrentPoint.Position.Y > midY)
                        {
                            orderedPoints[3] = argPoints[i];
                        }
                    }
                }
                List <Card> objects = new List <Card>();
                lock (cards)
                {
                    foreach (Card c in cards)
                    {
                        if (Enclose_Helper.PNPoly(orderedPoints, c.CurrentPosition.X, c.CurrentPosition.Y))
                        {
                            objects.Add(c);
                        }
                    }
                }

                if (objects.Count > 0)
                {
                    Gesture_Event_Grouping gestureEvent = new Gesture_Event_Grouping();
                    gestureEvent.Points  = orderedPoints;
                    gestureEvent.Senders = objects.ToArray();
                    Gesture_List.addGesture(gestureEvent);
                    Gesture_Grouping_Listener gestureListener = new Gesture_Grouping_Listener(controler, gestureEvent);
                    gestureEvent.Register(objects.ToArray(), orderedPoints);
                    foreach (My_Point p in result)
                    {
                        points.Remove(p);
                    }
                    return(gestureEvent);
                }
                return(null);
            }
            else
            {
                return(null);
            }
        }