コード例 #1
0
        static void Main(string[] args)
        {
            MarsTime         deimosRise = new MarsTime(12, 32);
            MarsTime         deimosSet  = new MarsTime(17, 06);
            MarsTime         phobosRise = new MarsTime(17, 06);
            MarsTime         phobosSet  = new MarsTime(19, 78);
            MarsTimeInterval deimos     = new MarsTimeInterval(deimosRise, deimosSet);
            MarsTimeInterval phobos     = new MarsTimeInterval(phobosRise, phobosSet);
            int overlapMinutes          = MoonVisibilityCalculator.GetOverlapMinutes(deimos, phobos);

            Console.WriteLine("Deimos and Phobos are both visible for " + overlapMinutes + " minutes.");
        }
コード例 #2
0
        // TBD: How to handle double Twilight rule?
        // D[ [ 4:00 ], [ 20:00] ];   P[ [ 20:00 ], [ 4:00] ]
        // also: D[ [ 3:00 ], [ 20:00] ];  P[ [ 20:00 ], [ 4:00] ]
        public static int GetOverlapMinutes(MarsTimeInterval intervalOne, MarsTimeInterval intervalTwo)
        {
            int intervalOneStart = intervalOne.getRelativeStartMinutes();
            int intervalOneEnd   = intervalOne.getRelativeEndMinutes();
            int intervalTwoStart = intervalTwo.getRelativeStartMinutes();
            int intervalTwoEnd   = intervalTwo.getRelativeEndMinutes();

            int overlap = 0;

            //bool twilightRule = false;

            if (DoIntervalsOverlap(intervalOneStart, intervalOneEnd, intervalTwoStart, intervalTwoEnd))
            {
                overlap += CalcOverlap(intervalOneStart, intervalOneEnd, intervalTwoStart, intervalTwoEnd);
            }
            else if (DoesTwilightRuleApply(intervalOneStart, intervalOneEnd, intervalTwoStart, intervalTwoEnd))
            {
                overlap += 1;
            }

            // if both intervals are on the same day return overlap
            if (intervalOne.DaysDiffer == intervalTwo.DaysDiffer)
            {
                return(overlap);
                //twilightRule = true;
            }

            // if intevals are on different days check for overlap on previous day:
            if (!(intervalOne.DaysDiffer))
            {
                intervalOneStart = intervalOne.getRelativeStartMinutesPreviousDay();
                intervalOneEnd   = intervalOne.getRelativeEndMinutesPreviousDay();
            }
            if (!(intervalTwo.DaysDiffer))
            {
                intervalTwoStart = intervalTwo.getRelativeStartMinutesPreviousDay();
                intervalTwoEnd   = intervalTwo.getRelativeEndMinutesPreviousDay();
            }


            if (DoIntervalsOverlap(intervalOneStart, intervalOneEnd, intervalTwoStart, intervalTwoEnd))
            {
                overlap += CalcOverlap(intervalOneStart, intervalOneEnd, intervalTwoStart, intervalTwoEnd);
            }
            else if (DoesTwilightRuleApply(intervalOneStart, intervalOneEnd, intervalTwoStart, intervalTwoEnd))
            {
                // TBD: Handle if twilight rule can be applied twice (&& (twilightRule == false))
                // TBD: Handle if twilight rule should be applied at: D[ [ 3:00 ], [ 20:00] ];  P[ [ 20:00 ], [ 4:00] ]  (&& overlap == 0)
                overlap += 1;
            }

            return(overlap);
        }