]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/commitdiff
Move on right side of method to point
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Wed, 14 Jul 2021 21:22:08 +0000 (23:22 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Wed, 14 Jul 2021 21:22:08 +0000 (23:22 +0200)
incl/bcar.hh
src/bcar.cc
ut/bcar.t.cc

index faa8470bbe74e2f89445735f4cd77f4636f3f2ee..0615f535d952c4334ab0a3a74b0f7b251cdb1acc 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,15 @@ 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;
 };
 
 class Line {
@@ -92,15 +103,6 @@ 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;
 };
 
index 96a2c8c82ecc5db43f62683fac03b1171999b24b..492213258d6cc2da7be8ca108e4d1fd779786623 100644 (file)
@@ -79,6 +79,22 @@ Point::inside_of(std::vector<Point> const& poly) const
        return c;
 }
 
+bool
+Point::on_right_side_of(Line const& li) const
+{
+       auto x1 = li.fp().x();
+       auto y1 = li.fp().y();
+       auto x2 = li.lp().x();
+       auto y2 = li.lp().y();
+       auto x3 = this->x_;
+       auto y3 = this->y_;
+       if (sgn((x3 - x1) * (y2 - y1) - (y3 - y1) * (x2 - x1)) < 0.0) {
+               return false;
+       } else {
+               return true;
+       }
+}
+
 Line::Line(Point const& fp, Point const& lp): first(fp), last(lp),
                intersection1(Point(0.0, 0.0)), intersection2(Point(0.0, 0.0))
 {
@@ -175,22 +191,6 @@ Line::intersects_with(Point const& c, double const r)
        return true;
 }
 
-bool
-Line::is_on_right_side(Point const& p) const
-{
-       auto x1 = this->fp().x();
-       auto y1 = this->fp().y();
-       auto x2 = this->lp().x();
-       auto y2 = this->lp().y();
-       auto x3 = p.x();
-       auto y3 = p.y();
-       if (sgn((x3 - x1) * (y2 - y1) - (y3 - y1) * (x2 - x1)) < 0.0) {
-               return false;
-       } else {
-               return true;
-       }
-}
-
 double
 Line::len() const
 {
index 95920e21869108795ac88ddbe0be87e5eec6943f..bdd43549af6e8524aa0f7c41e030fc71017e2ac2 100644 (file)
@@ -149,13 +149,13 @@ WVTEST_MAIN("auxiliary angle between three points")
        auto omo = Point(1.0, -1.0);
        auto tmo = Point(2.0, -1.0);
        auto mto = Point(-2.0, 1.0);
-       WVPASS(Line(momo, oo).is_on_right_side(to));
-       WVPASS(!Line(momo, oo).is_on_right_side(ot));
-       WVPASS(!Line(moo, omo).is_on_right_side(to));
-       WVPASS(!Line(moo, omo).is_on_right_side(ot));
-       WVPASS(!Line(moo, omo).is_on_right_side(tmo));
-       WVPASS(!Line(moo, omo).is_on_right_side(mot));
-       WVPASS(Line(moo, omo).is_on_right_side(mto));
+       WVPASS(to.on_right_side_of(Line(momo, oo)));
+       WVPASS(!ot.on_right_side_of(Line(momo, oo)));
+       WVPASS(!to.on_right_side_of(Line(moo, omo)));
+       WVPASS(!ot.on_right_side_of(Line(moo, omo)));
+       WVPASS(!tmo.on_right_side_of(Line(moo, omo)));
+       WVPASS(!mot.on_right_side_of(Line(moo, omo)));
+       WVPASS(mto.on_right_side_of(Line(moo, omo)));
 }
 
 WVTEST_MAIN("drivable")