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); }
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); }
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); }
public void SimpleAABBTree_Deletion_CheckCountIsZero() { 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); myTree.Remove(myEntity); Assert.IsTrue(myTree.Count == 1); }
public void SimpleAABBTree_BoundingBoxHitDetection_HitNone() { 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); BoundingBox myTestBox = new BoundingBox(new Vector3(3f, 3f, 3f), new Vector3(4, 4, 4)); RayCastHit <Object> myHit = myTree.BoundingPrimativeCast <Object>(myTestBox); Assert.AreEqual(0, myHit.Count); }
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); }
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]); } }
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); }
public void Test3() { 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() { 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); }); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }
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); }); }