public void TestConstructor() { Line2 line = new Line2(new Vector2(1.0f, 2.0f), new Vector2(3.0f, 4.0f)); Assert.AreEqual(1.0f, line.Offset.X, "X offset is taken over from constructor"); Assert.AreEqual(2.0f, line.Offset.Y, "Y offset is taken over from constructor"); Assert.AreEqual(3.0f, line.Direction.X, "X direction is taken over from constructor"); Assert.AreEqual(4.0f, line.Direction.Y, "Y direction is taken over from constructor"); }
public void TestClosestPointHorizontal() { Line2 line = new Line2(new Vector2(0.0f, 100.0f), Vector2.UnitX); Vector2 leftCap = line.ClosestPointTo(new Vector2(-2.0f, 200.0f)); Assert.AreEqual(new Vector2(-2.0f, 100.0f), leftCap, "Closest point beyond left end found"); Vector2 leftPoint = line.ClosestPointTo(new Vector2(0.0f, 200.0f)); 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(3.0f, 100.0f), rightCap, "Closest point beyond right end found"); }
public void TestEqualityOperator() { Line2 line1 = new Line2(new Vector2(100.0f, 200.0f), new Vector2(300.0f, 400.0f)); Line2 line2 = new Line2(line1); Assert.AreEqual(line1, line2, "Copied line is equal to the original line"); line1.Offset.X = 0.0f; Assert.AreNotEqual(line1, line2, "Modified copy is no longer equal to the original line"); line1.Offset.X = 100.0f; line1.Offset.Y = 0.0f; Assert.AreNotEqual(line1, line2, "Modified copy is no longer equal to the original line"); line1.Offset.Y = 200.0f; line1.Direction.X = 0.0f; Assert.AreNotEqual(line1, line2, "Modified copy is no longer equal to the original line"); line1.Direction.X = 300.0f; line1.Direction.Y = 0.0f; Assert.AreNotEqual(line1, line2, "Modified copy is no longer equal to the original line"); line1.Direction.Y = 400.0f; }
public void TestEqualityOperatorAgainstNull() { Line2 line = new Line2(); Assert.IsFalse(line.Equals(null), "Initialized Line is not equal to null"); }
public void TestSerialization() { XmlSerializer serializer = new XmlSerializer(typeof(Line2)); System.IO.MemoryStream stream = new System.IO.MemoryStream(); Line2 line = new Line2(new Vector2(123.0f, 456.0f), new Vector2(654.0f, 321.0f)); serializer.Serialize(stream, line); stream.Seek(0, System.IO.SeekOrigin.Begin); Line2 restored = (Line2)serializer.Deserialize(stream); Assert.AreEqual(line, restored, "Deserialized line matches serialized line"); }
public void TestClosestPointVertical() { Line2 line = new Line2(new Vector2(100.0f, 0.0f), Vector2.UnitY); Vector2 leftCap = line.ClosestPointTo(new Vector2(200.0f, -2.0f)); Assert.AreEqual(new Vector2(100.0f, -2.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, 3.0f), rightCap, "Closest point beyond upper end found"); }
/// <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(Line2 other) { if(other == null) return false; else return (this.Offset == other.Offset) && (this.Direction == other.Direction); }
public Line2(Line2 other) : this(other.Offset, other.Direction) { }