Ejemplo n.º 1
0
        public void TestClosestPointTo()
        {
            Disc2 testDisc = new Disc2(new Vector2(123.4f, 567.8f), 9.0f);

            Random randomNumberGenerator = new Random();

            for (int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index)
            {
                Vector2 randomPoint = new Vector2(
                    (float)randomNumberGenerator.NextDouble() * testDisc.Radius * 4.0f,
                    (float)randomNumberGenerator.NextDouble() * testDisc.Radius * 4.0f
                    );
                randomPoint += testDisc.Center;

                float distance = (randomPoint - testDisc.Center).Length();
                if (distance < testDisc.Radius)
                {
                    Assert.AreEqual(randomPoint, testDisc.ClosestPointTo(randomPoint));
                }
                else
                {
                    Vector2 closestPoint = testDisc.ClosestPointTo(randomPoint);
                    Assert.That(
                        (closestPoint - testDisc.Center).Length(),
                        Is.EqualTo(testDisc.Radius).Within(36).Ulps
                        // TODO: This method suffers from accuracy problems!
                        );
                }
            }
        }
Ejemplo n.º 2
0
        public void TestConstructor()
        {
            Disc2 testDisc = new Disc2(new Vector2(12.34f, 56.78f), 9.0f);

            Assert.AreEqual(12.34f, testDisc.Center.X);
            Assert.AreEqual(56.78f, testDisc.Center.Y);
            Assert.AreEqual(9.0f, testDisc.Radius);
        }
Ejemplo n.º 3
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);
    }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public void TestRandomPointOnPerimeter()
        {
            Disc2 testDisc = new Disc2(new Vector2(123.4f, 567.8f), 9.0f);

            DefaultRandom randomNumberGenerator = new DefaultRandom();

            for (int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index)
            {
                Vector2 randomPoint = testDisc.RandomPointOnPerimeter(randomNumberGenerator);
                Assert.That(
                    (testDisc.Center - randomPoint).Length(),
                    Is.EqualTo(testDisc.Radius).Within(36).Ulps
                    // TODO: This method suffers from accuracy problems!
                    );
            }
        }
Ejemplo n.º 6
0
        public void TestRandomPointWithin()
        {
            Disc2 testDisc = new Disc2(new Vector2(123.4f, 567.8f), 9.0f);

            DefaultRandom randomNumberGenerator = new DefaultRandom();

            for (int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index)
            {
                Vector2 randomPoint = testDisc.RandomPointWithin(randomNumberGenerator);

                float randomPointDistance = (testDisc.Center - randomPoint).Length();
                if (!FloatHelper.AreAlmostEqual(randomPointDistance, testDisc.Radius, 36))
                {
                    Assert.LessOrEqual(randomPointDistance, testDisc.Radius);
                }
            }
        }
Ejemplo n.º 7
0
    public void TestClosestPointTo() {
      Disc2 testDisc = new Disc2(new Vector2(123.4f, 567.8f), 9.0f);

      Random randomNumberGenerator = new Random();
      for(int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index) {
        Vector2 randomPoint = new Vector2(
          (float)randomNumberGenerator.NextDouble() * testDisc.Radius * 4.0f,
          (float)randomNumberGenerator.NextDouble() * testDisc.Radius * 4.0f
        );
        randomPoint += testDisc.Center;

        float distance = (randomPoint - testDisc.Center).Length();
        if(distance < testDisc.Radius) {
          Assert.AreEqual(randomPoint, testDisc.ClosestPointTo(randomPoint));
        } else {
          Vector2 closestPoint = testDisc.ClosestPointTo(randomPoint);
          Assert.That(
            (closestPoint - testDisc.Center).Length(),
            Is.EqualTo(testDisc.Radius).Within(36).Ulps
            // TODO: This method suffers from accuracy problems!
          );
        }
      }
    }
Ejemplo n.º 8
0
    public void TestCenterOfMass() {
      Disc2 testDisc = new Disc2(new Vector2(12.34f, 56.78f), 20.0f);

      Assert.AreEqual(testDisc.Center, testDisc.CenterOfMass);
    }
Ejemplo n.º 9
0
    public void TestCircumferenceLength() {
      Disc2 testDisc = new Disc2(new Vector2(12.34f, 56.78f), 20.0f);

      Assert.AreEqual(125.66371f, testDisc.CircumferenceLength);
    }
Ejemplo n.º 10
0
    public void TestSurfaceArea() {
      Disc2 testDisc = new Disc2(new Vector2(12.34f, 56.78f), 20.0f);

      Assert.AreEqual(1256.63706f, testDisc.Area);
    }
Ejemplo n.º 11
0
 public void TestConstructor() {
   Disc2 testDisc = new Disc2(new Vector2(12.34f, 56.78f), 9.0f);
   Assert.AreEqual(12.34f, testDisc.Center.X);
   Assert.AreEqual(56.78f, testDisc.Center.Y);
   Assert.AreEqual(9.0f, testDisc.Radius);
 }
Ejemplo n.º 12
0
    public void TestRandomPointWithin() {
      Disc2 testDisc = new Disc2(new Vector2(123.4f, 567.8f), 9.0f);

      DefaultRandom randomNumberGenerator = new DefaultRandom();
      for(int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index) {
        Vector2 randomPoint = testDisc.RandomPointWithin(randomNumberGenerator);

        float randomPointDistance = (testDisc.Center - randomPoint).Length();
        if(!FloatHelper.AreAlmostEqual(randomPointDistance, testDisc.Radius, 36)) {
          Assert.LessOrEqual(randomPointDistance, testDisc.Radius);
        }
      }

    }
Ejemplo n.º 13
0
    public void TestRandomPointOnPerimeter() {
      Disc2 testDisc = new Disc2(new Vector2(123.4f, 567.8f), 9.0f);

      DefaultRandom randomNumberGenerator = new DefaultRandom();
      for(int index = 0; index < Specifications.ProbabilisticFunctionSamples; ++index) {
        Vector2 randomPoint = testDisc.RandomPointOnPerimeter(randomNumberGenerator);
        Assert.That(
          (testDisc.Center - randomPoint).Length(),
          Is.EqualTo(testDisc.Radius).Within(36).Ulps
          // TODO: This method suffers from accuracy problems!
        );
      }
      
    }
Ejemplo n.º 14
0
        public void TestCenterOfMass()
        {
            Disc2 testDisc = new Disc2(new Vector2(12.34f, 56.78f), 20.0f);

            Assert.AreEqual(testDisc.Center, testDisc.CenterOfMass);
        }
Ejemplo n.º 15
0
        public void TestCircumferenceLength()
        {
            Disc2 testDisc = new Disc2(new Vector2(12.34f, 56.78f), 20.0f);

            Assert.AreEqual(125.66371f, testDisc.CircumferenceLength);
        }
Ejemplo n.º 16
0
        public void TestSurfaceArea()
        {
            Disc2 testDisc = new Disc2(new Vector2(12.34f, 56.78f), 20.0f);

            Assert.AreEqual(1256.63706f, testDisc.Area);
        }