private void Cleanup() { _traversalStack.Clear(); _visitedNodes.Clear(); #if DEBUG // Reset reentrancy test flag. Interlocked.Exchange(ref _reentranceFlag, 0); #endif }
/// <summary> /// Resolves conflicts either by bending bonds or stretching bonds in the /// shortest path between an overlapping pair. Bending and stretch are tried /// for each pair and the best resolution is used. /// </summary> /// <param name="pairs">pairs</param> private void BendOrStretch(IEnumerable <AtomPair> pairs) { // without checking which bonds have been bent/stretch already we // could end up repeating a lot of repeated work to no avail var bendVisit = new Dictionary <IBond, AtomPair>(); var stretchVisit = new Dictionary <IBond, AtomPair>(); var bendStack = new IntStack(atoms.Length); var stretchStack = new IntStack(atoms.Length); foreach (var pair in pairs) { double score = congestion.Score(); // each attempt will be more aggressive/distorting for (pair.attempt = 1; pair.attempt <= 3; pair.attempt++) { bendStack.Clear(); stretchStack.Clear(); // attempt both bending and stretching storing the // best result in the provided buffer var bendScore = Bend(pair, bendStack, buffer1, bendVisit); var stretchScore = Stretch(pair, stretchStack, buffer2, stretchVisit); // bending is better than stretching if (bendScore < stretchScore && bendScore < score) { RestoreCoords(bendStack, buffer1); congestion.Update(bendStack.xs, bendStack.len); break; } // stretching is better than bending else if (bendScore > stretchScore && stretchScore < score) { RestoreCoords(stretchStack, buffer2); congestion.Update(stretchStack.xs, stretchStack.len); break; } } } }