public void OneMine_ExpectTrue() { var board = MakeBoard(); board.Turtle.Position = new Position(1, 1); var expected = typeof(Mine); var collision = new Collision(board); var gameObject = collision.Check(board.Turtle); Assert.AreEqual(expected, gameObject.GetType()); }
public void MultipleMines_ExpectNull() { var board = MakeBoard(); board.Turtle.Position = new Position(2, 1); var expected = typeof(Mine); var collision = new Collision(board); var gameObject = collision.Check(board.Turtle); Assert.IsNull(gameObject); }
public List <LED> GetAll(Image <Bgr, Byte> src, out int lightCount) { List <LED> leds = new List <LED>(); var range = RangeImage(src); var rangeLight = LightImage(src); List <Rectangle> _lightRects = new List <Rectangle>(); using (MemStorage lightStorage = new MemStorage()) { for (Contour <Point> contours = rangeLight.FindContours(approximationMethod, retrieveType, lightStorage); contours != null; contours = contours.HNext) { Contour <Point> currentContour = contours.ApproxPoly(contours.Perimeter * LEDApproximation, lightStorage); if (GeometryExt.Area(currentContour.BoundingRectangle) >= MinLightArea && GeometryExt.Area(currentContour.BoundingRectangle) <= MaxLightArea) { _lightRects.Add(currentContour.BoundingRectangle); } } for (int k = 0; k < _lightRects.Count; k++) { for (int k2 = 0; k2 < _lightRects.Count; k2++) { if (k != k2) { if (GeometryExt.Distance(_lightRects[k], _lightRects[k2]) < MergeDist) { _lightRects[k] = GeometryExt.Join(_lightRects[k], _lightRects[k2]); _lightRects.RemoveAt(k2); k = -1; break; } } } } lightCount = _lightRects.Count; using (MemStorage storage = new MemStorage()) { for (Contour <Point> contours = range.FindContours(approximationMethod, retrieveType, storage); contours != null; contours = contours.HNext) { Contour <Point> currentContour = contours.ApproxPoly(contours.Perimeter * LEDApproximation, storage); if (GeometryExt.Area(currentContour.BoundingRectangle) >= MinArea && GeometryExt.Area(currentContour.BoundingRectangle) <= MaxArea) { LED led = new LED(); led.HaloBox = currentContour.BoundingRectangle; led.HaloColor = HaloColor; led.LightColor = LightColor; for (int k = 0; k < _lightRects.Count; k++) //check inside ones with priority { Rectangle r = _lightRects[k]; if (GeometryExt.Area(currentContour.BoundingRectangle) >= GeometryExt.Area(r) * areaMul) { if (Collision.Inside(currentContour.BoundingRectangle, r)) { led.InsideLightBoxes.Add(r); } else if (Collision.Check(currentContour.BoundingRectangle, r)) { led.CollidingLightBoxes.Add(r); } } } if (led.MainLightBox != new Rectangle()) //good led found, add it to results { led.InsideLightBoxes = led.InsideLightBoxes.OrderByDescending(x => GeometryExt.Area(x)).ToList(); led.CollidingLightBoxes = led.CollidingLightBoxes.OrderByDescending(x => GeometryExt.Area(x)).ToList(); leds.Add(led); } } } } } range.Dispose(); rangeLight.Dispose(); return(leds); }