Skip to content
Snippets Groups Projects
Commit 068e8e8b authored by Studer Gabriel's avatar Studer Gabriel
Browse files

simplify

parent d276f08c
No related branches found
No related tags found
No related merge requests found
...@@ -139,6 +139,7 @@ private: ...@@ -139,6 +139,7 @@ private:
typedef std::map<Index,SpatialOrganizerCell<ITEM>*> ItemMap; typedef std::map<Index,SpatialOrganizerCell<ITEM>*> ItemMap;
public: public:
DynamicSpatialOrganizer(Real delta, DynamicSpatialOrganizer(Real delta,
...@@ -161,15 +162,12 @@ public: ...@@ -161,15 +162,12 @@ public:
} }
void Add(ITEM* item, const geom::Vec3& pos) { void Add(ITEM* item, const geom::Vec3& pos) {
Index indx=gen_index(pos); Index indx=gen_index(pos);
typename ItemMap::iterator it = map_.find(indx); typename ItemMap::iterator it = map_.find(indx);
if(it == map_.end()) { if(it == map_.end()) {
map_[indx] = new SpatialOrganizerCell<ITEM>; map_[indx] = new SpatialOrganizerCell<ITEM>;
it = map_.find(indx); it = map_.find(indx);
} }
it->second->AddItem(item,pos[0],pos[1],pos[2]); it->second->AddItem(item,pos[0],pos[1],pos[2]);
} }
...@@ -187,28 +185,20 @@ public: ...@@ -187,28 +185,20 @@ public:
void Reset(ITEM* item, const geom::Vec3& actual_pos, const geom::Vec3& new_pos) { void Reset(ITEM* item, const geom::Vec3& actual_pos, const geom::Vec3& new_pos) {
Index actual_indx=gen_index(actual_pos); Index actual_indx=gen_index(actual_pos);
Index new_indx=gen_index(new_pos); Index new_indx=gen_index(new_pos);
if(actual_indx != new_indx) { typename ItemMap::iterator i = map_.find(actual_indx);
typename ItemMap::iterator i = map_.find(actual_indx); if(i == map_.end()) {
if(i != map_.end()) { throw promod3::Error("Could not find specified item in dynamic spatial organizer!");
typename ItemMap::iterator j = map_.find(new_indx);
if(j == map_.end()) {
map_[new_indx] = new SpatialOrganizerCell<ITEM>;
j = map_.find(new_indx);
}
i->second->RemoveItem(item);
j->second->AddItem(item,new_pos[0],new_pos[1],new_pos[2]);
return;
}
throw promod3::Error("Could not find specified item in dynamic spatial organizer!");
} }
else{ if(actual_indx == new_indx) {
typename ItemMap::iterator i = map_.find(actual_indx); i->second->ResetPos(item,new_pos[0],new_pos[1],new_pos[2]);
if(i != map_.end()) { } else {
i->second->ResetPos(item,new_pos[0],new_pos[1],new_pos[2]); typename ItemMap::iterator j = map_.find(new_indx);
} if(j == map_.end()) {
else{ map_[new_indx] = new SpatialOrganizerCell<ITEM>;
throw promod3::Error("Could not find specified item in dynamic spatial organizer!"); j = map_.find(new_indx);
} }
i->second->RemoveItem(item);
j->second->AddItem(item,new_pos[0],new_pos[1],new_pos[2]);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment