Ejemplo n.º 1
0
        /// <summary>
        /// Find the time at which the next discontinuity occurs between two binary
        /// discontinuous bubbles.
        /// </summary>
        /// <returns>The pair next discontinuity after.</returns>
        /// <param name="solver">Solver.</param>
        /// <param name="after">After.</param>
        /// <param name="a">The alpha component.</param>
        /// <param name="b">The blue component.</param>
        public static float BinaryPairNextDiscontinuityAfter(
            BubbleInteractionSolver <Position> solver, float after,
            BinaryBubble <Position> a, BinaryBubble <Position> b)
        {
            var aNextDiscontinuity = a.NextDiscontinuity();
            var bNextDiscontinuity = b.NextDiscontinuity();

            var pairs = new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >[]
            {
                new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >(a.Left, b.Left),
                new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >(a.Left, b.Right),
                new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >(a.Right, b.Left),
                new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >(a.Right, b.Right)
            };

            float nextDiscontinuity = aNextDiscontinuity < bNextDiscontinuity
                                ? aNextDiscontinuity : bNextDiscontinuity;

            foreach (var pair in pairs)
            {
                var pairDiscontinuity = solver.NextDiscontinuityAfter(
                    after, pair.First, pair.Second);
                if (pairDiscontinuity < nextDiscontinuity)
                {
                    nextDiscontinuity = pairDiscontinuity;
                }
            }

            return(nextDiscontinuity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Find the time of the next discontinuity between a binary bubble and
        /// some other discontinuous bubble.
        /// </summary>
        /// <returns>The next discontinuity after.</returns>
        /// <param name="solver">Solver.</param>
        /// <param name="after">After.</param>
        /// <param name="binaryBubble">Binary bubble.</param>
        /// <param name="other">Other.</param>
        public static float PairNextDiscontinuityAfter(BubbleInteractionSolver <Position> solver,
                                                       float after, BinaryBubble <Position> binaryBubble, DiscontinuousBubble <Position> other)
        {
            var leftNextDiscontinuity = solver.NextDiscontinuityAfter(
                after, binaryBubble.Left, other);
            var rightNextDiscontinuity = solver.NextDiscontinuityAfter(
                after, binaryBubble.Right, other);

            // TODO: cache the result somehow
            return(leftNextDiscontinuity < rightNextDiscontinuity
                                ? leftNextDiscontinuity
                                : rightNextDiscontinuity);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Resolve the next discontinuity between two binary discontinuous bubbles.
        /// This may involve swapping individual bubbles between the binary bubbles.
        /// </summary>
        /// <param name="solver">Solver.</param>
        /// <param name="after">After.</param>
        /// <param name="a">The alpha component.</param>
        /// <param name="b">The blue component.</param>
        public static void BinaryPairResolveDiscontinuityAfter(
            BubbleInteractionSolver <Position> solver, float after,
            BinaryBubble <Position> a, BinaryBubble <Position> b)
        {
            // TODO: find a way of caching this result from the prior check
            //       (might need to be a change implemented in the solver)
            var aNextDiscontinuity = a.NextDiscontinuity();
            var bNextDiscontinuity = b.NextDiscontinuity();

            var pairs = new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >[]
            {
                new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >(a.Left, b.Left),
                new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >(a.Left, b.Right),
                new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >(a.Right, b.Left),
                new Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> >(a.Right, b.Right)
            };

            float nextDiscontinuity = aNextDiscontinuity < bNextDiscontinuity
                                ? aNextDiscontinuity : bNextDiscontinuity;
            Pair <DiscontinuousBubble <Position>, DiscontinuousBubble <Position> > nextPair = null;

            foreach (var pair in pairs)
            {
                var pairDiscontinuity = solver.NextDiscontinuityAfter(
                    after, pair.First, pair.Second);
                if (pairDiscontinuity < nextDiscontinuity)
                {
                    nextDiscontinuity = pairDiscontinuity;
                    nextPair          = pair;
                }
            }

            if (nextPair == null)
            {
                if (aNextDiscontinuity < bNextDiscontinuity)
                {
                    a.ResolveNextDiscontinuity();
                }
                else
                {
                    b.ResolveNextDiscontinuity();
                }
            }
            else
            {
                solver.ResolveNextDiscontinuityAfter(after, nextPair.First, nextPair.Second);
                a.RecalculateProperties();
                b.RecalculateProperties();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Resolve the next discontinuity between a binary bubble and some other
        /// discontinuous bubble.
        /// </summary>
        /// <param name="solver">Solver.</param>
        /// <param name="after">After.</param>
        /// <param name="binaryBubble">Binary bubble.</param>
        /// <param name="other">Other.</param>
        public static void PairResolveDiscontinuityAfter(BubbleInteractionSolver <Position> solver,
                                                         float after, BinaryBubble <Position> binaryBubble, DiscontinuousBubble <Position> other)
        {
            // TODO: cache this part from the previous function
            var leftNextDiscontinuity = solver.NextDiscontinuityAfter(
                after, binaryBubble.Left, other);
            var rightNextDiscontinuity = solver.NextDiscontinuityAfter(
                after, binaryBubble.Right, other);

            if (leftNextDiscontinuity < rightNextDiscontinuity)
            {
                solver.ResolveNextDiscontinuityAfter(after, binaryBubble.Left, other);
            }
            else
            {
                solver.ResolveNextDiscontinuityAfter(after, binaryBubble.Right, other);
            }
        }