Beispiel #1
0
        public void Clone()
        {
            AdaptiveAabbTree <int> staticPartition  = new AdaptiveAabbTree <int>();
            DynamicAabbTree <int>  dynamicPartition = new DynamicAabbTree <int>();
            DualPartition <int>    partition        = new DualPartition <int>(staticPartition, dynamicPartition);

            partition.GetAabbForItem     = i => new Aabb();
            partition.EnableSelfOverlaps = true;
            partition.Filter             = new DelegatePairFilter <int>(pair => true);
            partition.Add(0);
            partition.Add(1);
            partition.Add(2);
            partition.Add(3);

            var clone = partition.Clone();

            Assert.NotNull(clone);
            Assert.AreNotSame(clone, partition);
            Assert.AreEqual(clone.EnableSelfOverlaps, partition.EnableSelfOverlaps);
            Assert.AreEqual(clone.Filter, partition.Filter);
            Assert.AreEqual(0, clone.Count);

            clone.Add(0);
            Assert.AreEqual(4, partition.Count);
            Assert.AreEqual(1, clone.Count);
        }
Beispiel #2
0
        public void NaNWithValidation()
        {
            GlobalSettings.ValidationLevel = 0xff;

            var partition = new DualPartition <int>();

            partition.EnableSelfOverlaps = true;
            partition.GetAabbForItem     = GetAabbForItem;

            partition.Add(1);
            partition.Add(4);
            partition.Add(2);
            partition.Add(3);

            // Full rebuild.
            Assert.Throws <GeometryException>(() => partition.Update(true));

            partition = new DualPartition <int>();
            partition.EnableSelfOverlaps = true;
            partition.GetAabbForItem     = GetAabbForItem;

            partition.Add(1);
            partition.Add(2);
            partition.Add(3);
            partition.Update(true);
            partition.Add(4);

            // Partial rebuild.
            Assert.Throws <GeometryException>(() => partition.Update(false));
        }
Beispiel #3
0
        public void Infinite()
        {
            GlobalSettings.ValidationLevel = 0xff;

            var partition = new DualPartition <int>
            {
                EnableSelfOverlaps = true,
                GetAabbForItem     = GetAabbForItem
            };

            partition.Add(1);
            partition.Add(0);
            partition.Add(2);
            partition.Add(3);

            Assert.AreEqual(new Aabb(new Vector3F(float.NegativeInfinity), new Vector3F(float.PositiveInfinity)), partition.Aabb);

            var overlaps = partition.GetOverlaps().ToArray();

            Assert.AreEqual(4, overlaps.Length);
            Assert.IsTrue(overlaps.Contains(new Pair <int>(0, 1)));
            Assert.IsTrue(overlaps.Contains(new Pair <int>(0, 2)));
            Assert.IsTrue(overlaps.Contains(new Pair <int>(0, 3)));
            Assert.IsTrue(overlaps.Contains(new Pair <int>(1, 2)));
        }
        protected override void Write(ContentWriter output, DualPartition <T> value)
        {
            dynamic internals = value.Internals;
            ISpatialPartition <T> staticPartition  = internals.StaticPartition;
            ISpatialPartition <T> dynamicPartition = internals.DynamicPartition;

            output.Write(value.EnableSelfOverlaps);
            output.WriteSharedResource(value.Filter);
            output.WriteObject(staticPartition);
            output.WriteObject(dynamicPartition);
        }
Beispiel #5
0
        protected override DualPartition <T> Read(ContentReader input, DualPartition <T> existingInstance)
        {
            if (existingInstance == null)
            {
                existingInstance = new DualPartition <T>();
            }
            else
            {
                existingInstance.Clear();
            }

            existingInstance.EnableSelfOverlaps = input.ReadBoolean();
            input.ReadSharedResource <IPairFilter <T> >(filter => existingInstance.Filter = filter);
            existingInstance.StaticPartition  = input.ReadObject <ISpatialPartition <T> >();
            existingInstance.DynamicPartition = input.ReadObject <ISpatialPartition <T> >();
            return(existingInstance);
        }
Beispiel #6
0
        public void NaN()
        {
            GlobalSettings.ValidationLevel = 0x00;

            var partition = new DualPartition <int>
            {
                EnableSelfOverlaps = true,
                GetAabbForItem     = GetAabbForItem
            };

            partition.Add(1);
            partition.Add(4);
            partition.Add(2);
            partition.Add(3);

            // No exception expected because internal tree is built top down (default
            // BottomUpBuildThreshold is 0). However, tree will not be useful.
            partition.Update(true);
        }
Beispiel #7
0
        public void NaN()
        {
            GlobalSettings.ValidationLevel = 0x00;

              var partition = new DualPartition<int>
              {
            EnableSelfOverlaps = true,
            GetAabbForItem = GetAabbForItem
              };

              partition.Add(1);
              partition.Add(4);
              partition.Add(2);
              partition.Add(3);

              // No exception expected because internal tree is built top down (default
              // BottomUpBuildThreshold is 0). However, tree will not be useful.
              partition.Update(true);
        }
Beispiel #8
0
        public void Infinite()
        {
            GlobalSettings.ValidationLevel = 0xff;

              var partition = new DualPartition<int>
              {
            EnableSelfOverlaps = true,
            GetAabbForItem = GetAabbForItem
              };

              partition.Add(1);
              partition.Add(0);
              partition.Add(2);
              partition.Add(3);

              Assert.AreEqual(new Aabb(new Vector3F(float.NegativeInfinity), new Vector3F(float.PositiveInfinity)), partition.Aabb);

              var overlaps = partition.GetOverlaps().ToArray();
              Assert.AreEqual(4, overlaps.Length);
              Assert.IsTrue(overlaps.Contains(new Pair<int>(0, 1)));
              Assert.IsTrue(overlaps.Contains(new Pair<int>(0, 2)));
              Assert.IsTrue(overlaps.Contains(new Pair<int>(0, 3)));
              Assert.IsTrue(overlaps.Contains(new Pair<int>(1, 2)));
        }
Beispiel #9
0
        public void Clone()
        {
            AdaptiveAabbTree<int> staticPartition = new AdaptiveAabbTree<int>();
              DynamicAabbTree<int> dynamicPartition = new DynamicAabbTree<int>();
              DualPartition<int> partition = new DualPartition<int>(staticPartition, dynamicPartition);
              partition.GetAabbForItem = i => new Aabb();
              partition.EnableSelfOverlaps = true;
              partition.Filter = new DelegatePairFilter<int>(pair => true);
              partition.Add(0);
              partition.Add(1);
              partition.Add(2);
              partition.Add(3);

              var clone = partition.Clone();
              Assert.NotNull(clone);
              Assert.AreNotSame(clone, partition);
              Assert.AreEqual(clone.EnableSelfOverlaps, partition.EnableSelfOverlaps);
              Assert.AreEqual(clone.Filter, partition.Filter);
              Assert.AreEqual(0, clone.Count);

              clone.Add(0);
              Assert.AreEqual(4, partition.Count);
              Assert.AreEqual(1, clone.Count);
        }
Beispiel #10
0
        public void NaNWithValidation()
        {
            GlobalSettings.ValidationLevel = 0xff;

              var partition = new DualPartition<int>();
              partition.EnableSelfOverlaps = true;
              partition.GetAabbForItem = GetAabbForItem;

              partition.Add(1);
              partition.Add(4);
              partition.Add(2);
              partition.Add(3);

              // Full rebuild.
              Assert.Throws<GeometryException>(() => partition.Update(true));

              partition = new DualPartition<int>();
              partition.EnableSelfOverlaps = true;
              partition.GetAabbForItem = GetAabbForItem;

              partition.Add(1);
              partition.Add(2);
              partition.Add(3);
              partition.Update(true);
              partition.Add(4);

              // Partial rebuild.
              Assert.Throws<GeometryException>(() => partition.Update(false));
        }