private bool IsLocationInCorner() { var p1 = new VectorF(Location, new PointF(0, 0)); var p2 = new VectorF(Location, new PointF(Aquarium.Size.Width, 0)); var p3 = new VectorF(Location, new PointF(0, Aquarium.Size.Height)); var p4 = new VectorF(Location, new PointF(Aquarium.Size.Width, Aquarium.Size.Height)); return(p1.GetLength() < Settings.BlueNeon.CornerRadius || p2.GetLength() < Settings.BlueNeon.CornerRadius || p3.GetLength() < Settings.BlueNeon.CornerRadius || p4.GetLength() < Settings.BlueNeon.CornerRadius); }
private void Walking() { if (_nextPointSleep == null) { _nextPointSleep = GetRandomPoint(); Direction = new VectorF(((PointF)_nextPointSleep).X - Location.X, ((PointF)_nextPointSleep).Y - Location.Y); } var vectorToNextPoint = new VectorF(Location, (PointF)_nextPointSleep); if (vectorToNextPoint.GetLength() < GetStepLength()) { _nextPointSleep = null; _counter = 60 * 3; PushState(Sleep, FishState.Sleep); } else { MoveTo(GetNextPoint()); } }
public static BoundingArea GetBoundingArea(float x1, float y1, float x2, float y2) { #if !SIMPLE_BOUNDING_AREA if (x1 == x2 || y1 == y2) { return(new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2))); } float delta = Math.Abs((x2 - x1) / (y2 - y1)); float stepMax = (float)Math.Sqrt(mMaxBoxArea / delta + delta * mMaxBoxArea); VectorF line = new VectorF(x1, y1, x2, y2); float lineLen = line.GetLength(); if (stepMax >= lineLen) { return(new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2))); } BoundingArea boundingArea = new BoundingArea(); int steps = (int)Math.Ceiling(lineLen / stepMax); VectorF stepVec = line; stepVec.SetLength(lineLen / (float)steps); VectorF pt1 = new VectorF(x1, y1); VectorF pt2; for (int i = 0; i < steps - 1; i++) { pt2 = pt1 + stepVec; boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y)); pt1 = pt2; } pt2 = new VectorF(x2, y2); boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y)); return(boundingArea); #else BoundingArea boundingArea = new BoundingArea(); boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)); return(boundingArea); #endif }
public void VectorLengthIsOne() { var zero = Math.Abs(1 - _vector1.GetLength()); zero.Should().BeLessThan(Epsilon); }
public static BoundingArea GetBoundingArea(float x1, float y1, float x2, float y2) { #if !SIMPLE_BOUNDING_AREA if (x1 == x2 || y1 == y2) { return new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)); } float delta = Math.Abs((x2 - x1) / (y2 - y1)); float stepMax = (float)Math.Sqrt(mMaxBoxArea / delta + delta * mMaxBoxArea); VectorF line = new VectorF(x1, y1, x2, y2); float lineLen = line.GetLength(); if (stepMax >= lineLen) { return new BoundingArea(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)); } BoundingArea boundingArea = new BoundingArea(); int steps = (int)Math.Ceiling(lineLen / stepMax); VectorF stepVec = line; stepVec.SetLength(lineLen / (float)steps); VectorF pt1 = new VectorF(x1, y1); VectorF pt2; for (int i = 0; i < steps - 1; i++) { pt2 = pt1 + stepVec; boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y)); pt1 = pt2; } pt2 = new VectorF(x2, y2); boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(pt1.X, pt1.Y, pt2.X, pt2.Y)); return boundingArea; #else BoundingArea boundingArea = new BoundingArea(); boundingArea.AddRectangles(VisualizationUtils.CreateRectangle(x1, y1, x2, y2)); return boundingArea; #endif }