Example #1
0
        /// <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="Area.GetIntersection(IReadOnlyArea, IReadOnlyArea)"/>, 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(IReadOnlyArea area)
        {
            if (!area.Bounds.Intersects(Bounds))
            {
                return(false);
            }

            if (Count <= area.Count)
            {
                foreach (Point pos in Positions)
                {
                    if (area.Contains(pos))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            foreach (Point pos in area.Positions)
            {
                if (Contains(pos))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Gets an area containing all positions in <paramref name="area1"/>, minus those that are in
        /// <paramref name="area2"/>.
        /// </summary>
        /// <param name="area1"/>
        /// <param name="area2"/>
        /// <returns>A area with exactly those positions in <paramref name="area1"/> that are NOT in
        /// <paramref name="area2"/>.</returns>
        public static Area GetDifference(IReadOnlyArea area1, IReadOnlyArea area2)
        {
            Area retVal = new Area();

            foreach (Point pos in area1.Positions)
            {
                if (area2.Contains(pos))
                {
                    continue;
                }

                retVal.Add(pos);
            }

            return(retVal);
        }
Example #3
0
        /// <summary>
        /// Gets an area containing exactly those positions contained in both of the given areas.
        /// </summary>
        /// <param name="area1"/>
        /// <param name="area2"/>
        /// <returns>An area containing exactly those positions contained in both of the given areas.</returns>
        public static Area GetIntersection(IReadOnlyArea area1, IReadOnlyArea area2)
        {
            Area retVal = new Area();

            if (!area1.Bounds.Intersects(area2.Bounds))
            {
                return(retVal);
            }

            if (area1.Count > area2.Count)
            {
                Swap(ref area1, ref area2);
            }

            foreach (Point pos in area1.Positions)
            {
                if (area2.Contains(pos))
                {
                    retVal.Add(pos);
                }
            }

            return(retVal);
        }