public static ILocationF GetNudgeLocation(this SpacialElement el, IRectangularF desiredLocation = null, float optimalAngle = 0, int?z = null) { desiredLocation = desiredLocation ?? el.EffectiveBounds(); var obstacles = el.GetObstacles(z: z); if (obstacles.Where(o => o.Touches(desiredLocation)).Any() || SpaceTime.CurrentSpaceTime.Bounds.Contains(desiredLocation) == false) { foreach (var angle in Enumerate360Angles(optimalAngle)) { for (var d = .1f; d < 15f; d += .1f) { var effectiveAngle = angle % 360; var testLoc = desiredLocation.MoveTowards(effectiveAngle, d); var testArea = RectangularF.Create(testLoc.Left, testLoc.Top, desiredLocation.Width, desiredLocation.Height); if (obstacles.Where(o => o.Touches(testArea)).None() && SpaceTime.CurrentSpaceTime.Bounds.Contains(testArea)) { return(testLoc.TopLeft()); } } } return(null); } else { return(el.TopLeft()); } }
public static float LineOfSightVisibility(this IRectangularF from, float angle, List <IRectangularF> obstacles, float range, float increment = .5f) { for (var d = increment; d < range; d += increment) { var testLocation = from.MoveTowards(angle, d); var testRect = RectangularF.Create(testLocation.Left, testLocation.Top, from.Width, from.Height); if (obstacles.Where(o => o.Touches(testRect)).Any() || SpaceTime.CurrentSpaceTime.Bounds.Contains(testRect) == false) { return(d); } } return(range); }
public static ILocationF GetNudgeLocation(this SpacialElement el, IRectangularF desiredLocation = null, float initialAngle = 0) { desiredLocation = desiredLocation ?? el.EffectiveBounds(); var obstacles = el.GetObstacles(); if (obstacles.Where(o => o.Touches(desiredLocation)).Any()) { for (var d = 1f; d < 15; d++) { for (var angle = initialAngle; angle < initialAngle + 360; angle += 20) { var effectiveAngle = angle % 360; var testLoc = desiredLocation.MoveTowards(effectiveAngle, d); var testArea = RectangularF.Create(testLoc.Left, testLoc.Top, desiredLocation.Width, desiredLocation.Height); if (obstacles.Where(o => o.Touches(testArea)).None() && SpaceTime.CurrentSpaceTime.Bounds.Contains(testArea)) { return(testLoc.TopLeft()); } } } } return(null); }