public void VectorMath_DetermineQuadrant() { uint quadrant; // 1st quadrant, on the same line to the left, angle = 0 quadrant = VectorMath.DetermineQuadrant(new Point(10, 10), new Point(9, 10)); Assert.AreEqual((uint)1, quadrant); // 1st quadrant, angle 45 degree (PI/4) quadrant = VectorMath.DetermineQuadrant(new Point(10, 10), new Point(7, 7)); Assert.AreEqual((uint)1, quadrant); // 2nd quadrant, angle 90 degree (PI/2) quadrant = VectorMath.DetermineQuadrant(new Point(10, 10), new Point(10, 8)); Assert.AreEqual((uint)2, quadrant); // 2nd quadrant, angle 135 degree (3/4 PI) quadrant = VectorMath.DetermineQuadrant(new Point(10, 10), new Point(11, 9)); Assert.AreEqual((uint)2, quadrant); // 3rd quadrant, angle 180 degree (PI) quadrant = VectorMath.DetermineQuadrant(new Point(10, 10), new Point(11, 10)); Assert.AreEqual((uint)3, quadrant); // 3rd quadrant, angle 225 degree (5/4 PI) quadrant = VectorMath.DetermineQuadrant(new Point(10, 10), new Point(12, 12)); Assert.AreEqual((uint)3, quadrant); // 3rd quadrant... quadrant = VectorMath.DetermineQuadrant(new Point(10, 10), new Point(1100, 5000)); Assert.AreEqual((uint)3, quadrant); // 4th quadrant, angle 270 degree (3/2 PI) quadrant = VectorMath.DetermineQuadrant(new Point(10, 10), new Point(10, 14)); Assert.AreEqual((uint)4, quadrant); // 4th quadrant, angle 315 degree (7/4 PI) quadrant = VectorMath.DetermineQuadrant(new Point(10, 10), new Point(9, 11)); Assert.AreEqual((uint)4, quadrant); }
public void ComputerDriverHelper_FilterCandidatePoints_RemoveUnfavorableDir() { Point middleGridPoint = new Point(20, 10); // routeGridPoints with a valid x+2, y-2 movement in the first quadrant IList <Point> routeGridPoints = new List <Point>(); Point startPoint = new Point(5, 10); Point endPoint = new Point(7, 8); routeGridPoints.Add(startPoint); routeGridPoints.Add(endPoint); uint quadrant = VectorMath.DetermineQuadrant(middleGridPoint, endPoint); Assert.AreEqual((uint)1, quadrant); bool resultValidity = ComputerDriverHelper.DirectionValid4Quadrant(quadrant, startPoint, endPoint); Assert.IsTrue(resultValidity); { // the regular list of candidates (for a standard car with acceleration = 1) // all of which are valid IList <Point> candidateGridPoints = new List <Point>(); candidateGridPoints.Add(new Point(8, 5)); candidateGridPoints.Add(new Point(8, 6)); candidateGridPoints.Add(new Point(8, 7)); candidateGridPoints.Add(new Point(9, 5)); candidateGridPoints.Add(new Point(9, 6)); candidateGridPoints.Add(new Point(9, 7)); candidateGridPoints.Add(new Point(10, 5)); candidateGridPoints.Add(new Point(10, 6)); candidateGridPoints.Add(new Point(10, 7)); IList <Point> filterResult = ComputerDriverHelper.FilterCandidatePoints_RemoveUnfavorableDir(candidateGridPoints, routeGridPoints, middleGridPoint); Assert.AreEqual(candidateGridPoints.Count, filterResult.Count); } { IList <Point> candidateGridPoints = new List <Point>(); // 3 valid candidateGridPoints.Add(new Point(8, 5)); candidateGridPoints.Add(new Point(8, 6)); candidateGridPoints.Add(new Point(8, 7)); // 5 invalid candidateGridPoints.Add(new Point(6, 5)); // x too small candidateGridPoints.Add(new Point(6, 100)); // x too small, y too big candidateGridPoints.Add(new Point(10, 100)); // y too small candidateGridPoints.Add(new Point(1, 1)); candidateGridPoints.Add(new Point(1000, 1000)); IList <Point> filterResult = ComputerDriverHelper.FilterCandidatePoints_RemoveUnfavorableDir(candidateGridPoints, routeGridPoints, middleGridPoint); Assert.AreEqual(3, filterResult.Count); } { IList <Point> candidateGridPoints = new List <Point>(); // 5 invalid candidateGridPoints.Add(new Point(6, 5)); // x too small candidateGridPoints.Add(new Point(6, 100)); // x too small, y too big candidateGridPoints.Add(new Point(10, 100)); // y too small candidateGridPoints.Add(new Point(1, 1)); // x too small candidateGridPoints.Add(new Point(1000, 1000)); // y too big IList <Point> filterResult = ComputerDriverHelper.FilterCandidatePoints_RemoveUnfavorableDir(candidateGridPoints, routeGridPoints, middleGridPoint); Assert.AreEqual(0, filterResult.Count); } { IList <Point> candidateGridPoints = new List <Point>(); IList <Point> filterResult = ComputerDriverHelper.FilterCandidatePoints_RemoveUnfavorableDir(candidateGridPoints, routeGridPoints, middleGridPoint); Assert.AreEqual(0, filterResult.Count); } }