예제 #1
0
        /// <summary>
        /// Toggles the start side of a polygon.
        /// </summary>
        public void ToggleStartSide()
        {
            // Get first view model point
            PolygonPointViewModel point1 = PointCollection[0];

            // Remove the first view model point
            PointCollection.Remove(point1);

            // Add the point to the end of the point collection
            PointCollection.Add(point1);

            // Get the first model point
            PolygonPoint pt1 = Polygon.Points[0];

            // Remove the first model point
            Polygon.Points.Remove(pt1);

            // Add the point to the end of the point collection
            Polygon.Points.Add(pt1);

            // Update the green line segment
            Segments[0]       = new LineSegmentViewModel(PointCollection[0], PointCollection[1]);
            Segments[0].Color = Colors.Lime;

            // Tell the view to refresh
            NotifyPointCollectionChanged();
        }
예제 #2
0
 //Removes that latest input incase of user input error
 private void Undo_Button_Click(object sender, RoutedEventArgs e)
 {
     if (PointListView.SelectedItems != null && PointListView.SelectedItem != null)
     {
         pointsCollection.Remove((Point)PointListView.SelectedItem);
         points.Remove((Point)PointListView.SelectedItem);
     }
 }
예제 #3
0
 public void UpdateLastPoint(Point point)
 {
     if (_points.Count > 1)
     {
         _points.Remove(_points.LastOrDefault());
     }
     AddPoint(point);
 }
예제 #4
0
        /// <summary>
        /// Deletes the specified polygon point.
        /// </summary>
        public void DeletePoint(PolygonPointViewModel pt)
        {
            // Remove the point from the polygon
            PointCollection.Remove(pt);
            Polygon.Points.Remove(pt.PolygonPoint);

            // Update the green line segment
            Segments[0]       = new LineSegmentViewModel(PointCollection[0], PointCollection[1]);
            Segments[0].Color = Colors.Lime;

            // Raise the collection Property changed event so that the converters in the view run
            NotifyPointCollectionChanged();
        }
예제 #5
0
        /// <summary>
        /// Adds the specified point to the point collection.
        /// </summary>
        /// <param name="position">Position of the new point</param>
        public override void AddPoint(Point position)
        {
            // Create the new model point
            PolygonPoint modelPoint = new PolygonPoint();

            // Add the model point to the model's point collection
            Polygon.Points.Add(modelPoint);

            // Create the new view model point
            PolygonPointViewModel viewModelPoint = new PolygonPointViewModel(modelPoint, this);

            // Initialize the position of the point
            viewModelPoint.X = position.X;
            viewModelPoint.Y = position.Y;

            // Add the point to the view model point collection
            PointCollection.Add(viewModelPoint);

            // If there are at least two points on the polygon then...
            if (PointCollection.Count > 1)
            {
                // Create a segment between the points
                LineSegmentViewModel segment =
                    new LineSegmentViewModel(
                        viewModelPoint,
                        PointCollection[PointCollection.Count - 2]);

                // Add the segment
                Segments.Add(segment);
            }

            // If there are two or more points then...
            if (PointCollection.Count >= 2)
            {
                // If the mouse is over the first polygon point then...
                if (IsMouseOverFirstPolygonPoint(position))
                {
                    // Remove the last point since we are going to connect up to the first point
                    PointCollection.Remove(PointCollection[PointCollection.Count - 1]);
                    Polygon.Points.Remove(Polygon.Points[Polygon.Points.Count - 1]);

                    // Make the WPF polygon visible
                    ClosePolygon();
                }
            }
        }
예제 #6
0
        // 对输入的两点及其上点集执行递归算法,找到最远点,根据围成的三角形分类点,生成两条边,对每条边极其上方的点集再次执行本递归算法
        private int FindSubHull(PointCollection points, Point pointLeft, Point pointRight)
        {
            if (points.Count == 0)
            {
                return(1);
            }
            int   totalCommandCount = 0;
            Point pointFarthest     = FindFarthestPoint(points, pointLeft, pointRight, out int commandCount);

            totalCommandCount += commandCount;
            ChangeToVertex(pointFarthest, pointsVertex.IndexOf(pointLeft) + 1);
            totalCommandCount += 3;
            historyLines.Add(GetLines(pointsVertex, out commandCount));
            totalCommandCount += commandCount;
            points.Remove(pointFarthest);
            totalCommandCount++;

            PointCollection points1 = new PointCollection();
            PointCollection points2 = new PointCollection();

            foreach (Point point in points)
            {
                int deter1 = CalDeter(pointLeft, pointFarthest, point);
                int deter2 = CalDeter(pointFarthest, pointRight, point);
                totalCommandCount += 2;
                if (deter1 > 0)
                {
                    points1.Add(point);
                    totalCommandCount++;
                }
                else if (deter2 > 0)
                {
                    points2.Add(point);
                    totalCommandCount++;
                }
                else    // 三角形内
                {
                    ChangeToInternal(point);
                    totalCommandCount += 2;;
                }
            }
            totalCommandCount += FindSubHull(points1, pointLeft, pointFarthest);
            totalCommandCount += FindSubHull(points2, pointFarthest, pointRight);
            return(totalCommandCount);
        }
예제 #7
0
        /// <summary>
        /// Toggles the start side of a polygon.
        /// </summary>
        public void ToggleStartSide()
        {
            // Get first view model point
            PolygonPointViewModel point1 = PointCollection[0];

            // Remove the first view model point
            PointCollection.Remove(point1);

            // Add the point to the end of the point collection
            PointCollection.Add(point1);

            // Get the first model point
            PolygonPoint pt1 = Ellipse.Points[0];

            // Remove the first model point
            Ellipse.Points.Remove(pt1);

            // Add the point to the end of the point collection
            Ellipse.Points.Add(pt1);

            // Increment the start side
            Ellipse.StartSideRotation++;

            // If we are past the last side then...
            if (Ellipse.StartSideRotation > 3)
            {
                // Wrap around to the first side
                Ellipse.StartSideRotation = 0;
            }

            // Update the green line segment
            Segments[0]       = new LineSegmentViewModel(PointCollection[0], PointCollection[1]);
            Segments[0].Color = Colors.Lime;

            // Force the view converters to run
            NotifyPointCollectionChanged();
        }
예제 #8
0
        private void PointCollectionOperations(object sender, SelectionChangedEventArgs e)
        {
            RadioButton li = (sender as RadioButton);

            // Strings used to display the results
            String syntaxString, resultType, operationString;

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
            switch (li.Name)
            {   //begin switch
            case "rb1":
            {
                //<SnippetPointCollectionAdd>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating an array of Points to the points
                Point[] pointArray = new Point[3];

                // Adding points to array
                pointArray[0] = point1;
                pointArray[1] = point2;
                pointArray[2] = point3;

                // Instantiating a PointCollection and initializing with an array
                PointCollection pointCollection1 = new PointCollection(pointArray);

                //  Adding a point to the PointCollection
                pointCollection1.Add(point4);

                // pointCollection1 is equal to (10,10 20,20 30,30 40,40)

                //</SnippetPointCollectionAdd>



                break;
            }

            case "rb2":
            {
                //<SnippetPointCollectionClear>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // clearing the PointCollection
                pointCollection1.Clear();

                // pointCollection1 is now empty

                //</SnippetPointCollectionClear>

                break;
            }

            case "rb3":
            {
                //<SnippetPointCollectionContains>

                Boolean inCollection;

                // Instantiating and Initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                inCollection = pointCollection1.Contains(point4);

                // inCollection is equal to False

                //</SnippetPointCollectionContains>

                break;
            }

            case "rb4":
            {
                //<SnippetPointCollectionIndexOf>

                int pIndex;

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);
                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Getting the index of a Point
                pIndex = pointCollection1.IndexOf(point2);

                // pointIndex is equal to 1

                //</SnippetPointCollectionIndexOf>

                break;
            }

            case "rb5":
            {
                //<SnippetPointCollectionInsert>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Inserting a Point into the PointCollection
                pointCollection1.Insert(1, point4);

                // pointCollection1 is now equal to (10,10 40,40 20,20 30,30

                //</SnippetPointCollectionInsert>

                break;
            }

            case "rb6":
            {
                //<SnippetPointCollectionRemove>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Removing a Point from the PointCollection
                pointCollection1.Remove(point2);

                // pointCollection1 is equal to 10,10 30,30

                //</SnippetPointCollectionRemove>

                break;
            }

            case "rb7":
            {
                //<SnippetPointCollectionRemoveAt>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Removing a range of Points
                pointCollection1.RemoveAt(1);

                // pointCollection1 is equal to (10,10 30,30)

                //</SnippetPointCollectionRemoveAt>

                break;
            }

            case "rb8":
            {
                //<SnippetPointCollectionToString>
                string pcString;

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Getting a string representation of the PointCollection
                pcString = pointCollection1.ToString();


                // pcString is equal to "10,10 20,20 30,30"

                //</SnippetPointCollectionToString>


                break;
            }

            case "rb9":
            {
                break;
            }

            case "rb10":
            {
                break;
            }

            case "rb11":
            {
                break;
            }

            case "rb12":
            {
                break;
            }
            } //end switch
        }
예제 #9
0
 // 设定点为内部点
 private void ChangeToInternal(Point point)
 {
     pointsUnknown.Remove(point);
     pointsInternal.Add(point);
 }