Commit 5b6667b8 authored by Anton Gladky's avatar Anton Gladky
Browse files

Resize interactionsOnBody, if it is necessary. (Closes: LP:1105177)

parent 83832e0b
......@@ -553,6 +553,7 @@ bool BodiesMenisciiList::prepare(Scene * scene)
bool BodiesMenisciiList::insert(const shared_ptr< Interaction >& interaction)
{
checkLengthBuffer(interaction);
interactionsOnBody[interaction->getId1()].push_back(interaction);
interactionsOnBody[interaction->getId2()].push_back(interaction);
return true;
......@@ -561,11 +562,19 @@ bool BodiesMenisciiList::insert(const shared_ptr< Interaction >& interaction)
bool BodiesMenisciiList::remove(const shared_ptr< Interaction >& interaction)
{
checkLengthBuffer(interaction);
interactionsOnBody[interaction->getId1()].remove(interaction);
interactionsOnBody[interaction->getId2()].remove(interaction);
return true;
}
void BodiesMenisciiList::checkLengthBuffer(const shared_ptr<Interaction>& interaction) {
Body::id_t maxBodyId = std::max(interaction->getId1(), interaction->getId2());
if (unsigned(maxBodyId) >= interactionsOnBody.size()) {
interactionsOnBody.resize(maxBodyId+1);
}
}
list< shared_ptr<Interaction> >& BodiesMenisciiList::operator[] (int index)
{
return interactionsOnBody[index];
......
......@@ -70,13 +70,14 @@ class BodiesMenisciiList
public:
BodiesMenisciiList();
BodiesMenisciiList(Scene* body);
bool prepare(Scene* scene);
bool insert(const shared_ptr<Interaction>& interaction);
bool remove(const shared_ptr<Interaction>& interaction);
list< shared_ptr<Interaction> >& operator[] (int index);
BodiesMenisciiList(Scene*);
bool prepare(Scene*);
bool insert(const shared_ptr<Interaction>&);
bool remove(const shared_ptr<Interaction>&);
list< shared_ptr<Interaction> >& operator[] (int);
int size();
void display();
void checkLengthBuffer(const shared_ptr<Interaction>&);
bool initialized;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment