/// <summary> /// Gets if an <see cref="ISpatial"/> and <see cref="Rectangle"/> occupy any common space. /// </summary> /// <param name="a">The <see cref="ISpatial"/>.</param> /// <param name="b">The <see cref="Rectangle"/>.</param> /// <returns>True if the two occupy any common space; otherwise false.</returns> public static bool Intersects(this ISpatial a, Rectangle b) { bool ret; a.ToRectangle().Intersects(ref b, out ret); return(ret); }
/// <summary> /// Gets a <see cref="Rectangle"/> that represents the valid area that items can be picked up at from /// the given <paramref name="spatial"/>. /// </summary> /// <param name="spatial">The <see cref="ISpatial"/> doing the picking-up.</param> /// <returns>A <see cref="Rectangle"/> that represents the area region that items can be picked up at from /// the given <paramref name="spatial"/>.</returns> public static Rectangle GetPickupArea(ISpatial spatial) { const int padding = 70; var r = spatial.ToRectangle(); return(new Rectangle(r.X - padding, r.Y - padding, r.Width + (padding * 2), r.Height + (padding * 2))); }
/// <summary> /// Gets if an <see cref="ISpatial"/> and another <see cref="ISpatial"/> occupy any common space. /// </summary> /// <param name="a">The first <see cref="ISpatial"/>.</param> /// <param name="b">The other <see cref="ISpatial"/>.</param> /// <returns>True if the two occupy any common space; otherwise false.</returns> public static bool Intersects(this ISpatial a, ISpatial b) { var bRect = b.ToRectangle(); bool ret; a.ToRectangle().Intersects(ref bRect, out ret); return(ret); }
/// <summary> /// Draws a <see cref="ISpatial"/> that is selected, but NOT focused on. This is primarily /// intended for when selecting multiple items at once to give an indication on what other /// objects are selected but to distinguish that they are not the focused objects. /// </summary> /// <param name="spatial">The <see cref="ISpatial"/> that is selected but not focused on.</param> /// <param name="sb">The <see cref="ISpriteBatch"/> to draw to.</param> public static void DrawNotFocused(ISpatial spatial, ISpriteBatch sb) { if (spatial == null) { return; } var r = spatial.ToRectangle(); RenderRectangle.Draw(sb, r, _nonfocusedColor, _nonfocusedBorderColorInner); var r2 = new Rectangle(r.X - 1, r.Y - 1, r.Width + 2, r.Height + 2); RenderRectangle.Draw(sb, r2, new Color(0, 0, 0, 0), _nonfocusedBorderColorOuter); }
/// <summary> /// Finds the Users close enough to the <paramref name="toSynchronize"/> to synchronize their /// Position and Velocity to. /// </summary> /// <param name="toSynchronize">The <see cref="ISpatial"/> to synchronize.</param> /// <returns>An IEnumerable of Users close enough to the <paramref name="toSynchronize"/> that they /// need to have the <paramref name="toSynchronize"/>'s Position and Velocity synchronized.</returns> IEnumerable <User> GetUsersToSyncPandVTo(ISpatial toSynchronize) { int xPad = (int)(GameData.ScreenSize.X * 1.5); int yPad = (int)(GameData.ScreenSize.Y * 1.5); var syncRegion = toSynchronize.ToRectangle().Inflate(xPad, yPad); foreach (var user in Users) { Rectangle userRegion = user.ToRectangle(); if (syncRegion.Intersects(userRegion)) { yield return(user); } } }
/// <summary> /// Finds the Users close enough to the <paramref name="toSynchronize"/> to synchronize their /// Position and Velocity to. /// </summary> /// <param name="toSynchronize">The <see cref="ISpatial"/> to synchronize.</param> /// <returns>An IEnumerable of Users close enough to the <paramref name="toSynchronize"/> that they /// need to have the <paramref name="toSynchronize"/>'s Position and Velocity synchronized.</returns> IEnumerable <User> GetUsersToSyncPandVTo(ISpatial toSynchronize) { var xPad = (int)(GameData.ScreenSize.X * 1.5); var yPad = (int)(GameData.ScreenSize.Y * 1.5); var r = toSynchronize.ToRectangle(); var syncRegion = new Rectangle(r.X - xPad, r.Y - yPad, r.Width + xPad * 2, r.Height + xPad * 2); foreach (var user in Users) { var userRegion = user.ToRectangle(); if (syncRegion.Intersects(userRegion)) { yield return(user); } } }
/// <summary> /// Gets a <see cref="Rectangle"/> that represents the valid area that items can be picked up at from /// the given <paramref name="spatial"/>. /// </summary> /// <param name="spatial">The <see cref="ISpatial"/> doing the picking-up.</param> /// <returns>A <see cref="Rectangle"/> that represents the area region that items can be picked up at from /// the given <paramref name="spatial"/>.</returns> public static Rectangle GetPickupArea(ISpatial spatial) { const int padding = 70; return spatial.ToRectangle().Inflate(padding); }
/// <summary> /// Gets the distance between this <see cref="ISpatial"/> and another. /// </summary> /// <param name="spatial">The first <see cref="ISpatial"/>.</param> /// <param name="other">The other <see cref="ISpatial"/>.</param> /// <returns>The distance between this <see cref="ISpatial"/> and another <see cref="ISpatial"/> as an /// absolute value greater than or equal to zero. If this intersects <paramref name="other"/>, the /// value will be 0. Otherwise, the value will be the length of the shortest path between the two /// <see cref="ISpatial"/>s.</returns> public static int GetDistance(this ISpatial spatial, ISpatial other) { return spatial.ToRectangle().GetDistance(other.ToRectangle()); }
/// <summary> /// Finds the Users close enough to the <paramref name="toSynchronize"/> to synchronize their /// Position and Velocity to. /// </summary> /// <param name="toSynchronize">The <see cref="ISpatial"/> to synchronize.</param> /// <returns>An IEnumerable of Users close enough to the <paramref name="toSynchronize"/> that they /// need to have the <paramref name="toSynchronize"/>'s Position and Velocity synchronized.</returns> IEnumerable<User> GetUsersToSyncPandVTo(ISpatial toSynchronize) { var xPad = (int)(GameData.ScreenSize.X * 1.5); var yPad = (int)(GameData.ScreenSize.Y * 1.5); var r = toSynchronize.ToRectangle(); var syncRegion = new Rectangle(r.X - xPad, r.Y - yPad, r.Width + xPad * 2, r.Height + xPad * 2); foreach (var user in Users) { var userRegion = user.ToRectangle(); if (syncRegion.Intersects(userRegion)) yield return user; } }
/// <summary> /// Gets if an <see cref="ISpatial"/> and another <see cref="ISpatial"/> occupy any common space. /// </summary> /// <param name="a">The first <see cref="ISpatial"/>.</param> /// <param name="b">The other <see cref="ISpatial"/>.</param> /// <returns>True if the two occupy any common space; otherwise false.</returns> public static bool Intersects(this ISpatial a, ISpatial b) { var bRect = b.ToRectangle(); bool ret; a.ToRectangle().Intersects(ref bRect, out ret); return ret; }
/// <summary> /// Gets if an <see cref="ISpatial"/> is fully contained inside of another <see cref="ISpatial"/>. That is, if /// the <see cref="contained"/> resides completely inside of the <see cref="container"/>. /// </summary> /// <param name="container">The <see cref="ISpatial"/> to check if it contains the <see cref="contained"/>.</param> /// <param name="contained">The <see cref="ISpatial"/> to check if is contained.</param> /// <returns>If the <paramref name="contained"/> is fully contained inside of the /// <paramref name="container"/>.</returns> public static bool Contains(this ISpatial container, ISpatial contained) { return container.ToRectangle().Contains(contained.ToRectangle()); }
/// <summary> /// Gets a <see cref="Rectangle"/> representing the area that an <see cref="ISpatial"/> occupies, plus some /// padding in all directions. /// </summary> /// <param name="spatial">The <see cref="ISpatial"/> to get the rectangle for.</param> /// <param name="padding">How many units to expand the resulting <see cref="Rectangle"/> in each direction.</param> /// <returns>A <see cref="Rectangle"/> representing the area that an <see cref="ISpatial"/> occupies, plus some /// padding in all directions.</returns> public static Rectangle ToRectangle(this ISpatial spatial, int padding) { var r = spatial.ToRectangle(); return(new Rectangle(r.X - padding, r.Y - padding, r.Width + (padding * 2), r.Height + (padding * 2))); }
/// <summary> /// Gets a <see cref="Rectangle"/> that represents the valid area that items can be picked up at from /// the given <paramref name="spatial"/>. /// </summary> /// <param name="spatial">The <see cref="ISpatial"/> doing the picking-up.</param> /// <returns>A <see cref="Rectangle"/> that represents the area region that items can be picked up at from /// the given <paramref name="spatial"/>.</returns> public static Rectangle GetPickupArea(ISpatial spatial) { const int padding = 70; var r = spatial.ToRectangle(); return new Rectangle(r.X - padding, r.Y - padding, r.Width + (padding * 2), r.Height + (padding * 2)); }
/// <summary> /// Gets a <see cref="Rectangle"/> that represents the valid area that items can be picked up at from /// the given <paramref name="spatial"/>. /// </summary> /// <param name="spatial">The <see cref="ISpatial"/> doing the picking-up.</param> /// <returns>A <see cref="Rectangle"/> that represents the area region that items can be picked up at from /// the given <paramref name="spatial"/>.</returns> public static Rectangle GetPickupArea(ISpatial spatial) { const int padding = 70; return(spatial.ToRectangle().Inflate(padding)); }
/// <summary> /// Gets a <see cref="Rectangle"/> containing the area that the <paramref name="shopper"/> may use to /// shop. Any <see cref="Entity"/> that owns a shop and intersects with this area is considered in a valid /// distance to shop with. /// </summary> /// <param name="shopper">The <see cref="Entity"/> doing the shopping.</param> /// <returns>A <see cref="Rectangle"/> containing the area that the <paramref name="shopper"/> may use to /// shop.</returns> public static Rectangle GetValidShopArea(ISpatial shopper) { return shopper.ToRectangle(); }
/// <summary> /// Draws a <see cref="ISpatial"/> that is selected, but NOT focused on. This is primarily /// intended for when selecting multiple items at once to give an indication on what other /// objects are selected but to distinguish that they are not the focused objects. /// </summary> /// <param name="spatial">The <see cref="ISpatial"/> that is selected but not focused on.</param> /// <param name="sb">The <see cref="ISpriteBatch"/> to draw to.</param> public static void DrawNotFocused(ISpatial spatial, ISpriteBatch sb) { if (spatial == null) return; var r = spatial.ToRectangle(); RenderRectangle.Draw(sb, r, _nonfocusedColor, _nonfocusedBorderColorInner); var r2 = new Rectangle(r.X - 1, r.Y - 1, r.Width + 2, r.Height + 2); RenderRectangle.Draw(sb, r2, new Color(0, 0, 0, 0), _nonfocusedBorderColorOuter); }
/// <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())); }
/// <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)); }
/// <summary> /// Finds the Users close enough to the <paramref name="toSynchronize"/> to synchronize their /// Position and Velocity to. /// </summary> /// <param name="toSynchronize">The <see cref="ISpatial"/> to synchronize.</param> /// <returns>An IEnumerable of Users close enough to the <paramref name="toSynchronize"/> that they /// need to have the <paramref name="toSynchronize"/>'s Position and Velocity synchronized.</returns> IEnumerable<User> GetUsersToSyncPandVTo(ISpatial toSynchronize) { int xPad = (int)(GameData.ScreenSize.X * 1.5); int yPad = (int)(GameData.ScreenSize.Y * 1.5); var syncRegion = toSynchronize.ToRectangle().Inflate(xPad, yPad); foreach (var user in Users) { Rectangle userRegion = user.ToRectangle(); if (syncRegion.Intersects(userRegion)) yield return user; } }
/// <summary> /// Gets if a <see cref="Rectangle"/> is fully contained inside of a <see cref="ISpatial"/>. That is, if /// the <see cref="contained"/> resides completely inside of the <see cref="container"/>. /// </summary> /// <param name="container">The <see cref="ISpatial"/> to check if it contains the <see cref="contained"/>.</param> /// <param name="contained">The <see cref="Rectangle"/> to check if is contained.</param> /// <returns>If the <paramref name="contained"/> is fully contained inside of the /// <paramref name="container"/>.</returns> public static bool Contains(this ISpatial container, Rectangle contained) { return(container.ToRectangle().Contains(contained)); }
/// <summary> /// Gets a <see cref="Rectangle"/> containing the area that the <paramref name="shopper"/> may use to /// shop. Any <see cref="Entity"/> that owns a shop and intersects with this area is considered in a valid /// distance to shop with. /// </summary> /// <param name="shopper">The <see cref="Entity"/> doing the shopping.</param> /// <returns>A <see cref="Rectangle"/> containing the area that the <paramref name="shopper"/> may use to /// shop.</returns> public static Rectangle GetValidShopArea(ISpatial shopper) { return(shopper.ToRectangle()); }
/// <summary> /// Gets the distance between this <see cref="ISpatial"/> and a <see cref="Rectangle"/>. /// </summary> /// <param name="spatial">The <see cref="ISpatial"/>.</param> /// <param name="other">The rectangle.</param> /// <returns>The distance between this <see cref="ISpatial"/> and the <see cref="Rectangle"/> as an /// absolute value greater than or equal to zero. If this intersects <paramref name="other"/>, the /// value will be 0. Otherwise, the value will be the length of the shortest path between the two /// <see cref="ISpatial"/>s.</returns> public static int GetDistance(this ISpatial spatial, Rectangle other) { return(spatial.ToRectangle().GetDistance(other)); }