Example #1
0
        public void TestClosestPointHorizontal()
        {
            Ray2 ray = new Ray2(new Vector2(0.0f, 100.0f), Vector2.UnitX);

            Vector2 leftCap = ray.ClosestPointTo(new Vector2(-2.0f, 200.0f));

            Assert.AreEqual(
                new Vector2(0.0f, 100.0f), leftCap, "Closest point beyond left end found"
                );

            Vector2 leftPoint = ray.ClosestPointTo(new Vector2(0.0f, 200.0f));

            Assert.AreEqual(
                new Vector2(0.0f, 100.0f), leftPoint, "Closest point on left end found"
                );

            Vector2 midLeftRight = ray.ClosestPointTo(new Vector2(0.5f, 200.0f));

            Assert.AreEqual(
                new Vector2(0.5f, 100.0f), midLeftRight, "Closest point inmidst of line found"
                );

            Vector2 rightPoint = ray.ClosestPointTo(new Vector2(1.0f, 200.0f));

            Assert.AreEqual(
                new Vector2(1.0f, 100.0f), rightPoint, "Closest point on right end found"
                );

            Vector2 rightCap = ray.ClosestPointTo(new Vector2(3.0f, 200.0f));

            Assert.AreEqual(
                new Vector2(3.0f, 100.0f), rightCap, "Closest point beyond right end found"
                );
        }
Example #2
0
        public void TestClosestPointVertical()
        {
            Ray2 ray = new Ray2(new Vector2(100.0f, 0.0f), Vector2.UnitY);

            Vector2 leftCap = ray.ClosestPointTo(new Vector2(200.0f, -2.0f));

            Assert.AreEqual(new Vector2(100.0f, 0.0f), leftCap, "Closest point beyond lower end found");

            Vector2 leftPoint = ray.ClosestPointTo(new Vector2(200.0f, 0.0f));

            Assert.AreEqual(new Vector2(100.0f, 0.0f), leftPoint, "Closest point on lower end found");

            Vector2 midLeftRight = ray.ClosestPointTo(new Vector2(200.0f, 0.5f));

            Assert.AreEqual(new Vector2(100.0f, 0.5f), midLeftRight, "Closest point inmidst of line found");

            Vector2 rightPoint = ray.ClosestPointTo(new Vector2(200.0f, 1.0f));

            Assert.AreEqual(new Vector2(100.0f, 1.0f), rightPoint, "Closest point on upper end found");

            Vector2 rightCap = ray.ClosestPointTo(new Vector2(200.0f, 3.0f));

            Assert.AreEqual(new Vector2(100.0f, 3.0f), rightCap, "Closest point beyond upper end found");
        }
Example #3
0
    public void TestClosestPointHorizontal() {
      Ray2 ray = new Ray2(new Vector2(0.0f, 100.0f), Vector2.UnitX);

      Vector2 leftCap = ray.ClosestPointTo(new Vector2(-2.0f, 200.0f));
      Assert.AreEqual(
        new Vector2(0.0f, 100.0f), leftCap, "Closest point beyond left end found"
      );

      Vector2 leftPoint = ray.ClosestPointTo(new Vector2(0.0f, 200.0f));
      Assert.AreEqual(
        new Vector2(0.0f, 100.0f), leftPoint, "Closest point on left end found"
      );

      Vector2 midLeftRight = ray.ClosestPointTo(new Vector2(0.5f, 200.0f));
      Assert.AreEqual(
        new Vector2(0.5f, 100.0f), midLeftRight, "Closest point inmidst of line found"
      );

      Vector2 rightPoint = ray.ClosestPointTo(new Vector2(1.0f, 200.0f));
      Assert.AreEqual(
        new Vector2(1.0f, 100.0f), rightPoint, "Closest point on right end found"
      );

      Vector2 rightCap = ray.ClosestPointTo(new Vector2(3.0f, 200.0f));
      Assert.AreEqual(
        new Vector2(3.0f, 100.0f), rightCap, "Closest point beyond right end found"
      );
    }
Example #4
0
    public void TestClosestPointVertical() {
      Ray2 ray = new Ray2(new Vector2(100.0f, 0.0f), Vector2.UnitY);

      Vector2 leftCap = ray.ClosestPointTo(new Vector2(200.0f, -2.0f));
      Assert.AreEqual(new Vector2(100.0f, 0.0f), leftCap, "Closest point beyond lower end found");

      Vector2 leftPoint = ray.ClosestPointTo(new Vector2(200.0f, 0.0f));
      Assert.AreEqual(new Vector2(100.0f, 0.0f), leftPoint, "Closest point on lower end found");

      Vector2 midLeftRight = ray.ClosestPointTo(new Vector2(200.0f, 0.5f));
      Assert.AreEqual(new Vector2(100.0f, 0.5f), midLeftRight, "Closest point inmidst of line found");

      Vector2 rightPoint = ray.ClosestPointTo(new Vector2(200.0f, 1.0f));
      Assert.AreEqual(new Vector2(100.0f, 1.0f), rightPoint, "Closest point on upper end found");

      Vector2 rightCap = ray.ClosestPointTo(new Vector2(200.0f, 3.0f));
      Assert.AreEqual(new Vector2(100.0f, 3.0f), rightCap, "Closest point beyond upper end found");
    }