Exemplo n.º 1
0
    public void SimpleAABBTree_InsertTwoDisjointedElementsRemoveOne_ChecksOtherRemains()
    {//TODO: STILL
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        var         myEntity2 = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(1.1f, 1.1f, 1.1f), new Vector3(2, 2, 2)));
        BoundingBox myBox     = new BoundingBox(new Vector3(1.1f, 1.1f, 1.1f), new Vector3(2, 2, 2));

        myTree.Insert(myEntity2);

        myTree.Remove(myEntity);

        var Results = myTree.BoundingPrimativeCast <Object>(myBox);

        Assert.IsTrue(Results.Count == 1);
        bool correctObject = false;

        foreach (object A in Results)
        {
            if (A == myEntity2)
            {
                correctObject = true;
            }
        }
        Assert.IsTrue(correctObject);
    }
Exemplo n.º 2
0
    public void SimpleAABBTree_InsertTwoOverlappingElementsRemoveOne_ChecksOtherRemains()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        BoundingBox myBox     = new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(2, 2, 2));
        var         myEntity2 = new SimpleAABBTreeStaticOBJ(myBox);

        myTree.Insert(myEntity2);

        myTree.Remove(myEntity);

        var Results = myTree.BoundingPrimativeCast <Object>(myBox);

        Assert.AreEqual(1, Results.Count, "Results didn't match expected number of items in the Tree.");
        bool correctObject = false;

        foreach (object A in Results)
        {
            if (A == myEntity2)
            {
                correctObject = true;
            }
        }
        Assert.IsTrue(correctObject);
    }
Exemplo n.º 3
0
    public void SimpleAABBTree_BoundingBoxHitDetection_GetNearestToPoint()
    {
        SimpleAABBTree myTree    = new SimpleAABBTree();
        Vector3        TestPoint = new Vector3(0, 0, 0);
        List <NearestObjectForSort> myObjectsAndDistanceFromPoint = new List <NearestObjectForSort>();

        for (int i = 0; i < 100; i++)
        {
            var aBox     = new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100)));
            var myEntity = new SimpleAABBTreeStaticOBJ(aBox);
            NearestObjectForSort mySortObject = new NearestObjectForSort()
            {
                Distance = Vector3.Distance(aBox.Center, TestPoint), myObject = myEntity
            };
            myObjectsAndDistanceFromPoint.Add(mySortObject);
            myTree.Insert(myEntity);
        }

        myObjectsAndDistanceFromPoint.Sort();
        var Result = myTree.GetNearest <SimpleAABBTreeStaticOBJ>(TestPoint, 100);

        Assert.AreEqual(100, Result.Count);
        for (int i = 0; i < Result.Count; i++)
        {
            Assert.IsNotNull(Result[i]);
            //Assert.AreEqual(Vector3.Distance(Result[i].Bounds.Center, TestPoint), myObjectsAndDistanceFromPoint[i].Distance);
        }
        Result = myTree.GetNearest <SimpleAABBTreeStaticOBJ>(TestPoint, 100, 100);
        Assert.AreEqual(100, Result.Count);
        for (int i = 0; i < Result.Count; i++)
        {
            Assert.IsNotNull(Result[i]);
            //Assert.AreEqual(Result[i], myObjectsAndDistanceFromPoint[i]);
        }
    }
Exemplo n.º 4
0
    public void SimpleAABBTree_InsertTwoElements_Intersects_TreeCheck()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(2, 2, 2)));
        BoundingBox myBox = new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(2, 2, 2));

        myTree.Insert(myEntity);

        var Results = myTree.BoundingPrimativeCast <Object>(myBox);

        Assert.IsTrue(Results.Count == 2);
        bool correctObject = false;

        foreach (object A in Results)
        {
            if (A == myEntity)
            {
                correctObject = true;
            }
        }
        Assert.IsTrue(correctObject);
    }
Exemplo n.º 5
0
    public void SimpleAABBTree_RemoveRebuildCheck()
    {
        SimpleAABBTree myATree = new SimpleAABBTree();
        SimpleAABBTree myBTree = new SimpleAABBTree();
        BoundingBox    myBox;
        int            TESTCOUNT = 20;
        SimpleAABBTreeDynamicInstance myObjectToRemove = null;

        for (int i = 0; i < TESTCOUNT; i++)
        {
            var myEntity = new SimpleAABBTreeDynamicInstance(new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100))));
            if (i + 1 != TESTCOUNT)
            {
                myATree.Insert(myEntity);
            }
            else
            {
                myObjectToRemove = myEntity;
            }
            myBTree.Insert(myEntity);
        }
        myBTree.Remove(myObjectToRemove);
        myBTree.Rebuild();
        Assert.AreEqual(myATree.CompareTo(myBTree), 0);
    }
Exemplo n.º 6
0
    public void SimpleAABBTree_TreeRaySingleHitDetection_RunOnEmptyTree()
    {
        SimpleAABBTree      myTree = new SimpleAABBTree();
        Ray                 aRay   = new Ray(new Vector3(0, 0, 0), new Vector3(0, 1, 0));
        RayCastHit <Object> myHit  = myTree.RaycastReturnFirst <Object>(aRay);

        Assert.AreEqual(myHit.Count, 0);
    }
Exemplo n.º 7
0
    public void SimpleAABBTree_CountTest_OneEntityAdded()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        Assert.AreEqual(myTree.Count, 1);
    }
Exemplo n.º 8
0
    public void SimpleAABBTree_BoundingBoxHitDetection_GetNearestToPoint_EmptyTree()
    {
        SimpleAABBTree myTree    = new SimpleAABBTree();
        Vector3        TestPoint = new Vector3(0, 0, 0);
        var            Result    = myTree.GetNearest <Object>(TestPoint, 100);

        Assert.AreEqual(Result.Count, 0);
    }
Exemplo n.º 9
0
    public void SimpleAABBTree_BoundingBoxHitDetection_HitOne_TreeOnlyHasNone()
    {
        SimpleAABBTree myTree = new SimpleAABBTree();

        BoundingBox         myTestBox = new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(2, 2, 2));
        RayCastHit <Object> myHit     = myTree.BoundingPrimativeCast <Object>(myTestBox);

        Assert.AreEqual(0, myHit.Count);
    }
Exemplo n.º 10
0
    public void SimpleAABBTree_Deletion_CheckCountIsZeroAdd1Remove1()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        Assert.IsTrue(myTree.Count == 1);
        myTree.Remove(myEntity);
        Assert.IsTrue(myTree.Count == 0);
    }
Exemplo n.º 11
0
    public void SimpleAABBTree_BoundingBoxHitDetection_HitOne_TreeOnlyHasOne()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        BoundingBox         myTestBox = new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(2, 2, 2));
        RayCastHit <Object> myHit     = myTree.BoundingPrimativeCast <Object>(myTestBox);

        Assert.AreEqual(1, myHit.Count);
    }
Exemplo n.º 12
0
    public void SimpleAABBTree_TreeRaySingleHitDetection_OneItemInTree()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        BoundingBox    myBox    = new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
        var            myEntity = new SimpleAABBTreeStaticOBJ(myBox);

        myTree.Insert(myEntity);
        Ray aRay = new Ray(new Vector3(0, 0, 0), new Vector3(0, 1, 0));
        RayCastHit <Object> myHit = myTree.RaycastReturnFirst <Object>(aRay);

        Assert.AreEqual(myHit.Count, 1);
    }
Exemplo n.º 13
0
    public void SimpleAABBTree_CompareToCheck_SameTree()
    {
        SimpleAABBTree myATree = new SimpleAABBTree();
        SimpleAABBTree myBTree = new SimpleAABBTree();
        BoundingBox    myBox;
        int            TESTCOUNT = 20;

        for (int i = 0; i < TESTCOUNT; i++)
        {
            var myEntity = new SimpleAABBTreeDynamicInstance(new BoundingBox(new Vector3(myRandom.Next(-100, -1), myRandom.Next(-100, -1), myRandom.Next(-100, -1)), new Vector3(myRandom.Next(0, 100), myRandom.Next(0, 100), myRandom.Next(0, 100))));
            myATree.Insert(myEntity);
        }
        Assert.AreEqual(myBTree.CompareTo(myBTree), 0);
    }
Exemplo n.º 14
0
    public void SimpleAABBTree_IteratorTest_OneEntityAdded()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeDynamicInstance(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        bool Worked = false;

        foreach (SimpleAABBTreeDynamicInstance A in myTree.GetEnumerator <SimpleAABBTreeDynamicInstance>())
        {
            Worked = true;
            break;
        }
        Assert.IsTrue(Worked);
    }
Exemplo n.º 15
0
    public void Test1()
    {
        SimpleAABBTree myBTree = new SimpleAABBTree();
        BoundingBox    myBox;
        int            TESTCOUNT = 20;

        for (int i = 0; i < TESTCOUNT; i++)
        {
            myBox = new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100)));
            var myEntity = new SimpleAABBTreeDynamicInstance(myBox);
            myBTree.Insert(myEntity);
        }
        myBTree.SetReadOnly(true);
        Assert.Throws <Exception>(delegate()
        {
            myBTree.Rebuild();
        });
    }
Exemplo n.º 16
0
    public void SimpleAABBTree_IteratorTest_MultipleSameEntityAdded()
    {
        int            TESTCOUNT = 20;
        SimpleAABBTree myTree    = new SimpleAABBTree();

        for (int i = 0; i < TESTCOUNT; i++)
        {
            var myEntity = new SimpleAABBTreeDynamicInstance(new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100))));
            myTree.Insert(myEntity);
        }
        int Count = 0;

        foreach (SimpleAABBTreeDynamicInstance A in myTree.GetEnumerator <SimpleAABBTreeDynamicInstance>())
        {
            Count++;
        }
        Assert.IsTrue(Count == TESTCOUNT);
    }
Exemplo n.º 17
0
    public void Test7()
    {
        SimpleAABBTree myATree = new SimpleAABBTree();
        BoundingBox    myBox;
        int            TESTCOUNT = 20;
        SimpleAABBTreeDynamicInstance myObjectToRemove = null;

        for (int i = 0; i < TESTCOUNT; i++)
        {
            myBox = new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100)));
            var myEntity = new SimpleAABBTreeDynamicInstance(myBox);
            myEntity.Bounds.Value = myBox;
            myATree.Insert(myEntity);
        }

        StaticAABBTree myStaticObject = myATree.GetAreaAsStaticTree(new BoundingBox(new Vector3(-1000000), new Vector3(100000)));

        Assert.IsTrue(myStaticObject.CompareTo(myATree) == 0);
    }
Exemplo n.º 18
0
    public void SimpleAABBTree_CompareToCheck_DifferentSizedTrees_SameItems()
    {
        SimpleAABBTree myATree = new SimpleAABBTree();
        SimpleAABBTree myBTree = new SimpleAABBTree();
        BoundingBox    myBox;
        int            TESTCOUNT        = 20;
        object         myObjectToRemove = null;

        for (int i = 0; i < TESTCOUNT; i++)
        {
            var myEntity = new SimpleAABBTreeDynamicInstance(new BoundingBox(new Vector3(myRandom.Next(-100, -1), myRandom.Next(-100, -1), myRandom.Next(-100, -1)), new Vector3(myRandom.Next(0, 100), myRandom.Next(0, 100), myRandom.Next(0, 100))));
            if (i + 1 != TESTCOUNT)
            {
                myATree.Insert(myEntity);
            }
            myBTree.Insert(myEntity);
        }
        Assert.AreEqual(1, myATree.CompareTo(myBTree));
        Assert.AreEqual(-1, myBTree.CompareTo(myATree));
    }
Exemplo n.º 19
0
    public void SimpleAABBTree_TreeRaySingleHitDetection_CheckIsOne()
    {
        SimpleAABBTree myTree   = new SimpleAABBTree();
        var            myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)));

        myTree.Insert(myEntity);
        myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(2, 2, 2)));
        myTree.Insert(myEntity);

        Ray aRay = new Ray(new Vector3(0, 0, 0), new Vector3(0, 1, 0));
        RayCastHit <Object> myHit = myTree.RaycastReturnFirst <Object>(aRay);

        Assert.AreEqual(myHit.Count, 1);
        aRay  = new Ray(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0, 1, 0));
        myHit = myTree.RaycastReturnFirst <Object>(aRay);
        Assert.AreEqual(myHit.Count, 1);
        aRay  = new Ray(new Vector3(0.5f, -1, 0.5f), new Vector3(0, 1, 0));
        myHit = myTree.RaycastReturnFirst <Object>(aRay);
        Assert.AreEqual(myHit.Count, 1);
        aRay  = new Ray(new Vector3(1.5f, 1.5f, 1.5f), new Vector3(0, 1, 0));
        myHit = myTree.RaycastReturnFirst <Object>(aRay);
        Assert.AreEqual(myHit.Count, 1);
    }
Exemplo n.º 20
0
    public void Test4()
    {
        SimpleAABBTree          myBTree = new SimpleAABBTree();
        BoundingBox             myBox;
        int                     TESTCOUNT = 20;
        SimpleAABBTreeStaticOBJ Last      = null;

        for (int i = 0; i < TESTCOUNT; i++)
        {
            myBox = new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100)));
            var myEntity = new SimpleAABBTreeStaticOBJ(myBox); //();
            myBTree.Insert(myEntity);
            if (i + 1 == TESTCOUNT)
            {
                Last = myEntity;
            }
        }
        myBTree.SetReadOnly(true);
        Assert.Throws <Exception>(delegate()
        {
            myBTree.Remove(Last);
        });
    }
Exemplo n.º 21
0
    public void SimpleAABBTree_IteratorTest_MultipleEntities_OneEntityDifferentClass_Added()
    {
        int            TESTCOUNT = 20;
        SimpleAABBTree myTree    = new SimpleAABBTree();
        BoundingBox    myBox;

        for (int i = 0; i < TESTCOUNT; i++)
        {
            var myEntity = new SimpleAABBTreeDynamicInstance(new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100))));
            myTree.Insert(myEntity);
        }
        //Inserts one dummy item
        SimpleAABBTreeStaticOBJ myEntity2 = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(myRandom.Next(-100, 0), myRandom.Next(-100, 0), myRandom.Next(-100, 0)), new Vector3(myRandom.Next(1, 100), myRandom.Next(1, 100), myRandom.Next(1, 100))));

        myTree.Insert(myEntity2);

        int Count = 0;

        foreach (SimpleAABBTreeDynamicInstance A in myTree.GetEnumerator <SimpleAABBTreeDynamicInstance>())
        {
            Count++;
        }
        Assert.IsTrue(Count == TESTCOUNT);
    }
Exemplo n.º 22
0
 public int CompareTo(SimpleAABBTree other)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 23
0
 public AABBStaticDataNode(BoundingBox myBox, SimpleAABBTree myTree, IStaticObject myData)
 {
     Owner     = myTree;
     Bounds    = myBox;
     this.Data = myData;
 }
Exemplo n.º 24
0
 public SharedAABBTree(SimpleAABBTree ParentObject, IAABBNode minimalSharedBranch) : base(minimalSharedBranch)
 {
     this.ParentObject = ParentObject;
 }