Example #1
0
        public void GetObjectsWithin_ReturnsCorrectObjects()
        {
            var grid = new UniversalGrid <string>(10, 20);

            var thing1 = "A".AsSpatialObject(1, 1);
            var thing2 = "B".AsSpatialObject(1, 2);

            grid.SetObjects(thing1, thing2);

            var objs = grid.GetObjectsWithin(new Rectangle(0, 0, 5, 5)).ToList();

            Assert.That(objs.First(), Is.EqualTo(thing1));
            Assert.That(objs.Skip(1).First(), Is.EqualTo(thing2));
            Assert.That(objs.Count, Is.EqualTo(2));
        }
Example #2
0
        public void GetObjectsOverlapping_ReturnsCorrectObject()
        {
            var grid = new UniversalGrid <string>(10, 20);

            var thing1 = "A".AsSpatialObject(1, 1);
            var thing2 = "B".AsSpatialObject(1, 2);

            grid.SetObjects(thing1, thing2);

            var objs = grid.GetObjectsOverlapping(new Point2D()
            {
                X = 1, Y = 2
            }).ToList();

            Assert.That(objs.Single(), Is.EqualTo(thing2));
        }
Example #3
0
        public void Move_CorrectlySetsTopLeftPosAndMovesContainingObjects()
        {
            var grid = new UniversalGrid <string>(10, 20);

            var thing1   = "A".AsSpatialObject(1, 1);
            var thing2   = "B".AsSpatialObject(1, 2);
            var moves    = 0;
            var modified = false;

            grid.ItemMoved += (s, e) =>
            {
                moves++;
            };

            grid.Modified += (s, e) =>
            {
                modified = true;
            };

            grid.SetObjects(thing1, thing2);

            grid.Move(new Point2D()
            {
                X = 2, Y = 1
            });

            Assert.That(modified);
            Assert.That(grid.TopLeft, Is.EqualTo(new Point2D()
            {
                X = 2, Y = 1
            }));
            Assert.That(grid.AllObjects.Count(), Is.EqualTo(2));
            Assert.That(thing1.TopLeft, Is.EqualTo(new Point2D()
            {
                X = 3, Y = 2
            }));
            Assert.That(thing2.TopLeft, Is.EqualTo(new Point2D()
            {
                X = 3, Y = 3
            }));
            Assert.That(moves, Is.EqualTo(2));
        }