X-Git-Url: http://rtime.felk.cvut.cz/gitweb/hubacji1/bcar.git/blobdiff_plain/37f51ce08240dc4c677197ec4a142f97de6d8356..3121301770eb1b42bf64320abcd2e1e9dd606e16:/src/bcar.cc diff --git a/src/bcar.cc b/src/bcar.cc index 32b2b88..8825fb7 100644 --- a/src/bcar.cc +++ b/src/bcar.cc @@ -3,11 +3,11 @@ namespace bcar { -Point::Point(double x, double y) : x_(x), y_(y) +Point::Point() { } -Point::Point() : Point::Point(0.0, 0.0) +Point::Point(double x, double y) : x_(x), y_(y) { } @@ -82,10 +82,10 @@ Point::inside_of(std::vector const& poly) const 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 x1 = li.b().x(); + auto y1 = li.b().y(); + auto x2 = li.e().x(); + auto y2 = li.e().y(); auto x3 = this->x_; auto y3 = this->y_; if (sgn((x3 - x1) * (y2 - y1) - (y3 - y1) * (x2 - x1)) < 0.0) { @@ -121,46 +121,45 @@ operator<<(std::ostream& out, Point const& p) return out; } -Line::Line(Point const& fp, Point const& lp): first(fp), last(lp), - intersection1(Point(0.0, 0.0)), intersection2(Point(0.0, 0.0)) +Line::Line(Point const& b, Point const& e): b_(b), e_(e) { } Point -Line::fp() const& +Line::b() const& { - return this->first; + return this->b_; } Point -Line::lp() const& +Line::e() const& { - return this->last; + return this->e_; } Point -Line::in1() const& +Line::i1() const& { - return this->intersection1; + return this->i1_; } Point -Line::in2() const& +Line::i2() const& { - return this->intersection2; + return this->i2_; } bool Line::intersects_with(Line const& li) { - auto x1 = this->fp().x(); - auto y1 = this->fp().y(); - auto x2 = this->lp().x(); - auto y2 = this->lp().y(); - auto x3 = li.fp().x(); - auto y3 = li.fp().y(); - auto x4 = li.lp().x(); - auto y4 = li.lp().y(); + auto x1 = this->b_.x(); + auto y1 = this->b_.y(); + auto x2 = this->e_.x(); + auto y2 = this->e_.y(); + auto x3 = li.b().x(); + auto y3 = li.b().y(); + auto x4 = li.e().x(); + auto y4 = li.e().y(); double deno = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); if (deno == 0.0) { return false; @@ -173,18 +172,18 @@ Line::intersects_with(Line const& li) if (t < 0.0 || t > 1.0 || u < 0.0 || u > 1.0) { return false; } - this->intersection1.x(x1 + t * (x2 - x1)); - this->intersection1.y(y1 + t * (y2 - y1)); + this->i1_.x(x1 + t * (x2 - x1)); + this->i1_.y(y1 + t * (y2 - y1)); return true; } bool Line::intersects_with(Point const& c, double const r) { - auto x1 = this->fp().x(); - auto y1 = this->fp().y(); - auto x2 = this->lp().x(); - auto y2 = this->lp().y(); + auto x1 = this->b_.x(); + auto y1 = this->b_.y(); + auto x2 = this->e_.x(); + auto y2 = this->e_.y(); auto cx = c.x(); auto cy = c.y(); x2 -= cx; @@ -210,32 +209,26 @@ Line::intersects_with(Point const& c, double const r) iy1 += cy; double iy2 = (-D*dx - std::abs(dy)*sqrt(r*r * dr*dr - D*D)) / (dr*dr); iy2 += cy; - this->intersection1.x(ix1); - this->intersection1.y(iy1); - this->intersection2.x(ix2); - this->intersection2.y(iy2); + this->i1_.x(ix1); + this->i1_.y(iy1); + this->i2_.x(ix2); + this->i2_.y(iy2); return true; } double Line::len() const { - double dx = this->lp().x() - this->fp().x(); - double dy = this->lp().y() - this->fp().y(); - return sqrt(dx * dx + dy * dy); + return this->b_.edist(this->e_); } std::ostream& operator<<(std::ostream& out, Line const& li) { - out << "[" << li.first << "," << li.last << "]"; + out << "[" << li.b_ << "," << li.e_ << "]"; return out; } -Pose::Pose() : Point() -{ -} - Pose::Pose(double x, double y, double h) : Point(x, y), h_(h) { } @@ -328,61 +321,61 @@ operator<<(std::ostream& out, PoseRange const& p) double CarSize::ctc() const { - return this->curb_to_curb; + return this->curb_to_curb_; } void CarSize::ctc(double ctc) { - this->curb_to_curb = ctc; + this->curb_to_curb_ = ctc; } double CarSize::wb() const { - return this->wheelbase; + return this->wheelbase_; } void CarSize::wb(double wb) { - this->wheelbase = wb; + this->wheelbase_ = wb; } double CarSize::w() const { - return this->width; + return this->width_; } void CarSize::w(double w) { - this->width = w; + this->width_ = w; } double CarSize::len() const { - return this->length; + return this->length_; } void CarSize::len(double len) { - this->length = len; + this->length_ = len; } double CarSize::df() const { - return this->distance_to_front; + return this->distance_to_front_; } void CarSize::df(double df) { - this->distance_to_front = df; + this->distance_to_front_ = df; } double @@ -436,25 +429,25 @@ CarSize::perfect_parking_slot_len() const double CarMove::sp() const { - return this->speed; + return this->speed_; } void CarMove::sp(double sp) { - this->speed = sp; + this->speed_ = sp; } double CarMove::st() const { - return this->steer; + return this->steer_; } void CarMove::st(double st) { - this->steer = st; + this->steer_ = st; } bool