public void TestCenterOfMass() {
      AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
        new Vector2(100, 100), new Vector2(110, 120)
      );

      Assert.AreEqual(new Vector2(105, 110), testRectangle.CenterOfMass);
    }
    public void TestCircumferenceLength() {
      AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
        new Vector2(10.0f, 20.0f), new Vector2(30.0f, 40.0f)
      );

      float circumferenceLength = (20.0f * 2.0f) + (20.0f * 2.0f);
      Assert.AreEqual(circumferenceLength, testRectangle.CircumferenceLength);
    }
    public void TestArea() {
      AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
        new Vector2(10.0f, 20.0f), new Vector2(30.0f, 40.0f)
      );

      float surfaceArea = 20.0f * 20.0f;
      Assert.AreEqual(surfaceArea, testRectangle.Area);
    }
        public void TestCenterOfMass()
        {
            AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
                new Vector2(100, 100), new Vector2(110, 120)
                );

            Assert.AreEqual(new Vector2(105, 110), testRectangle.CenterOfMass);
        }
        public void TestBoundingBox()
        {
            AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
                new Vector2(100, 100), new Vector2(110, 120)
                );

            Assert.AreEqual(testRectangle, testRectangle.BoundingBox);
        }
 public void TestFullConstructor() {
   AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
     new Vector2(1.2f, 3.4f), new Vector2(5.6f, 7.8f)
   );
   Assert.AreEqual(1.2f, testRectangle.Min.X);
   Assert.AreEqual(3.4f, testRectangle.Min.Y);
   Assert.AreEqual(5.6f, testRectangle.Max.X);
   Assert.AreEqual(7.8f, testRectangle.Max.Y);
 }
        public void TestArea()
        {
            AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
                new Vector2(10.0f, 20.0f), new Vector2(30.0f, 40.0f)
                );

            float surfaceArea = 20.0f * 20.0f;

            Assert.AreEqual(surfaceArea, testRectangle.Area);
        }
        public void TestCircumferenceLength()
        {
            AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
                new Vector2(10.0f, 20.0f), new Vector2(30.0f, 40.0f)
                );

            float circumferenceLength = (20.0f * 2.0f) + (20.0f * 2.0f);

            Assert.AreEqual(circumferenceLength, testRectangle.CircumferenceLength);
        }
        public void TestFullConstructor()
        {
            AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
                new Vector2(1.2f, 3.4f), new Vector2(5.6f, 7.8f)
                );

            Assert.AreEqual(1.2f, testRectangle.Min.X);
            Assert.AreEqual(3.4f, testRectangle.Min.Y);
            Assert.AreEqual(5.6f, testRectangle.Max.X);
            Assert.AreEqual(7.8f, testRectangle.Max.Y);
        }
Ejemplo n.º 10
0
        public void TestBoundingBox()
        {
            Disc2 testDisc = new Disc2(new Vector2(123.4f, 567.8f), 9.0f);

            AxisAlignedRectangle2 boundingRectangle = testDisc.BoundingBox;

            Assert.AreEqual(testDisc.Center.X - testDisc.Radius, boundingRectangle.Min.X);
            Assert.AreEqual(testDisc.Center.X + testDisc.Radius, boundingRectangle.Max.X);

            Assert.AreEqual(testDisc.Center.Y - testDisc.Radius, boundingRectangle.Min.Y);
            Assert.AreEqual(testDisc.Center.Y + testDisc.Radius, boundingRectangle.Max.Y);
        }
        public void TestRandomPointWithin()
        {
            DefaultRandom         random        = new DefaultRandom();
            AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
                new Vector2(12.3f, 45.6f), new Vector2(98.7f, 65.4f)
                );

            for (int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index)
            {
                Vector2 randomPoint = testRectangle.RandomPointWithin(random);
                Assert.AreEqual(testRectangle.ClosestPointTo(randomPoint), randomPoint);
            }
        }
        public void TestClosestPointTo()
        {
            AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
                new Vector2(100, 100), new Vector2(110, 120)
                );

            Assert.AreEqual(
                testRectangle.Min,
                testRectangle.ClosestPointTo(new Vector2(60, 70))
                );
            Assert.AreEqual(
                testRectangle.Max,
                testRectangle.ClosestPointTo(new Vector2(115, 200))
                );
            Assert.AreEqual(
                new Vector2(104, 117),
                testRectangle.ClosestPointTo(new Vector2(104, 117))
                );
        }
        public void TestRandomPointOnPerimeter()
        {
            DefaultRandom         random        = new DefaultRandom();
            AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
                new Vector2(12.3f, 45.6f), new Vector2(98.7f, 65.4f)
                );

            float[] possibleXs = new float[] { 12.3f, 98.7f };
            float[] possibleYs = new float[] { 45.6f, 65.4f };

            for (int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index)
            {
                Vector2 randomPoint = testRectangle.RandomPointOnPerimeter(random);
                Assert.AreEqual(testRectangle.ClosestPointTo(randomPoint), randomPoint);

                Assert.IsTrue(
                    arrayContains(possibleXs, randomPoint.X) || arrayContains(possibleYs, randomPoint.Y)
                    );
            }
        }
    public void TestClosestPointTo() {
      AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
        new Vector2(100, 100), new Vector2(110, 120)
      );

      Assert.AreEqual(
        testRectangle.Min,
        testRectangle.ClosestPointTo(new Vector2(60, 70))
      );
      Assert.AreEqual(
        testRectangle.Max,
        testRectangle.ClosestPointTo(new Vector2(115, 200))
      );
      Assert.AreEqual(
        new Vector2(104, 117),
        testRectangle.ClosestPointTo(new Vector2(104, 117))
      );
    }
    public void TestRandomPointWithin() {
      DefaultRandom random = new DefaultRandom();
      AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
        new Vector2(12.3f, 45.6f), new Vector2(98.7f, 65.4f)
      );

      for(int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index) {
        Vector2 randomPoint = testRectangle.RandomPointWithin(random);
        Assert.AreEqual(testRectangle.ClosestPointTo(randomPoint), randomPoint);
      }
    }
    public void TestBoundingBox() {
      AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
        new Vector2(100, 100), new Vector2(110, 120)
      );

      Assert.AreEqual(testRectangle, testRectangle.BoundingBox);
    }
    public void TestRandomPointOnPerimeter() {
      DefaultRandom random = new DefaultRandom();
      AxisAlignedRectangle2 testRectangle = new AxisAlignedRectangle2(
        new Vector2(12.3f, 45.6f), new Vector2(98.7f, 65.4f)
      );

      float[] possibleXs = new float[] { 12.3f, 98.7f };
      float[] possibleYs = new float[] { 45.6f, 65.4f };

      for(int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index) {
        Vector2 randomPoint = testRectangle.RandomPointOnPerimeter(random);
        Assert.AreEqual(testRectangle.ClosestPointTo(randomPoint), randomPoint);

        Assert.IsTrue(
          arrayContains(possibleXs, randomPoint.X) || arrayContains(possibleYs, randomPoint.Y)
        );
      }
    }