]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/commitdiff
Set is cusp and cusp count when setting parent
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 16 Mar 2023 16:41:57 +0000 (17:41 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 16 Mar 2023 16:41:57 +0000 (17:41 +0100)
rrts/incl/rrts.hh
rrts/src/rrts.cc

index 8503e0c79ea0e61ee2e1e6bd5538f5990d602352..a6c00f0f78745ad9c620a9e49ce2d0cad8ee9384 100644 (file)
@@ -84,6 +84,9 @@ public:
        /*! Set if the parent node is cusp (direction changed from parent). */
        void p_is_cusp(bool isit);
 
+       /*! Return true if p would be cusp if set as parent of this. */
+       bool would_be_cusp_if_parent(RRTNode const& p) const;
+
        bool operator==(RRTNode const& n);
 };
 
index 3d84e6225c0d10ed6ccf99da5ef512be8f122a3b..da4ae36f6fcbb6a78164113a2f0f82f0ac27a7c8 100644 (file)
@@ -60,6 +60,8 @@ RRTNode::p(RRTNode& p)
        if (this != &p) {
                this->_p = &p;
        }
+       this->p_is_cusp(this->would_be_cusp_if_parent(p));
+       this->cusp_cnt(p);
 }
 
 unsigned int
@@ -101,6 +103,31 @@ RRTNode::p_is_cusp(bool isit)
        this->_p_is_cusp = isit;
 }
 
+bool
+RRTNode::would_be_cusp_if_parent(RRTNode const& p) const
+{
+       if (p.sp() == 0) {
+               assert(this->sp() != 0);
+               if (p.p()) {
+                       if (sgn(p.p()->sp()) != sgn(this->sp())) {
+                               return true;
+                       } else {
+                               return false;
+                       }
+               } else {
+                       return true; // only root has no parent and it is cusp
+               }
+       } else {
+               if (this->sp() == 0) {
+                       return false; // this is cusp, not the parent
+               } else if (sgn(p.sp()) != sgn(this->sp())) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+}
+
 bool
 RRTNode::operator==(RRTNode const& n)
 {
@@ -152,7 +179,6 @@ RRTS::join_steered(RRTNode* f)
                RRTNode* t = &this->_nodes.back();
                t->p(*f);
                t->c(this->cost_build(*f, *t));
-               t->cusp_cnt(*f);
                this->_steered.erase(this->_steered.begin());
                f = t;
        }
@@ -167,8 +193,6 @@ RRTS::connect()
        assert(std::abs(t->x() - f->x()) < 1e-3);
        assert(std::abs(t->y() - f->x()) < 1e-3);
        assert(std::abs(t->h() - f->x()) < 1e-3);
-       // When f and t has different directions, the node (f == t) is cusp:
-       // TODO
        this->_steered.erase(this->_steered.begin());
        t = &this->_steered.front();
 #if USE_RRTS
@@ -192,7 +216,6 @@ RRTS::connect()
        t = &this->_nodes.back();
        t->p(*f);
        t->c(this->cost_build(*f, *t));
-       t->cusp_cnt(*f);
        this->_steered.erase(this->_steered.begin());
        return true;
 }