Пример #1
0
        private void findMidPoint(int x, int y)
        {
            if (x <= Panel1.Width || y <= Panel1.Height)
            {
                if (pairs() >= 4)
                {
                    PointSet tempNorth = new PointSet();
                    PointSet tempSouth = new PointSet();
                    PointSet tempEast = new PointSet();
                    PointSet tempWest = new PointSet();
                    System.Drawing.Point temp = new System.Drawing.Point(x, y);
                    PointSet tempSet = new PointSet();
                    tempSet.points.AddRange(North.points);
                    //North.points.Clear();
                    foreach (Point point in tempSet.points)
                    {
                        if (point.x > 0 && point.x < temp.X)
                        {
                            //west
                            if (point.y > 0 && point.y < temp.Y)
                            {
                                tempNorth.add(point);
                            }
                            else
                            {
                                tempWest.add(point);
                            }
                        }
                        else
                        {
                            //east
                            if (point.y > 0 && point.y < temp.Y)
                            {
                                tempEast.add(point);
                            }
                            else
                            {
                                tempSouth.add(point);
                            }
                        }
                    }
                    double distancePointsNorth = ClosestPairDQ(tempNorth);
                    double distancePointsSouth = ClosestPairDQ(tempSouth);
                    double distancePointsEast = ClosestPairDQ(tempEast);
                    double distancePointsWest = ClosestPairDQ(tempWest);

                    if (SameColor(tempNorth) && SameColor(tempEast) && SameColor(tempSouth) && SameColor(tempWest))
                    {

                        if (!Double.IsInfinity(distancePointsEast) && !Double.IsInfinity(distancePointsNorth)
                            && !Double.IsInfinity(distancePointsSouth) && !Double.IsInfinity(distancePointsWest))
                        {
                            isSplit = temp;
                            Graphics g = Panel1.CreateGraphics();
                            Pen p = new Pen(Color.Black);
                            g.DrawLine(p, 0, isSplit.Y, isSplit.X, isSplit.Y);
                            g.DrawLine(p, isSplit.X, 0, isSplit.X, isSplit.Y);
                            g.DrawLine(p, isSplit.X, isSplit.Y, isSplit.X, Panel1.Height);
                            g.DrawLine(p, isSplit.X, isSplit.Y, Panel1.Width, isSplit.Y);
                            tempSet.points.Clear();
                            tempSet.points.AddRange(North.points);
                            North.points.Clear();
                            foreach (Point point in tempSet.points)
                            {
                                if (point.x > 0 && point.x < isSplit.X)
                                {
                                    //west
                                    if (point.y > 0 && point.y < isSplit.Y)
                                    {
                                        North.add(point);
                                    }
                                    else
                                    {
                                        West.add(point);
                                    }
                                }
                                else
                                {
                                    //east
                                    if (point.y > 0 && point.y < isSplit.Y)
                                    {
                                        East.add(point);
                                    }
                                    else
                                    {
                                        South.add(point);
                                    }
                                }
                            }
                        }
                        else
                        {
                            System.Drawing.Point point;
                            if (tempEast.points.Count > tempNorth.points.Count)
                            {
                                if (tempEast.points.Count > tempSouth.points.Count)
                                {
                                    if (tempEast.points.Count > tempWest.points.Count)
                                        point = findAverage(tempEast, temp);
                                    else
                                        point = findAverage(tempWest, temp);
                                }
                                else if (tempSouth.points.Count > tempWest.points.Count)
                                    point = findAverage(tempSouth, temp);
                                else
                                    point = findAverage(tempWest, temp);
                            }
                            else if (tempNorth.points.Count > tempSouth.points.Count)
                            {
                                if (tempNorth.points.Count > tempWest.points.Count)
                                    point = findAverage(tempNorth, temp);
                                else
                                    point = findAverage(tempWest, temp);
                            }
                            else if (tempSouth.points.Count > tempWest.points.Count)
                            {
                                point = findAverage(tempSouth, temp);
                            }
                            else
                            {
                                point = findAverage(tempWest, temp);
                            }
                            findMidPoint(point.X, point.Y);
                        }
                    }
                    else
                    {
                        //niet dezelfde kleur
                    }
                }
                else
                {
                    //niet genoeg paren
                }
            }
            else
            {
                //niet gevonden
            }
        }
Пример #2
0
 // returns a subset of containing the elements of S from fromIndex to
 // toIndex inclusive
 public PointSet subSet(PointSet S, int fromIndex, int toIndex)
 {
     PointSet T = new PointSet();
     for (int i = fromIndex; i <= toIndex; i++)
     {
         T.add(S.pointAt(i));
     }
     return T;
 }