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" ); }
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" ); }
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" ); }
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" ); }