]> rtime.felk.cvut.cz Git - hubacji1/psp.git/commitdiff
Add collide implementation
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Mon, 22 Jul 2019 10:05:29 +0000 (12:05 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Mon, 22 Jul 2019 12:30:52 +0000 (14:30 +0200)
api/psp.h
src/psp.cc

index 65d5747a6dc4cfd0b6803a8ca6092da77f5b17f9..6a1ee5a44b52e143539d8f100a3b2d78e1dd5da6 100644 (file)
--- a/api/psp.h
+++ b/api/psp.h
@@ -18,6 +18,17 @@ class PSPlanner {
                 BicycleCar gc_;
                 ParkingSlot ps_;
         public:
+                /*! \brief Return `true` if there is collision.
+
+                If the parking slot `ps` collide with current car `cc`,
+                return `true`.
+
+                This method depends on `intersection` function that
+                returns `true` or `false` if two line segments collide.
+                Each line segment of current car `cc` (borders) is
+                checked to each line segment of parking slot `ps`
+                (parking slot lines).
+                */
                 bool collide();
 
                 // find entry
index 711e82149c685c046da67631b873572c6c088c5b..0b84195d7086095b7656588d73333807a2dd3fb3 100644 (file)
@@ -2,6 +2,90 @@
 
 bool PSPlanner::collide()
 {
+        if(std::get<0>(intersect(
+                this->cc().lfx(), this->cc().lfy(),
+                this->cc().lrx(), this->cc().lry(),
+                this->ps().x1(), this->ps().y1(),
+                this->ps().x2(), this->ps().y2()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().rfx(), this->cc().rfy(),
+                this->cc().rrx(), this->cc().rry(),
+                this->ps().x1(), this->ps().y1(),
+                this->ps().x2(), this->ps().y2()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().lfx(), this->cc().lfy(),
+                this->cc().rfx(), this->cc().rfy(),
+                this->ps().x1(), this->ps().y1(),
+                this->ps().x2(), this->ps().y2()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().lrx(), this->cc().lry(),
+                this->cc().rrx(), this->cc().rry(),
+                this->ps().x1(), this->ps().y1(),
+                this->ps().x2(), this->ps().y2()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().lfx(), this->cc().lfy(),
+                this->cc().lrx(), this->cc().lry(),
+                this->ps().x2(), this->ps().y2(),
+                this->ps().x3(), this->ps().y3()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().rfx(), this->cc().rfy(),
+                this->cc().rrx(), this->cc().rry(),
+                this->ps().x2(), this->ps().y2(),
+                this->ps().x3(), this->ps().y3()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().lfx(), this->cc().lfy(),
+                this->cc().rfx(), this->cc().rfy(),
+                this->ps().x2(), this->ps().y2(),
+                this->ps().x3(), this->ps().y3()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().lrx(), this->cc().lry(),
+                this->cc().rrx(), this->cc().rry(),
+                this->ps().x2(), this->ps().y2(),
+                this->ps().x3(), this->ps().y3()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().lfx(), this->cc().lfy(),
+                this->cc().lrx(), this->cc().lry(),
+                this->ps().x3(), this->ps().y3(),
+                this->ps().x4(), this->ps().y4()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().rfx(), this->cc().rfy(),
+                this->cc().rrx(), this->cc().rry(),
+                this->ps().x3(), this->ps().y3(),
+                this->ps().x4(), this->ps().y4()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().lfx(), this->cc().lfy(),
+                this->cc().rfx(), this->cc().rfy(),
+                this->ps().x3(), this->ps().y3(),
+                this->ps().x4(), this->ps().y4()
+        )))
+                return true;
+        if(std::get<0>(intersect(
+                this->cc().lrx(), this->cc().lry(),
+                this->cc().rrx(), this->cc().rry(),
+                this->ps().x3(), this->ps().y3(),
+                this->ps().x4(), this->ps().y4()
+        )))
+                return true;
         return false;
 }