Beispiel #1
0
        internal BoundedObject[] Sorted(params BoundedObject[] arr)
        {
            var result = new BoundedObject[arr.Length];

            Array.Copy(arr, result, arr.Length);
            Array.Sort(result, new BoundedObject.Comparer());
            return(result);
        }
Beispiel #2
0
        internal BoundedObject[] Sorted(params SpatialCollection <BoundedObject> .ItemInfo[] arr)
        {
            var result = new BoundedObject[arr.Length];

            for (int i = 0; i < arr.Length; i++)
            {
                result[i] = arr[i].Item;
            }
            Array.Sort(result, new BoundedObject.Comparer());
            return(result);
        }
Beispiel #3
0
        public void RecursionTest()
        {
            var a = new BoundedObject(new Vector2(0, 0), new Vector2(15, 15));
            var b = new BoundedObject(new Vector2(8, 8), new Vector2(23, 23));
            var c = new BoundedObject(new Vector2(16, 16), new Vector2(31, 31));

            Collection.Add(a);
            Collection.Add(b);
            Collection.Add(c);

            var e1  = Collection.GetItemsFromBounds(new Bounds(new Vector2(8, 8), new Vector2(32, 32)));
            var e2  = Collection.GetItemsFromBounds(new Bounds(new Vector2(8, 8), new Vector2(32, 32)));
            var e3  = Collection.GetItemsFromBounds(new Bounds(new Vector2(8, 8), new Vector2(32, 32)));
            var arr = Sorted(e3.ToArray());

            Assert.AreEqual(Sorted(e2.ToArray()), arr);
            Assert.AreEqual(Sorted(e1.ToArray()), arr);
            Assert.AreEqual(Sorted(Collection.ToArray()), arr);
            e3.Dispose();
            e2.Dispose();
            e1.Dispose();
        }
Beispiel #4
0
        public void BasicTest()
        {
            var a = new BoundedObject(new Vector2(0, 0), new Vector2(15, 15));
            var b = new BoundedObject(new Vector2(8, 8), new Vector2(23, 23));
            var c = new BoundedObject(new Vector2(16, 16), new Vector2(31, 31));

            Collection.Add(a);
            Collection.Add(b);
            Collection.Add(c);

            Assert.AreEqual(Sorted(a, b, c), Sorted(Collection.ToArray()));

            Assert.AreEqual(Sorted(a, b), Sorted(Collection.GetItemsFromBounds(a.Bounds).ToArray()));
            Assert.AreEqual(Sorted(a, b, c), Sorted(Collection.GetItemsFromBounds(b.Bounds).ToArray()));
            Assert.AreEqual(Sorted(b, c), Sorted(Collection.GetItemsFromBounds(c.Bounds).ToArray()));

            a.Bounds = new Bounds(new Vector2(24, 24), new Vector2(47, 47));
            Collection.UpdateItemBounds(a);

            Assert.AreEqual(Sorted(b, c, a), Sorted(Collection.GetItemsFromBounds(a.Bounds).ToArray()));
            Assert.AreEqual(Sorted(b, c, a), Sorted(Collection.GetItemsFromBounds(b.Bounds).ToArray()));
            Assert.AreEqual(Sorted(b, c, a), Sorted(Collection.GetItemsFromBounds(c.Bounds).ToArray()));
        }