Esempio n. 1
0
        //Metodo que testa se a proxmia posição for comida
        public bool gotFood()
        {
            if (posição.X == Canvas.GetLeft(food) && posição.Y == Canvas.GetTop(food))
            {
                Task.Run(() => notificationSound.Play());

                Random rnd = new Random();
                Console.WriteLine("Pegou a comida");

                PointCollection d = new PointCollection();
                for (int i = 0; i < rects.Count; i++)
                {
                    d.Add(new Point(Canvas.GetLeft(rects[i]), Canvas.GetTop(rects[i])));
                }
                int rnd1, rnd2;
                //Muda a posição da comida caso não seja dentro da snake
                do
                {
                    rnd1 = rnd.Next(30);
                    rnd2 = rnd.Next(30);
                    Canvas.SetLeft(food, rnd1 * dimension);
                    Canvas.SetTop(food, rnd2 * dimension);
                }while (d.Contains(new Point(rnd1 * dimension, rnd2 * dimension)));

                return(true);
            }
            return(false);
        }
 public static void AssertContains(this PointCollection collection, params double[][] points)
 {
     Assert.AreEqual(points.Length, collection.Count, "Expected to find {0} points in collection", points.Length);
     foreach (var point in points)
     {
         Assert.IsTrue(collection.Contains(new Point(point[0], point[1])), "Expected collection to contain point [{0},{1}]", point[0], point[1]);
     }
 }
        public override bool AddEdge(EdgePointID GraphEdge)
        {
            if (PointCollection.Contains(GraphEdge.StartPoint) && PointCollection.Contains(GraphEdge.EndPoint))
            {
                // Переназначаем вершины графа на те, что точно содержаться в списке графа.
                GraphEdge.StartPoint = PointCollection.First(i1 => i1.Name == GraphEdge.StartPoint.Name);
                GraphEdge.EndPoint = PointCollection.First(i1 => i1.Name == GraphEdge.EndPoint.Name);

                return base.HashSetEdges.Add(GraphEdge);
            }
            else throw new Exception("Graph not contains this combination of points: " + GraphEdge.StartPoint.ToString() + ", " + GraphEdge.EndPoint.ToString());
        }
Esempio n. 4
0
        public PointCollection BSplineCurve(ObservableCollection <RationalBSplinePoint> Points, int Degree, double[] KnotVector, double StepSize)
        {
            PointCollection Result = new PointCollection();

            for (double i = 0; i < 1; i += StepSize)
            {
                if (this.IsBSpline)
                {
                    Result.Add(BSplinePoint(Points, Degree, KnotVector, i));
                }
                else
                {
                    Result.Add(RationalBSplinePoint(Points, Degree, KnotVector, i));
                }
            }

            if (!Result.Contains(Points[Points.Count - 1].MyPoint))
            {
                Result.Add(Points[Points.Count - 1].MyPoint);
            }

            return(Result);
        }
Esempio n. 5
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
        }