Example #1
0
        public void TestNull()
        {
            string nullString = null;

            Insist.IsNull(null);
            Insist.IsNull(nullString);
            Insist.IsNull(new DateTime?());
            Insist.IsNull(new int?());
            Insist.IsNull(null);

            Assert.Throws <ValueNotNullException>(() => Insist.IsNull(32));
            Assert.Throws <ValueNotNullException>(() => Insist.IsNull(DateTime.Today));
            Assert.Throws <ValueNotNullException>(() => Insist.IsNull("string"));
            Assert.Throws <ValueNotNullException>(() => Insist.IsNull(new object()));
        }
Example #2
0
        /// <summary>
        /// Insert an item into this QuadTree object.
        /// </summary>
        /// <param name="item">The item to insert.</param>
        internal void Insert(QuadTreeObject <T> item)
        {
            // If this quad doesn't contain the items rectangle, do nothing, unless we are the root
            if (!_rect.Contains(item.Data.Bounds))
            {
                Insist.IsNull(_parent, "We are not the root, and this object doesn't fit here. How did we get here?");
                if (_parent == null)
                {
                    // This object is outside of the QuadTree bounds, we should add it at the root level
                    Add(item);
                }
                else
                {
                    return;
                }
            }

            if (_objects == null || (_childTL == null && _objects.Count + 1 <= maxObjectsPerNode))
            {
                // If there's room to add the object, just add it
                Add(item);
            }
            else
            {
                // No quads, create them and bump objects down where appropriate
                if (_childTL == null)
                {
                    Subdivide();
                }

                // Find out which tree this object should go in and add it there
                var destTree = GetDestinationTree(item);
                if (destTree == this)
                {
                    Add(item);
                }
                else
                {
                    destTree.Insert(item);
                }
            }
        }