]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/commitdiff
Add parked method
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 15 Jul 2021 11:03:25 +0000 (13:03 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Thu, 15 Jul 2021 14:17:37 +0000 (16:17 +0200)
incl/pslot.hh
src/pslot.cc

index 50f17ef6c7bc31c418bbc244595029a8a16a0289..85fdb771f4b3f045a62a0eb6d7f640b49f5519bf 100644 (file)
@@ -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);
 };
 
index 2246b5253e27e410156bac649d1319fb11badcaa..1864de9f037afd84925408aaf90dfe523dfdd3fd 100644 (file)
@@ -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<Point> 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)
 {