From 068e8e8ba77d3c3b70d251d194a3189cdbde3353 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Fri, 26 Oct 2018 15:46:57 +0200
Subject: [PATCH] simplify
---
core/src/dynamic_spatial_organizer.hh | 36 ++++++++++-----------------
1 file changed, 13 insertions(+), 23 deletions(-)
diff --git a/core/src/dynamic_spatial_organizer.hh b/core/src/dynamic_spatial_organizer.hh
index dada464d..ca2b710d 100644
--- a/core/src/dynamic_spatial_organizer.hh
+++ b/core/src/dynamic_spatial_organizer.hh
@@ -139,6 +139,7 @@ private:
typedef std::map<Index,SpatialOrganizerCell<ITEM>*> ItemMap;
+
public:
DynamicSpatialOrganizer(Real delta,
@@ -161,15 +162,12 @@ public:
}
void Add(ITEM* item, const geom::Vec3& pos) {
-
Index indx=gen_index(pos);
typename ItemMap::iterator it = map_.find(indx);
-
if(it == map_.end()) {
map_[indx] = new SpatialOrganizerCell<ITEM>;
it = map_.find(indx);
}
-
it->second->AddItem(item,pos[0],pos[1],pos[2]);
}
@@ -187,28 +185,20 @@ public:
void Reset(ITEM* item, const geom::Vec3& actual_pos, const geom::Vec3& new_pos) {
Index actual_indx=gen_index(actual_pos);
Index new_indx=gen_index(new_pos);
- if(actual_indx != new_indx) {
- typename ItemMap::iterator i = map_.find(actual_indx);
- if(i != map_.end()) {
- 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!");
+ typename ItemMap::iterator i = map_.find(actual_indx);
+ if(i == map_.end()) {
+ throw promod3::Error("Could not find specified item in dynamic spatial organizer!");
}
- else{
- typename ItemMap::iterator i = map_.find(actual_indx);
- if(i != map_.end()) {
- i->second->ResetPos(item,new_pos[0],new_pos[1],new_pos[2]);
- }
- else{
- throw promod3::Error("Could not find specified item in dynamic spatial organizer!");
+ if(actual_indx == new_indx) {
+ i->second->ResetPos(item,new_pos[0],new_pos[1],new_pos[2]);
+ } else {
+ 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]);
}
}
--
GitLab