From f95b82c5138d576de581be0b3b30b3af74897573 Mon Sep 17 00:00:00 2001 From: Jiri Vlasak Date: Thu, 15 Jul 2021 13:03:25 +0200 Subject: [PATCH] Add parked method --- incl/pslot.hh | 3 +++ src/pslot.cc | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/incl/pslot.hh b/incl/pslot.hh index 50f17ef..85fdb77 100644 --- a/incl/pslot.hh +++ b/incl/pslot.hh @@ -74,6 +74,9 @@ public: /*! Change side of the parking slot. */ void swap_side(); + /*! Return `true` if car `c` is parking in slot `this`. */ + bool parked(BicycleCar const& c) const; + friend std::ostream& operator<<(std::ostream& o, ParkingSlot const& s); }; diff --git a/src/pslot.cc b/src/pslot.cc index 2246b52..1864de9 100644 --- a/src/pslot.cc +++ b/src/pslot.cc @@ -114,6 +114,15 @@ ParkingSlot::swap_side() this->border_[2].rotate(this->border_[3], M_PI); } +bool +ParkingSlot::parked(BicycleCar const& c) const +{ + auto b_len = sizeof(this->border_) / sizeof(this->border_[0]); + std::vector b(this->border_, this->border_ + b_len); + return c.lf().inside_of(b) && c.lr().inside_of(b) + && c.rr().inside_of(b) && c.rf().inside_of(b); +} + std::ostream& operator<<(std::ostream& o, ParkingSlot const& s) { -- 2.39.2