Exemplo n.º 1
0
    public void TestClosestPointHorizontal() {
      Segment2 line = new Segment2(new Vector2(0.0f, 100.0f), new Vector2(1.0f, 100.0f));

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

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

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

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

      Vector2 rightCap = line.ClosestPointTo(new Vector2(3.0f, 200.0f));
      Assert.AreEqual(
        new Vector2(1.0f, 100.0f), rightCap, "Closest point beyond right end found"
      );
    }
Exemplo n.º 2
0
    public void TestConstructor() {
      Segment2 line = new Segment2(new Vector2(1.0f, 2.0f), new Vector2(3.0f, 4.0f));

      Assert.AreEqual(1.0f, line.Start.X, "X start is taken over from constructor");
      Assert.AreEqual(2.0f, line.Start.Y, "Y start is taken over from constructor");
      Assert.AreEqual(3.0f, line.End.X, "X end is taken over from constructor");
      Assert.AreEqual(4.0f, line.End.Y, "Y end is taken over from constructor");
    }
Exemplo n.º 3
0
    public void TestEqualityOperator() {
      Segment2 segment1 = new Segment2(new Vector2(100.0f, 200.0f), new Vector2(300.0f, 400.0f));
      Segment2 segment2 = new Segment2(segment1);

      Assert.AreEqual(segment1, segment2, "Copied segment is equal to the Startal segment");

      segment1.Start.X = 0.0f;
      Assert.AreNotEqual(segment1, segment2, "Modified copy is no longer equal to the Startal segment");
      segment1.Start.X = 100.0f;

      segment1.Start.Y = 0.0f;
      Assert.AreNotEqual(segment1, segment2, "Modified copy is no longer equal to the Startal segment");
      segment1.Start.Y = 200.0f;

      segment1.End.X = 0.0f;
      Assert.AreNotEqual(segment1, segment2, "Modified copy is no longer equal to the Startal segment");
      segment1.End.X = 300.0f;

      segment1.End.Y = 0.0f;
      Assert.AreNotEqual(segment1, segment2, "Modified copy is no longer equal to the Startal segment");
      segment1.End.Y = 400.0f;
    }
Exemplo n.º 4
0
 public void TestEqualityOperatorAgainstNull() {
   Segment2 line = new Segment2();
   
   Assert.IsFalse(line.Equals(null), "Initialized Line is not equal to null");
 }
Exemplo n.º 5
0
    public void TestSerialization() {
      XmlSerializer serializer = new XmlSerializer(typeof(Segment2));

      System.IO.MemoryStream stream = new System.IO.MemoryStream();
      Segment2 segment = new Segment2(new Vector2(123.0f, 456.0f), new Vector2(654.0f, 321.0f));
      serializer.Serialize(stream, segment);

      stream.Seek(0, System.IO.SeekOrigin.Begin);
      Segment2 restored = (Segment2)serializer.Deserialize(stream);

      Assert.AreEqual(segment, restored, "Deserialized segment matches serialized segment");
    }
Exemplo n.º 6
0
    public void TestClosestPointVertical() {
      Segment2 line = new Segment2(new Vector2(100.0f, 0.0f), new Vector2(100.0f, 1.0f));

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

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

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

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

      Vector2 rightCap = line.ClosestPointTo(new Vector2(200.0f, 3.0f));
      Assert.AreEqual(
        new Vector2(100.0f, 1.0f), rightCap, "Closest point beyond upper end found"
      );
    }
Exemplo n.º 7
0
 public Segment2(Segment2 other) {
   Start = other.Start;
   End = other.End;
 }
Exemplo n.º 8
0
 /// <summary>Checks whether another instance is equal to this instance</summary>
 /// <param name="other">Other instance to compare to this instance</param>
 /// <returns>True if the other instance is equal to this instance</returns>
 public virtual bool Equals(Segment2 other) {
   if(other == null)
     return false;
   else
     return (this.Start == other.Start) && (this.End == other.End);
 }