]> rtime.felk.cvut.cz Git - hubacji1/rrts.git/blobdiff - src/rrtext4.cc
Change spacing
[hubacji1/rrts.git] / src / rrtext4.cc
index 7abfa34673891ef5bbc517c6c9c023f285a7ea53..1277a4b08eb5de7ce93ff00cd07e75dc480d238b 100644 (file)
@@ -2,19 +2,19 @@
 
 void RRTExt4::Cell::nn(RRTNode *t, RRTNode **nn, RRTS *p)
 {
-        double cost = p->cost_search(**nn, *t);
-        for (auto f: this->nodes()) {
-                if (p->cost_search(*f, *t) < cost) {
-                        *nn = f;
-                        cost = p->cost_search(*f, *t);
-                }
-        }
+       double cost = p->cost_search(**nn, *t);
+       for (auto f: this->nodes()) {
+               if (p->cost_search(*f, *t) < cost) {
+                       *nn = f;
+                       cost = p->cost_search(*f, *t);
+               }
+       }
 }
 
 void RRTExt4::Cell::store_node(RRTNode *n)
 {
-        this->nodes_.push_back(n);
-        this->changed_ = true;
+       this->nodes_.push_back(n);
+       this->changed_ = true;
 }
 
 RRTExt4::Cell::Cell()
@@ -23,90 +23,90 @@ RRTExt4::Cell::Cell()
 
 unsigned int RRTExt4::xi(RRTNode n)
 {
-        if (n.x() >= this->x_max_)
-                return 99;
-        if (n.x() <= this->x_min_)
-                return 0;
-        return (unsigned int) (floor(n.x() - this->x_min_) / ETA);
+       if (n.x() >= this->x_max_)
+               return GRID_MAX_XI - 1;
+       if (n.x() <= this->x_min_)
+               return 0;
+       return (unsigned int) (floor(n.x() - this->x_min_) / GRID);
 }
 
 unsigned int RRTExt4::yi(RRTNode n)
 {
-        if (n.y() > this->y_max_)
-                return 99;
-        if (n.y() <= this->y_min_)
-                return 0;
-        return (unsigned int) (floor(n.y() - this->y_min_) / ETA);
+       if (n.y() > this->y_max_)
+               return GRID_MAX_YI - 1;
+       if (n.y() <= this->y_min_)
+               return 0;
+       return (unsigned int) (floor(n.y() - this->y_min_) / GRID);
 }
 
 // API
 void RRTExt4::init()
 {
-        this->x_min_ = this->nodes().back().x() - 50 * ETA;
-        this->x_max_ = this->nodes().back().x() + 50 * ETA;
-        this->y_min_ = this->nodes().back().y() - 50 * ETA;
-        this->y_max_ = this->nodes().back().y() + 50 * ETA;
+       this->x_min_ = this->nodes().back().x() - GRID_WIDTH / 2;
+       this->x_max_ = this->nodes().back().x() + GRID_WIDTH / 2;
+       this->y_min_ = this->nodes().back().y() - GRID_HEIGHT / 2;
+       this->y_max_ = this->nodes().back().y() + GRID_HEIGHT / 2;
 }
 
 void RRTExt4::deinit()
 {
-        for (unsigned int i = 0; i < 100; i++)
-                for (unsigned int j = 0; j < 100; j++)
-                        this->grid_[i][j].nodes().clear();
+       for (unsigned int i = 0; i < GRID_MAX_XI; i++)
+               for (unsigned int j = 0; j < GRID_MAX_YI; j++)
+                       this->grid_[i][j].nodes().clear();
 }
 
 void RRTExt4::store_node(RRTNode n)
 {
-        RRTS::store_node(n);
-        RRTNode *sn = &this->nodes().back();
-        this->grid_[this->xi(n)][this->yi(n)].store_node(sn);
+       RRTS::store_node(n);
+       RRTNode *sn = &this->nodes().back();
+       this->grid_[this->xi(n)][this->yi(n)].store_node(sn);
 }
 
 RRTNode *RRTExt4::nn(RRTNode &t)
 {
-        RRTNode *nn = &this->nodes().front();
-        unsigned int txi = this->xi(t);
-        unsigned int tyi = this->yi(t);
-        unsigned int l = 0;
-        while (this->cost_search(*nn, t) > l * ETA) {
-                int xi_min = txi - l;
-                if (xi_min < 0)
-                        xi_min = 0;
-                int xi_max = txi + l;
-                if (xi_max > 99)
-                        xi_max = 99;
-                int yi_min = tyi - l;
-                if (yi_min < 0)
-                        yi_min = 0;
-                int yi_max = tyi + l;
-                if (yi_max > 99)
-                        yi_max = 99;
-                for (int xi = xi_min; xi <= xi_max; xi++) {
-                        this->grid_[xi][yi_max].nn(&t, &nn, this);
-                }
-                for (int xi = xi_min; xi <= xi_max; xi++) {
-                        this->grid_[xi][yi_min].nn(&t, &nn, this);
-                }
-                for (int yi = yi_min + 1; yi <= yi_max - 1; yi++) {
-                        this->grid_[xi_min][yi].nn(&t, &nn, this);
-                }
-                for (int yi = yi_min + 1; yi <= yi_max - 1; yi++) {
-                        this->grid_[xi_max][yi].nn(&t, &nn, this);
-                }
-                l++;
-        }
-        return nn;
+       RRTNode *nn = &this->nodes().front();
+       unsigned int txi = this->xi(t);
+       unsigned int tyi = this->yi(t);
+       unsigned int l = 0;
+       while (this->cost_search(*nn, t) > l * GRID) {
+               int xi_min = txi - l;
+               if (xi_min < 0)
+                       xi_min = 0;
+               int xi_max = txi + l;
+               if (xi_max > GRID_MAX_XI - 1)
+                       xi_max = GRID_MAX_XI - 1;
+               int yi_min = tyi - l;
+               if (yi_min < 0)
+                       yi_min = 0;
+               int yi_max = tyi + l;
+               if (yi_max > GRID_MAX_YI - 1)
+                       yi_max = GRID_MAX_YI - 1;
+               for (int xi = xi_min; xi <= xi_max; xi++) {
+                       this->grid_[xi][yi_max].nn(&t, &nn, this);
+               }
+               for (int xi = xi_min; xi <= xi_max; xi++) {
+                       this->grid_[xi][yi_min].nn(&t, &nn, this);
+               }
+               for (int yi = yi_min + 1; yi <= yi_max - 1; yi++) {
+                       this->grid_[xi_min][yi].nn(&t, &nn, this);
+               }
+               for (int yi = yi_min + 1; yi <= yi_max - 1; yi++) {
+                       this->grid_[xi_max][yi].nn(&t, &nn, this);
+               }
+               l++;
+       }
+       return nn;
 }
 
 std::vector<RRTNode *> RRTExt4::nv(RRTNode &t)
 {
-        std::vector<RRTNode *> nv;
-        unsigned int txi = this->xi(t);
-        unsigned int tyi = this->yi(t);
-        unsigned int l = 0;
-        double cost = std::min(GAMMA(this->nodes().size()), ETA);
-        for (auto f: this->grid_[txi][tyi].nodes())
-                if (this->cost_search(*f, t) < cost)
-                        nv.push_back(f);
-        return nv;
+       std::vector<RRTNode *> nv;
+       unsigned int txi = this->xi(t);
+       unsigned int tyi = this->yi(t);
+       unsigned int l = 0;
+       double cost = std::min(GAMMA(this->nodes().size()), ETA);
+       for (auto f: this->grid_[txi][tyi].nodes())
+               if (this->cost_search(*f, t) < cost)
+                       nv.push_back(f);
+       return nv;
 }