/// <summary> /// Returns whether or not the given map area intersects the current one. If you intend to /// determine/use the exact intersection based on this return value, it is best to instead /// call the <see cref="MapArea.GetIntersection(IReadOnlyMapArea, IReadOnlyMapArea)"/>, and /// check the number of positions in the result (0 if no intersection). /// </summary> /// <param name="area">The area to check.</param> /// <returns>True if the given map area intersects the current one, false otherwise.</returns> public bool Intersects(IReadOnlyMapArea area) { if (!area.Bounds.Intersects(Bounds)) { return(false); } if (Count <= area.Count) { foreach (var pos in Positions) { if (area.Contains(pos)) { return(true); } } return(false); } foreach (var pos in area.Positions) { if (Contains(pos)) { return(true); } } return(false); }
/// <summary> /// Gets a MapArea containing all positions in <paramref name="area1"/>, minus those that are in /// <paramref name="area2"/>. /// </summary> /// <param name="area1">The first MapArea.</param> /// <param name="area2">The second MapArea.</param> /// <returns>A MapArea with exactly those positions in <paramref name="area1"/> that are NOT in /// <paramref name="area2"/>.</returns> public static MapArea GetDifference(IReadOnlyMapArea area1, IReadOnlyMapArea area2) { var retVal = new MapArea(); foreach (var pos in area1.Positions) { if (area2.Contains(pos)) { continue; } retVal.Add(pos); } return(retVal); }
/// <summary> /// Gets a MapArea containing exactly those positions contained in both of the given MapAreas. /// </summary> /// <param name="area1">First MapArea.</param> /// <param name="area2">Second MapArea.</param> /// <returns>A MapArea containing exactly those positions contained in both of the given MapAreas.</returns> public static MapArea GetIntersection(IReadOnlyMapArea area1, IReadOnlyMapArea area2) { var retVal = new MapArea(); if (!area1.Bounds.Intersects(area2.Bounds)) { return(retVal); } if (area1.Count > area2.Count) { Utility.Swap(ref area1, ref area2); } foreach (var pos in area1.Positions) { if (area2.Contains(pos)) { retVal.Add(pos); } } return(retVal); }