Esempio n. 1
0
        private List <ISpatial> Cast <T>(int x0, int y0, int x1, int y1, bool needMany, out Vector2 finalPoint)
        {
            int dx = Math.Abs(x1 - x0);
            int dy = Math.Abs(y1 - y0);

            int sx;
            int sy;

            if (x0 < x1)
            {
                sx = 1;
            }
            else
            {
                sx = -1;
            }

            if (y0 < y1)
            {
                sy = 1;
            }
            else
            {
                sy = -1;
            }

            int err = dx - dy;
            int e2;
            var temp = new List <ISpatial>();

            while (true)
            {
                finalPoint = new Vector2(x0, y0);

                var res = _mapSpatialCollection.GetMany(finalPoint).OfType <T>();

                foreach (ISpatial s in res)
                {
                    // Don't add the same ISpatial twice
                    if (!temp.Contains(s))
                    {
                        // Don't add ourselves
                        if (s != _owner)
                        {
                            temp.Add(s);
                        }

                        // Only return the first if required
                        if (!temp.IsEmpty() && !needMany)
                        {
                            return(temp);
                        }
                    }
                }

                if ((x0 == x1) && (y0 == y1))
                {
                    break;
                }

                e2 = err << 1;

                if (e2 > -dy)
                {
                    err = err - dy;
                    x0  = x0 + sx;
                }

                if (e2 < dx)
                {
                    err = err + dx;
                    y0  = y0 + sy;
                }
            }

            if (!temp.IsEmpty())
            {
                return(temp);
            }

            return(null);
        }
Esempio n. 2
0
 /// <summary>
 /// Gets the <see cref="ISpatial"/>s found intersecting the given region.
 /// </summary>
 /// <param name="c">The <see cref="ISpatialCollection"/>.</param>
 /// <param name="spatial">The <see cref="ISpatial"/> representing the map area to check.</param>
 /// <typeparam name="T">Type of ISpatial to convert to.</typeparam>
 /// <returns>List of all <see cref="ISpatial"/>s found intersecting the given region.</returns>
 public static IEnumerable <T> GetMany <T>(this ISpatialCollection c, ISpatial spatial)
 {
     return(c.GetMany <T>(spatial.ToRectangle()));
 }
Esempio n. 3
0
        private ISpatial Cast <T>(int x0, int y0, int x1, int y1, out Vector2 finalPoint)
        {
            int dx = Math.Abs(x1 - x0);
            int dy = Math.Abs(y1 - y0);

            int sx = 0;
            int sy = 0;

            if (x0 < x1)
            {
                sx = 1;
            }
            else
            {
                sx = -1;
            }

            if (y0 < y1)
            {
                sy = 1;
            }
            else
            {
                sy = -1;
            }

            int err = dx - dy;

            int e2;

            while (true)
            {
                finalPoint = new Vector2(x0, y0);

                var res = _mapSpatialCollection.GetMany(finalPoint).OfType <T>();

                if (res.Count() > 0)
                {
                    return(_mapSpatialCollection.Get(finalPoint));
                }


                if ((x0 == x1) && (y0 == y1))
                {
                    break;
                }

                e2 = err << 1;

                if (e2 > -dy)
                {
                    err = err - dy;
                    x0  = x0 + sx;
                }

                if (e2 < dx)
                {
                    err = err + dx;
                    y0  = y0 + sy;
                }
            }
            return(null);
        }
Esempio n. 4
0
 /// <summary>
 /// Gets the <see cref="ISpatial"/>s found intersecting the given region.
 /// </summary>
 /// <param name="c">The <see cref="ISpatialCollection"/>.</param>
 /// <param name="spatial">The <see cref="ISpatial"/> representing the map area to check.</param>
 /// <param name="condition">Condition the <see cref="ISpatial"/>s must meet.</param>
 /// <typeparam name="T">Type of ISpatial to convert to.</typeparam>
 /// <returns>List of all <see cref="ISpatial"/>s found intersecting the given region.</returns>
 public static IEnumerable <T> GetMany <T>(this ISpatialCollection c, ISpatial spatial, Predicate <T> condition)
 {
     return(c.GetMany(spatial.ToRectangle(), condition));
 }