]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/commitdiff
Move rotate method to point
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Wed, 14 Jul 2021 23:12:47 +0000 (01:12 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Wed, 14 Jul 2021 23:12:47 +0000 (01:12 +0200)
incl/bcar.hh
src/bcar.cc

index 5a4e46608cc077a766441660a0ca0b957882f8b5..ee9c3036eaca795c99edbe752ee79afcd782becc 100644 (file)
@@ -58,6 +58,13 @@ public:
         */
        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);
+
        friend std::ostream& operator<<(std::ostream& out, Point const& p);
 };
 
@@ -125,11 +132,6 @@ public:
        /*! Set pose (`x`, `y`, and `h`.) */
        void set_pose(Pose const& p);
 
-       /*! \brief Rotate self around the point.
-
-       \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);
index 8aa2b9491ee7eaacc293367b1428bc660672947c..230ccbec22200d4460f9cbe6dc72916a2ec77274 100644 (file)
@@ -95,6 +95,19 @@ Point::on_right_side_of(Line const& li) const
        }
 }
 
+void
+Point::rotate(Point const& c, double const angl)
+{
+       double px = this->x();
+       double py = this->y();
+       px -= c.x();
+       py -= c.y();
+       double nx = px * cos(angl) - py * sin(angl);
+       double ny = px * sin(angl) + py * cos(angl);
+       this->x(nx + c.x());
+       this->y(ny + c.y());
+}
+
 std::ostream&
 operator<<(std::ostream& out, Point const& p)
 {
@@ -243,15 +256,8 @@ Pose::set_pose(Pose const& p)
 void
 Pose::rotate(Point const& c, double const angl)
 {
-       double px = this->x();
-       double py = this->y();
-       px -= c.x();
-       py -= c.y();
-       double nx = px * cos(angl) - py * sin(angl);
-       double ny = px * sin(angl) + py * cos(angl);
+       Point::rotate(c, angl);
        this->h(this->h() + angl);
-       this->x(nx + c.x());
-       this->y(ny + c.y());
 }
 
 std::ostream&