public void TestFindingYIntersect() { //arrange float a = 1; Vector2 pointOnLine = Vector2.One * 2; //act float intersect = LineFormula.FindYIntersect(a, pointOnLine); //assert Assert.IsTrue(intersect == 0, "Not intersecting in origo!"); //arrange a = 2; pointOnLine = new Vector2(1, 3); //act intersect = LineFormula.FindYIntersect(a, pointOnLine); //assert Assert.IsTrue(intersect == 1, "Not intersecting in origo!"); //arrange a = -3; pointOnLine = new Vector2(1, 0); //act intersect = LineFormula.FindYIntersect(a, pointOnLine); //assert Assert.IsTrue(intersect == 3, "Not intersecting in origo!"); }
public void TestLineIntersectWithHorizontalLines() { //arrange Vector2 direction = new Vector2(3, -2); Vector2 knownPositionOnLine = new Vector2(3, 2); var line = LineFormula.FromCoordinateAndDirection(knownPositionOnLine, direction); float horizontalLinesYValue = 4; //act float xValueOfIntersectWithHorizontalLine = line.GetInterSectWithHorizontalLine(horizontalLinesYValue).Value; //assert Assert.IsTrue(xValueOfIntersectWithHorizontalLine == 0, "Not intersecting in origo!"); }
public void TestLineIntersectWithVerticalLines() { //arrange Vector2 direction = new Vector2(3, -2); Vector2 knownPositionOnLine = new Vector2(3, 2); var line = LineFormula.FromCoordinateAndDirection(knownPositionOnLine, direction); float verticalLinesXValue = -3; //act float yValueOfIntersectWithVerticalLine = line.GetInterSectWithVerticalLine(verticalLinesXValue).Value; //assert Assert.IsTrue(yValueOfIntersectWithVerticalLine == 6, "Not intersecting in origo!"); }
public void TestLineFormula() { //arrange float angleInRadians = (float)Math.PI / 4; Vector2 direction = angleInRadians.AngleAsVector(); var knownPositionOnLine = Vector2.One; //act var line = LineFormula.FromCoordinateAndDirection(knownPositionOnLine, direction); var line2 = LineFormula.FromCoordinateAndDirection(knownPositionOnLine, angleInRadians); //assert Assert.IsTrue(line.B == 0, "Not intersecting in origo!"); Assert.AreEqual(line, line2, "Not getting same line objects from constructors"); }