]> rtime.felk.cvut.cz Git - hubacji1/psp.git/commitdiff
Add line segment intersection skeleton, ut
authorJiri Vlasak <hubacji1@fel.cvut.cz>
Mon, 22 Jul 2019 09:15:43 +0000 (11:15 +0200)
committerJiri Vlasak <hubacji1@fel.cvut.cz>
Mon, 22 Jul 2019 12:30:52 +0000 (14:30 +0200)
api/psp.h
src/psp.cc
ut/psp.t.cc

index 086a36300d16acf84c9c2d700980eb1669c5cdea..65d5747a6dc4cfd0b6803a8ca6092da77f5b17f9 100644 (file)
--- a/api/psp.h
+++ b/api/psp.h
@@ -1,6 +1,8 @@
 #ifndef PSP_H
 #define PSP_H
 
+#include <tuple>
+
 #include "bcar.h"
 #include "pslot.h"
 
@@ -36,4 +38,29 @@ class PSPlanner {
                 PSPlanner();
 };
 
+/*! \brief Return intersection of two line segments.
+
+The output is tuple `std::tuple<bool, double, double>`, where the first
+value is true when there is an intersection and false otherwise. The
+second and third parameters in the return tuple are coordinates of the
+intersection.
+
+\see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
+
+\param x1 First line segment first `x` coordinate.
+\param y1 First line segment first `y` coordinate.
+\param x2 First line segment second `x` coordinate.
+\param y2 First line segment second `y` coordinate.
+\param x3 Second line segment first `x` coordinate.
+\param y3 Second line segment first `y` coordinate.
+\param x4 Second line segment second `x` coordinate.
+\param y4 Second line segment second `y` coordinate.
+*/
+std::tuple<bool, double, double> intersect(
+        double x1, double y1,
+        double x2, double y2,
+        double x3, double y3,
+        double x4, double y4
+);
+
 #endif /* PSP_H */
index 6d90ce422a85dcf274a250ac78d889cbdddd8dae..367b1f0bb9dc94500300f6e45d4f903e8d83de8b 100644 (file)
@@ -17,3 +17,13 @@ void PSPlanner::fer()
 PSPlanner::PSPlanner()
 {
 }
+
+std::tuple<bool, double, double> intersect(
+        double x1, double y1,
+        double x2, double y2,
+        double x3, double y3,
+        double x4, double y4
+)
+{
+        return std::make_tuple(false, 0, 0);
+}
index 6ee13312cf8690bebaff3018cdf17c2fa61139b3..277e118885de3c5eeeaa6e30716c18511489c8b2 100644 (file)
@@ -23,6 +23,12 @@ WVTEST_MAIN("parking slot planner basic test")
         WVPASSEQ_DOUBLE(psp.ps().heading(), psp.gc().h(), 0.00001);
 
         // collide
+        auto tmpi1 = intersect(1, 1, 3, 3, 1, 3, 3, 1);
+        WVPASS(std::get<0>(tmpi1));
+        WVPASSEQ_DOUBLE(std::get<1>(tmpi1), 2, 0.00001);
+        WVPASSEQ_DOUBLE(std::get<2>(tmpi1), 2, 0.00001);
+        auto tmpi2 = intersect(1, 1, 1, 3, 3, 1, 3, 3);
+        WVPASS(!std::get<0>(tmpi2));
         PSPlanner tpsp;
         tpsp.ps().border(2, 3, 4, 3, 4, 8, 2, 8);
         tpsp.gc() = BicycleCar(psp.gc());