Skip to content

Commit

Permalink
Fix #650 part 2
Browse files Browse the repository at this point in the history
Bug raised by @mquevill - delete a non-selected atom

Since deleting atoms renumbers, make sure selected atoms stays
with "swap and pop" form from atom index, etc.

Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
  • Loading branch information
ghutchis committed Jul 16, 2021
1 parent 390c8c0 commit e3e7bf0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions avogadro/core/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,13 @@ bool Molecule::removeAtom(Index index)
if (m_colors.size() == atomCount())
m_colors.swapAndPop(index);

if (m_selectedAtoms.size() == atomCount())
m_selectedAtoms.erase(m_selectedAtoms.begin() + index);
if (m_selectedAtoms.size() == atomCount()) {
// swap and pop on std::vector<bool>
if (index != m_selectedAtoms.size() - 1) {
m_selectedAtoms[index] = m_selectedAtoms.back();
}
m_selectedAtoms.pop_back();
}

Index affectedIndex = static_cast<Index>(m_atomicNumbers.size() - 1);
m_atomicNumbers.swapAndPop(index);
Expand Down

0 comments on commit e3e7bf0

Please sign in to comment.