]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blobdiff - incl/bcar.hh
Add car frame point and side getters
[hubacji1/bcar.git] / incl / bcar.hh
index 1ab5b58965e7d29cce30f956cbccf3a136243565..ad33a7ddaf4410546fc288390f49b852e04def13 100644 (file)
@@ -11,6 +11,8 @@ template <typename T> int sgn(T val) {
        return (T(0) < val) - (val < T(0));
 }
 
+class Line;
+
 class Point {
 private:
        double x_ = 0.0;
@@ -46,6 +48,27 @@ public:
         * \param poly Polygon to consider.
         */
        bool inside_of(std::vector<Point> const& poly) const;
+
+       /*! \brief Return `true` if on the right side of the plane.
+        *
+        * The plane is given by the line `li`, where `li->fp()` is the base
+        * point and the direction is given by `li->lp() - li->fp()`.
+        *
+        * \param li The plane to consider is given by `li`.
+        */
+       bool on_right_side_of(Line const& li) const;
+
+       /*! \brief Rotate self around the point.
+
+       \param c Rotation center `Point`.
+       \param angl Angle of rotation.
+       */
+       void rotate(Point const& c, double const angl);
+
+       /*! Return Euclidean distance to `p`. */
+       double edist(Point const& p) const;
+
+       friend std::ostream& operator<<(std::ostream& out, Point const& p);
 };
 
 class Line {
@@ -92,34 +115,18 @@ public:
         */
        bool intersects_with(Point const& c, double const r);
 
-       /*! \brief Return if point `p` is on the right side of the plane.
-        *
-        * The plane is given by the line `this`, where `this->fp()` is the base
-        * point and the direction is given by `this->lp() - this->fp()`.
-        *
-        * \param p The point to consider.
-        */
-       bool is_on_right_side(Point const& p) const;
+       double len() const;
+
+       friend std::ostream& operator<<(std::ostream& out, Line const& li);
 };
 
 /*! Store coordinates `x`, `y`, and heading `h`. */
-class Pose {
+class Pose : public virtual Point {
 private:
-       double x_ = 0.0;
-       double y_ = 0.0;
        double h_ = 0.0;
 public:
-       /*! Get horizontal coordinate. */
-       double x() const;
-
-       /*! Set horizontal coordinate. */
-       void x(double x);
-
-       /*! Get vertical coordinate. */
-       double y() const;
-
-       /*! Set vertical coordinate. */
-       void y(double y);
+       Pose(double x, double y, double h);
+       Pose();
 
        /*! Get heading in the interval [-pi, +pi] radians. */
        double h() const;
@@ -127,17 +134,15 @@ public:
        /*! Set heading in radians. It's recomputed to [-pi, +pi]. */
        void h(double h);
 
-       /*! \brief Rotate self around the point.
+       /*! Set pose (`x`, `y`, and `h`.) */
+       void set_pose(Pose const& p);
 
-       \param c Rotation center `Point`.
-       \param angl Angle of rotation.
-       */
        void rotate(Point const& c, double const angl);
 
        friend std::ostream& operator<<(std::ostream& out, Pose const& p);
 };
 
-class PoseRange : public Pose {
+class PoseRange : public virtual Pose {
 private:
        double e_ = 0.0;
        using Pose::h;
@@ -216,6 +221,39 @@ public:
         * radius.
         */
        double mtr() const;
+
+       /*! \brief Return inner radius.
+        *
+        * The inner radius is the distance from minimum turning radius circle
+        * center to the nearest point on the car. In this case, the nearest
+        * points on the car are rear axle endpoints.
+        */
+       double iradi() const;
+
+       /*! \brief Return outer front radius.
+        *
+        * The outer front radius is the distance from minimum turning radius
+        * circle center to the farthest point on the front (from the rear axle
+        * view) part of the car.
+        */
+       double ofradi() const;
+
+       /*! \brief Return outer rear radius.
+        *
+        * The outer rear radius is the distance from minimum turning radius
+        * circle center to the farthest point on the rear (from the rear axle
+        * view) part of the car.
+        */
+       double orradi() const;
+
+       /*! \brief Return length of perfect parking slot.
+        *
+        * The width of the slot is the same as the width of the car.
+        *
+        * \see Simon R. Blackburn *The Geometry of Perfect Parking*
+        * \see https://www.ma.rhul.ac.uk/SRBparking
+        */
+       double perfect_parking_slot_len() const;
 };
 
 /*! Store car motion. */
@@ -241,7 +279,8 @@ public:
  *
  * - `x()` and `y()` methods returns coordinates of rear axle center.
  */
-class BicycleCar : public Pose, public CarSize, public CarMove {
+class BicycleCar : public virtual Pose, public virtual CarSize,
+               public virtual CarMove {
 private:
 public:
        /*! \brief Return `false` if `bc` is not achievable.
@@ -249,46 +288,11 @@ public:
         * When `false` is returned the `bc` may still be drivable, but not
         * trivially, i.e. by "line segment - circle arc - line segment".
         *
-        * \param bc The bicycle car to achieve.
-        * \param b The beginning of the heading range.
-        * \param e The end of the heading range.
+        * \param p `PoseRange` (resp. `Pose`) to achieve.
         */
-       bool drivable(Pose const& p, double b, double e) const;
+       bool drivable(PoseRange const& p) const;
        bool drivable(Pose const& p) const;
 
-       /*! \brief Return inner radius.
-        *
-        * The inner radius is the distance from minimum turning radius circle
-        * center to the nearest point on the car. In this case, the nearest
-        * points on the car are rear axle endpoints.
-        */
-       double iradi() const;
-
-       /*! \brief Return outer front radius.
-        *
-        * The outer front radius is the distance from minimum turning radius
-        * circle center to the farthest point on the front (from the rear axle
-        * view) part of the car.
-        */
-       double ofradi() const;
-
-       /*! \brief Return outer rear radius.
-        *
-        * The outer rear radius is the distance from minimum turning radius
-        * circle center to the farthest point on the rear (from the rear axle
-        * view) part of the car.
-        */
-       double orradi() const;
-
-       /*! \brief Return length of perfect parking slot.
-        *
-        * The width of the slot is the same as the width of the car.
-        *
-        * \see Simon R. Blackburn *The Geometry of Perfect Parking*
-        * \see https://www.ma.rhul.ac.uk/SRBparking
-        */
-       double perfect_parking_slot_len() const;
-
        /*! Set maximum steering angle. */
        void set_max_steer();
 
@@ -316,6 +320,30 @@ public:
        /*! Get frame's right front y coordinate. */
        double rfy() const;
 
+       /*! Get frame's left front point. */
+       Point lf() const;
+
+       /*! Get frame's left rear point. */
+       Point lr() const;
+
+       /*! Get frame's right rear point. */
+       Point rr() const;
+
+       /*! Get frame's right front point. */
+       Point rf() const;
+
+       /*! Get frame's left side. */
+       Line left() const;
+
+       /*! Get frame's rear side. */
+       Line rear() const;
+
+       /*! Get frame's right side. */
+       Line right() const;
+
+       /*! Get frame's front side. */
+       Line front() const;
+
        /*! Get rear axle's left x coordinate. */
        double ralx() const;