return (T(0) < val) - (val < T(0));
}
+class Line;
+
class Point {
private:
double x_ = 0.0;
* \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 {
*/
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;
};
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))
{
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
{
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")