예제 #1
0
 public void TestDistance() {
     Vector p1 = new Vector(0, 0);
     Vector p2 = new Vector(3, 4);
     Assert.IsTrue(p1.Distance(p2) == 5, "Distance calc 1 failed");
     Assert.IsTrue(p1.Distance2(p2) == 25, "Distance2 calc 1 failed");
     Assert.IsTrue(new Vector(1, 1).Closest(p1, new Vector(2, 0)) == new Vector(1, 0), "Closest point 1 failed.");
     //Same test for point that is already on the line
     Assert.IsTrue(new Vector(1, 0).Closest(p1, new Vector(2, 0)) == new Vector(1, 0), "Closest point 3 failed.");
 }
예제 #2
0
 public void TestAngleProjection() {
     //Test GetPointAt in all 8 cardinal directions.  Origin assumed to be in top-left
     var tests = new List<KeyValuePair<double, Vector>>();
     tests.Add(new KeyValuePair<double, Vector>(0d, new Vector(1, 0)));
     tests.Add(new KeyValuePair<double, Vector>(Math.PI / 4, new Vector(1, -1)));
     tests.Add(new KeyValuePair<double, Vector>(Math.PI / 2, new Vector(0, -1)));
     tests.Add(new KeyValuePair<double, Vector>(3 * Math.PI / 4, new Vector(-1, -1)));
     tests.Add(new KeyValuePair<double, Vector>(Math.PI, new Vector(-1, 0)));
     tests.Add(new KeyValuePair<double, Vector>(-3 * Math.PI / 4, new Vector(-1, 1)));
     tests.Add(new KeyValuePair<double, Vector>(-Math.PI / 2, new Vector(0, 1)));
     tests.Add(new KeyValuePair<double, Vector>(-Math.PI / 4, new Vector(1, 1)));
     string format = "GetPointAt fails on {0}.  Expected {1}, got {2}";
     Vector origin = new Vector(0, 0);
     foreach (var pair in tests) {
         double hypotenuse = origin.Distance(pair.Value);
         Vector point = origin.GetPointAt(hypotenuse, pair.Key);
         Assert.IsTrue(point == pair.Value,
             string.Format(format, pair.Key, pair.Value, point));
     }
 }