Exemplo n.º 1
0
        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());
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private static IRectangularF GetObstacleIfMovedTo(SpacialElement el, int?z = null)
        {
            var overlaps = el.GetObstacles(z).Where(e => e.EffectiveBounds().Touches(el)).ToArray();

            return(overlaps.FirstOrDefault());
        }
Exemplo n.º 4
0
 public static bool HasLineOfSight(this SpacialElement from, IRectangularF to) => HasLineOfSight(from, to, from.GetObstacles());