public bool MoveNext() { if (_copy.IsEmpty()) { return(false); } Current = _copy.DelMin(); return(Current != null); }
/// <summary> /// Simulates the system of particles for the specified amount of time. /// </summary> /// <param name="limit">the amount of time</param> public IEnumerator Simulate(double limit, double hz) { Start(limit); while (!_pq.IsEmpty()) { // get impending event, discard if invalidated Event e = _pq.DelMin(); if (!e.IsValid()) { continue; } Particle a = e.A; Particle b = e.B; // physical collision, so update positions, and then simulation clock for (int i = 0; i < _particles.Length; i++) { _particles[i].Move(e.Time - _t); } _t = e.Time; // process event if (a != null && b != null) { a.BounceOff(b); // particle-particle collision } else if (a != null && b == null) { a.BounceOffVerticalWall(); // particle-wall collision } else if (a == null && b != null) { b.BounceOffHorizontalWall(); // particle-wall collision } else if (a == null && b == null) { yield return(sWaitForSeconds); Redraw(limit, hz); // redraw event } // update the priority queue with new collisions involving a or b Predict(a, limit); Predict(b, limit); } }