]> rtime.felk.cvut.cz Git - hubacji1/psp.git/blob - api/psp.h
Use fer for perpendicular fe
[hubacji1/psp.git] / api / psp.h
1 #ifndef PSP_H
2 #define PSP_H
3
4 #include <tuple>
5
6 #include "bcar.h"
7 #include "pslot.h"
8
9 /*! \brief Parking Slot Planner basic class.
10
11 \param cc Current bicycle car.
12 \param ps Parking slot.
13 \param gc Goal car.
14 */
15 class PSPlanner {
16         private:
17                 BicycleCar cc_;
18                 BicycleCar gc_;
19                 ParkingSlot ps_;
20
21                 // find entry to slot by reverse approach
22                 void fe_parallel();
23                 void fe_perpendicular();
24                 void fer_parallel();
25                 void fer_perpendicular();
26         public:
27                 /*! \brief Return `true` if there is collision.
28
29                 If the parking slot `ps` collide with current car `cc`,
30                 return `true`.
31
32                 This method depends on `intersection` function that
33                 returns `true` or `false` if two line segments collide.
34                 Each line segment of current car `cc` (borders) is
35                 checked to each line segment of parking slot `ps`
36                 (parking slot lines).
37                 */
38                 bool collide();
39                 /*! \brief Return parking direction
40
41                 Return `true` if the direction of the parking in the
42                 slot is forward.
43                 */
44                 bool forward();
45                 /*! \brief Has current car `cc` left?
46
47                 Return `true` if the current car `cc` left the parking
48                 slot `ps`;
49                 */
50                 bool left();
51
52                 // find entry
53                 /*! \brief Find entry to the parking slot.
54                 */
55                 void fe();
56                 /*! \brief Find entry to slot by reverse approach.
57
58                 See `Vorobieva2015` for more information.
59                 */
60                 void fer();
61
62                 // getters, setters
63                 BicycleCar &cc() { return this->cc_; }
64                 BicycleCar &gc() { return this->gc_; }
65                 ParkingSlot &ps() { return this->ps_; }
66
67                 PSPlanner();
68 };
69
70 /*! \brief Return intersection of two line segments.
71
72 The output is tuple `std::tuple<bool, double, double>`, where the first
73 value is true when there is an intersection and false otherwise. The
74 second and third parameters in the return tuple are coordinates of the
75 intersection.
76
77 \see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
78
79 \param x1 First line segment first `x` coordinate.
80 \param y1 First line segment first `y` coordinate.
81 \param x2 First line segment second `x` coordinate.
82 \param y2 First line segment second `y` coordinate.
83 \param x3 Second line segment first `x` coordinate.
84 \param y3 Second line segment first `y` coordinate.
85 \param x4 Second line segment second `x` coordinate.
86 \param y4 Second line segment second `y` coordinate.
87 */
88 std::tuple<bool, double, double> intersect(
89         double x1, double y1,
90         double x2, double y2,
91         double x3, double y3,
92         double x4, double y4
93 );
94
95 #endif /* PSP_H */