]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/commitdiff
Add set to start method for parkig slot
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Wed, 19 Jan 2022 22:30:22 +0000 (23:30 +0100)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Wed, 19 Jan 2022 22:30:40 +0000 (23:30 +0100)
incl/pslot.hh
src/pslot.cc

index fbadd41495cffa3d8ae023c799817a915a1168f3..7cf2b42822a2863da88248fc339a25e819089489 100644 (file)
@@ -126,6 +126,12 @@ public:
        /*! Return `true` if `c`'s car frame collide with `this` border. */
        bool collide(BicycleCar const& c) const;
 
+       /*! \brief Set car `c` to the start position.
+        *
+        * \param c Bicycle car.
+        */
+       void set_to_start(BicycleCar& c);
+
        /*! \brief Drive car `c` into the parking slot `this`.
         *
         * \param c Starting bicycle car.
index 6a9a9bb25c573e5881d09c3b3986ac4a8f5728b5..b1a17dad1d2b8b8b81bc555fd2e9217faeaf8577 100644 (file)
@@ -222,6 +222,19 @@ ParkingSlot::collide(BicycleCar const& c) const
                || c.front().intersects_with(this->_front);
 }
 
+void
+ParkingSlot::set_to_start(BicycleCar& c)
+{
+       c.h(this->h());
+       double clen = -this->_offset + this->len() - c.df();
+       double cw = c.w() / 2.0;
+       c.x(this->lrx() + clen * cos(c.h()) + cw * cos(c.h() + M_PI / 2.0));
+       c.y(this->lry() + clen * sin(c.h()) + cw * sin(c.h() + M_PI / 2.0));
+       c.set_max_steer();
+       assert(this->_parking_speed < 0.0);
+       c.sp(this->_parking_speed);
+}
+
 std::vector<BicycleCar>
 ParkingSlot::drive_in_slot(BicycleCar c)
 {
@@ -351,14 +364,7 @@ ParkingSlot::fe(BicycleCar c)
                this->swap_side();
                swapped = true;
        }
-       c.h(this->h());
-       double clen = -this->_offset + this->len() - c.df();
-       double cw = c.w() / 2.0;
-       c.x(this->lrx() + clen * cos(c.h()) + cw * cos(c.h() + M_PI / 2.0));
-       c.y(this->lry() + clen * sin(c.h()) + cw * sin(c.h() + M_PI / 2.0));
-       c.set_max_steer();
-       assert(this->_parking_speed < 0.0);
-       c.sp(this->_parking_speed);
+       this->set_to_start(c);
        auto const rc = c.rf();
        this->_curb.intersects_with(rc, c.len());
        double max_to_slot;