/// <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; } }; }
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); }
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); }
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); }
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(); }
/// <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; }
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); }