public void TestBoundingLineReflect180Bot() { //Preconfig Vector position1 = new Vector(0f, 50f); Vector target1 = new Vector(50f, 50f); Vector ballSpeed = new Vector(0, -10); Vector ballPos = new Vector(20f, 100f); Vector hitPoint = new Vector(20, 50); Vector expectedReflection = -ballSpeed; expectedReflection.Normalize(); Vector reflection; //Creation Line parent = new Line(); BoundingContainer bCont = new BoundingContainer(parent); BoundingLine bL1 = new BoundingLine(position1, target1); bCont.AddBoundingBox(bL1); parent.Location = (new Vector(0, 0)); //Operation reflection = bL1.Reflect(ballSpeed, hitPoint, ballPos); reflection.Normalize(); //Assertion Assert.AreEqual(expectedReflection, reflection); }
public void TestBoundingCirclePushBackLeft() { //Preconfig int radius = 20; Vector position = new Vector(100f, 100f); Vector ballPos = new Vector(90, 120); Vector hitPoint = new Vector(100, 120); Vector ballSpeed = hitPoint - ballPos; Vector expectedPushBack = (radius * 2 / 1.9f) * ((hitPoint - (position + new Vector(radius, radius)))).AsNormalized(); Vector pushBackVec; //Creation Bumper parent = new Bumper(); BoundingCircle bC2 = new BoundingCircle(radius, position); BoundingContainer bCont = new BoundingContainer(parent); bCont.AddBoundingBox(bC2); //Operation parent.Location = (new Vector(0, 0)); pushBackVec = bC2.GetOutOfAreaPush(radius * 2, hitPoint, ballSpeed, ballPos); //Assertion Assert.AreEqual(expectedPushBack, pushBackVec); }
public void TestReflection135Direction() { //Preconfig Vector position = new Vector(100f, 100f); Vector ballPos = new Vector(140f, 120f); int radius = 20; Vector ballSpeed = new Vector(-100, -100); Vector hitPoint = new Vector(120 + 14.1421f, 120 + 14.1421f); Vector expectedReflection = -ballSpeed; expectedReflection.Normalize(); Vector reflection; //Creation Bumper parent = new Bumper(); BoundingCircle bC2 = new BoundingCircle(radius, position); BoundingContainer bCont = new BoundingContainer(parent); bCont.AddBoundingBox(bC2); //Operation parent.Location = (new Vector(0, 0)); reflection = bC2.Reflect(ballSpeed, hitPoint, ballPos); reflection.Normalize(); //Assertion Assert.AreEqual(expectedReflection.X, reflection.X, 0.001f); Assert.AreEqual(expectedReflection.Y, reflection.Y, 0.001f); }
public void TestPushBackBotRightToCenter() { //Preconfig Vector position1 = new Vector(0f, 50f); Vector target1 = new Vector(50f, 50f); int radius2 = 20; Vector center2 = new Vector(25, 55); Vector ballSpeed = new Vector(-5, -5); Vector hitPoint = new Vector(20, 50); Vector pushBackVec; Vector estimatedPushBackVec = new Vector(0, 1); estimatedPushBackVec.Normalize(); //Creation Line parent = new Line(); BoundingContainer bCont = new BoundingContainer(parent); BoundingLine bL1 = new BoundingLine(position1, target1); bCont.AddBoundingBox(bL1); parent.Location = (new Vector(0, 0)); //Operation pushBackVec = bL1.GetOutOfAreaPush(radius2 * 2, hitPoint, -ballSpeed, center2); pushBackVec.Normalize(); //Assertion Assert.AreEqual(estimatedPushBackVec, pushBackVec); }
public void addReferenceTwiceTest() { //Preconfig int radius1 = 20; Vector center1 = new Vector(0f, 0f); //Creation Bumper parent = new Bumper(); BoundingContainer bCont = new BoundingContainer(parent); BoundingCircle bC1 = new BoundingCircle(radius1, center1); bCont.AddBoundingBox(bC1); BoundingField bf = new BoundingField(0, 0); //Operation bf.addReference(bC1); bf.addReference(bC1); int hit = 0; //Assertion foreach (IBoundingBox b in bf.getReferences()) { if (b.Equals(bC1)) { hit++; } } if (hit == 1) { Assert.AreEqual(1, hit); } }
public void TestIntersectIntersect1pxLeftTooFar() { //Preconfig int radius1 = 20; Vector center1 = new Vector(0f, 0f); int radius2 = 20; Vector center2 = new Vector(-19, 0f); Vector ballSpeed = new Vector(-5, 0); Vector hitPoint; bool isIntersec = false; //Creation Bumper parent = new Bumper(); Ball ball = new Ball(); BoundingContainer bCont = new BoundingContainer(parent); BoundingContainer bCont2 = new BoundingContainer(ball); BoundingCircle bC1 = new BoundingCircle(radius1, center1); BoundingCircle bC2 = new BoundingCircle(radius2, center2); bCont.AddBoundingBox(bC1); bCont2.AddBoundingBox(bC2); ball.Velocity = ballSpeed; parent.Location = (new Vector(0, 0)); parent.Width = 2 * radius1; parent.Height = 2 * radius1; //Operation isIntersec = bC1.Intersect(bC2, out hitPoint, ballSpeed); //Assertion Assert.IsTrue(isIntersec); Assert.AreEqual(new Vector(40, 20), hitPoint); }
public void TestIntersect1pxOverlapBot() { //Preconfig Vector position1 = new Vector(0f, 50f); Vector target1 = new Vector(50f, 50f); int radius2 = 20; Vector center2 = new Vector(20, 49); Vector ballSpeed = new Vector(0, -5); Vector hitPoint; bool isIntersec = false; //Creation Line parent = new Line(); Ball ball = new Ball(); BoundingContainer bCont = new BoundingContainer(parent); BoundingContainer bCont2 = new BoundingContainer(ball); BoundingLine bL1 = new BoundingLine(position1, target1); BoundingCircle bC2 = new BoundingCircle(radius2, center2); bCont.AddBoundingBox(bL1); bCont2.AddBoundingBox(bC2); ball.Velocity = ballSpeed; parent.Location = (new Vector(0, 0)); //Operation isIntersec = bC2.Intersect(bL1, out hitPoint); //Assertion Assert.IsTrue(isIntersec); Assert.AreEqual(new Vector(40,50), hitPoint); }
public void TakeOverBoundingContainerWithCircleBigCenter() { //preconfig int cols = 10; int rows = 10; int width = 100; int height = 100; int expectedFieldHeight = height / rows; int expectedFieldWidth = width / cols; int radius1 = 50; Vector position1 = new Vector(0, 0); //creation BoundingRaster br = new BoundingRaster(cols, rows, width, height); Bumper parent1 = new Bumper(); BoundingCircle bC1 = new BoundingCircle(radius1, position1); BoundingContainer bCont1 = new BoundingContainer(parent1); bCont1.AddBoundingBox(bC1); parent1.Location = (new Vector(0, 0)); //operation br.TakeOverBoundingContainer(bCont1); //assertion for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { if (x <= 9 && x >= 0 && y <= 9 && y >= 0) { bool found = false; foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences()) { Assert.AreEqual(bC1, b); found = true; } if (!found) { Assert.Fail(); } } else { foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences()) { if (bC1.Equals(b)) { Assert.Fail(); } } } } } }
public void TakeOverBoundingContainerWithLineSmallDiagonal() { //preconfig int cols = 10; int rows = 10; int width = 100; int height = 100; int expectedFieldHeight = height / rows; int expectedFieldWidth = width / cols; Vector position1 = new Vector(0, 0); Vector target1 = new Vector(50, 50); //creation BoundingRaster br = new BoundingRaster(cols, rows, width, height); Line parent1 = new Line(); BoundingLine bL1 = new BoundingLine(position1, target1); BoundingContainer bCont1 = new BoundingContainer(parent1); bCont1.AddBoundingBox(bL1); parent1.Location = (new Vector(0, 0)); //operation br.TakeOverBoundingContainer(bCont1); //assertion for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { if ((x == y) && x >= 0 && x <= 5) { bool found = false; foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences()) { Assert.AreEqual(bL1, b); found = true; } if (!found) { Assert.Fail(); } } else { foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences()) { if (bL1.Equals(b)) { Assert.Fail(); } } } } } }
public void TestIntersectIntersectleft1pxOverlap() { //Preconfig Vector target1 = new Vector(40, 50); Vector position1 = new Vector(0f, 50f); int radius2 = 20; Vector center2 = new Vector(-39, 30); Vector ballSpeed = new Vector(0, 5); Vector hitPoint; bool isIntersec = false; //Creation Line parent = new Line(); Ball ball = new Ball(); BoundingContainer bCont = new BoundingContainer(parent); BoundingContainer bCont2 = new BoundingContainer(ball); BoundingLine bL1 = new BoundingLine(position1, target1); BoundingCircle bC2 = new BoundingCircle(radius2, center2); bCont.AddBoundingBox(bL1); bCont2.AddBoundingBox(bC2); ball.Velocity = ballSpeed; ball.Location = (new Vector(0, 0)); ball.Width = 20; ball.Height = 20; parent.Location = (new Vector(0, 0)); parent.Width = 40; parent.Height = 0; //Operation isIntersec = bL1.Intersect(bC2, out hitPoint); //Assertion Assert.IsTrue(isIntersec); Assert.AreEqual(0, hitPoint.X, 2); Assert.AreEqual(50f, hitPoint.Y, 2); }
public void TestIntersectIntersectNone() { //Preconfig Vector target1 = new Vector(20, 50); Vector position1 = new Vector(0f, 50f); int radius2 = 20; Vector center2 = new Vector(10, 0f); Vector ballSpeed = new Vector(0, 5); Vector hitPoint; bool isIntersec = false; //Creation Line parent = new Line(); Ball ball = new Ball(); BoundingContainer bCont = new BoundingContainer(parent); BoundingContainer bCont2 = new BoundingContainer(ball); BoundingLine bL1 = new BoundingLine(position1, target1); BoundingCircle bC2 = new BoundingCircle(radius2, center2); bCont.AddBoundingBox(bL1); bCont2.AddBoundingBox(bC2); ball.Velocity = ballSpeed; parent.Location = new Vector(0, 0); parent.Width = 20; parent.Height = 0; //Operation isIntersec = bC2.Intersect(bL1, out hitPoint); //Assertion Assert.IsFalse(isIntersec); }
public void TestIntersectNoIntersectTouch() { //Preconfig int radius1 = 20; Vector center1 = new Vector(0f, 0f); int radius2 = 20; Vector center2 = new Vector(40f, 0f); Vector ballSpeed = new Vector(-5, 0); Vector hitPoint; bool isIntersec = false; //Creation Bumper parent = new Bumper(); Ball ball = new Ball(); BoundingContainer bCont = new BoundingContainer(parent); BoundingContainer bCont2 = new BoundingContainer(ball); BoundingCircle bC1 = new BoundingCircle(radius1, center1); BoundingCircle bC2 = new BoundingCircle(radius2, center2); bCont.AddBoundingBox(bC1); bCont2.AddBoundingBox(bC2); ball.Velocity = ballSpeed; //Operation isIntersec = bC1.Intersect(bC2, out hitPoint); //Assertion Assert.IsFalse(isIntersec); }
public void TakeOverBoundingContainerWithLineTotalOutside() { //preconfig int cols = 10; int rows = 10; int width = 100; int height = 100; int expectedFieldHeight = height / rows; int expectedFieldWidth = width / cols; Vector position1 = new Vector(-20, -20); Vector target1 = new Vector(-50, -50); //creation BoundingRaster br = new BoundingRaster(cols, rows, width, height); Line parent1 = new Line(); BoundingLine bL1 = new BoundingLine(position1, target1); BoundingContainer bCont1 = new BoundingContainer(parent1); bCont1.AddBoundingBox(bL1); parent1.Location = (new Vector(0, 0)); //operation br.TakeOverBoundingContainer(bCont1); //assertion for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { foreach (IBoundingBox b in br.GetBoundingField(x, y).getReferences()) { if (bL1.Equals(b)) { Assert.Fail(); } } } } }