Ejemplo n.º 1
0
        /// <summary>
        /// Tries to translate <paramref name="region"/> by the specified <paramref name="offset"/>, and returns a
        /// value indicating whether the translation was successful. If the translation was successful,
        /// <see langword="true"/> will be returned, and <paramref name="beforeChange"/> will be set to a region
        /// equivalent to <paramref name="region"/> before the translation was applied.
        /// </summary>
        /// <param name="region">
        /// The region to try to translate.
        /// </param>
        /// <param name="offset">
        /// The offset by which to translate this region.
        /// </param>
        /// <param name="beforeChange">
        /// If the translation succeeds, a region equivalent to this region before the translation was applied.
        /// </param>
        /// <returns>
        /// <see langword="true"/> if the translation succeeded; otherwise, <see langword="false"/>.
        /// </returns>
        public static bool TryTranslateBy(this IMoveOnlyRegion region, Coord offset, out IReadOnlyRegion beforeChange)
        {
            if (region is null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            return(region.TryMoveTo(region.TopLeft + offset, out beforeChange));
        }