Пример #1
0
        /// <summary>
        /// Находит остатки от пересечения текущего куба с посторонним кубом
        /// </summary>
        public static List <SpatialBox <TContext> > Difference <TContext>(this SpatialBox <TContext> instance, SpatialBox <TContext> other)
            where TContext : class
        {
            var intersection = instance.Intersect(other, (x, y) => null); // we do not need context of intersection

            if (intersection == null)
            {
                return new List <SpatialBox <TContext> > {
                           instance
                }
            }
            ;

            var result = new List <SpatialBox <TContext> >();

            result.AddRange(
                instance.OfferInterval.Difference(intersection.OfferInterval, (x, i) => x.AddDays(i))
                .Select(x => instance.Copy(offerInterval: x)).ToList());
            result.AddRange(
                instance.NightInterval.Difference(intersection.NightInterval, (x, i) => (short)(x + i))
                .Select(x => instance.Copy(offerInterval: intersection.OfferInterval, nightInterval: x)).ToList());
            result.AddRange(
                instance.SeasonInterval.Difference(intersection.SeasonInterval, (x, i) => x.AddDays(i))
                .Select(x => instance.Copy(offerInterval: intersection.OfferInterval, nightInterval: intersection.NightInterval, seasonInterval: x)).ToList());

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Объединяет параллелепипеды, если возможно
        /// </summary>
        public static SpatialBox <TContext> Merge <TContext>(this SpatialBox <TContext> instance, SpatialBox <TContext> other)
            where TContext : class
        {
            var areOffersEqual  = instance.OfferInterval.EqualsTo(other.OfferInterval);
            var areNightsEqual  = instance.NightInterval.EqualsTo(other.NightInterval);
            var areSeasonsEqual = instance.SeasonInterval.EqualsTo(other.SeasonInterval);

            var offerMerged  = instance.OfferInterval.Merge(other.OfferInterval, (x, i) => x.AddDays(i));
            var nightMerged  = instance.NightInterval.Merge(other.NightInterval, (x, i) => (short)(x + i));
            var seasonMerged = instance.SeasonInterval.Merge(other.SeasonInterval, (x, i) => x.AddDays(i));

            if (offerMerged != null && areNightsEqual && areSeasonsEqual)
            {
                return(instance.Copy(offerInterval: offerMerged));
            }
            if (areOffersEqual && nightMerged != null && areSeasonsEqual)
            {
                return(instance.Copy(nightInterval: nightMerged));
            }
            if (areOffersEqual && areNightsEqual && seasonMerged != null)
            {
                return(instance.Copy(seasonInterval: seasonMerged));
            }

            return(null);
        }