Exemplo n.º 1
0
        /// <summary>
        /// Constructs a new instance of <see cref="Hull"/>.
        /// </summary>
        /// <param name="points">
        /// Points of the hull polygon. In order for the hull to be valid, the points must form:
        /// <list type="number">
        /// <item><description>A polygon with at least 3 points.</description></item>
        /// <item><description>A simple polygon (no two edges intersect with each other).</description></item>
        /// </list>
        /// </param>
        public Hull(IEnumerable <Vector2> points = null)
        {
            if (points != null)
            {
                _rawLocalPoints.AddRange(points);
                ValidateRawLocalPoints();
                if (Valid)
                {
                    ConvertRawLocalPointsToLocalPoints();
                }
            }

            _rawLocalPoints.CollectionChanged += (s, e) =>
            {
                ValidateRawLocalPoints();
                if (Valid)
                {
                    ConvertRawLocalPointsToLocalPoints();
                    if (e.Action == NotifyCollectionChangedAction.Add)
                    {
                        foreach (Vector2 point in e.NewItems)
                        {
                            Logger.Write($"New point at {point}.");
                        }
                    }
                    _worldDirty  = true;
                    _pointsDirty = true;
                }
            };
        }
Exemplo n.º 2
0
        public void Test_AddRange_Ok()
        {
            int eventCount = 0;

            IEnumerable <int> initialNumbers = Enumerable.Range(1, 4);
            IEnumerable <int> newNumbers     = Enumerable.Range(16, 32);

            ExtendedObservableCollection <int> observableCollection = new ExtendedObservableCollection <int>(initialNumbers);

            observableCollection.CollectionChanged += (sender, args) => eventCount++;

            observableCollection.AddRange(newNumbers);

            Assert.Equal(initialNumbers.Count() + newNumbers.Count(), observableCollection.Count);

            foreach (int number in initialNumbers)
            {
                Assert.Contains(observableCollection, numberItem => numberItem == number);
            }

            foreach (int number in newNumbers)
            {
                Assert.Contains(observableCollection, numberItem => numberItem == number);
            }

            Assert.Equal(1, eventCount);
        }
Exemplo n.º 3
0
        public void Test_AddRange_EmptyItemsArgument_Ok()
        {
            int eventCount = 0;

            IEnumerable <int> newNumbers = Enumerable.Range(16, 32);

            ExtendedObservableCollection <int> observableCollection = new ExtendedObservableCollection <int>();

            observableCollection.CollectionChanged += (sender, args) => eventCount++;

            observableCollection.AddRange(null);
            observableCollection.AddRange(new List <int>());
            observableCollection.AddRange(new int[0]);

            Assert.Empty(observableCollection);
            Assert.Equal(0, eventCount);
        }
Exemplo n.º 4
0
        protected void SetSamplePackets()
        {
            var samplePackets = new PacketBase[] {
                new BNetPacket(null, false, new RPCHeader(-1, -1, -1), null),
                // new PegPacket(null, false, -1, null),
            };

            _packets.Clear();
            _packets.AddRange(samplePackets);
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            var collection = new ExtendedObservableCollection <string>();

            collection.CollectionChanged += Collection_CollectionChanged;

            collection.Add("item1");
            collection.AddRange(new string[] { "item2", "item3", "item4" });
            collection[0] = "item1 mk2";
            collection.Move(0, 3);
            collection.Remove("item3");
            collection.Clear();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructs a new instance of <see cref="Hull"/>.
        /// </summary>
        /// <param name="points">
        /// Points of the hull polygon. In order for the hull to be valid, the points must form:
        /// <list type="number">
        /// <item><description>A polygon with at least 3 points.</description></item>
        /// <item><description>A simple polygon (no two edges intersect with each other).</description></item>
        /// </list>
        /// </param>
        public Hull(IEnumerable <Vector2> points = null)
        {
            if (points != null)
            {
                _rawLocalPoints.AddRange(points);
                ValidateRawLocalPoints();
                if (Valid)
                {
                    ConvertRawLocalPointsToLocalPoints();
                }
            }

            _rawLocalPoints.CollectionChanged += (s, e) => _pointsDirty = true;
        }
Exemplo n.º 7
0
        public void AddRange_OneItem_ItemIsAddedAndCollectionChangedResetRaised()
        {
            var collectionChangedEventArgsList = new List <NotifyCollectionChangedEventArgs>();

            var collection = new ExtendedObservableCollection <int>();

            collection.CollectionChanged += (_, args) => collectionChangedEventArgsList.Add(args);

            collection.AddRange(new[] { 123 });

            Assert.Single(collection);
            Assert.Equal(123, collection[0]);

            Assert.Single(collectionChangedEventArgsList);
            Assert.Equal(NotifyCollectionChangedAction.Reset, collectionChangedEventArgsList[0].Action);
        }