]> rtime.felk.cvut.cz Git - hubacji1/psp.git/blob - api/psp.h
Merge branch 'feature/find-entry-reverse'
[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         public:
21                 /*! \brief Return `true` if there is collision.
22
23                 If the parking slot `ps` collide with current car `cc`,
24                 return `true`.
25
26                 This method depends on `intersection` function that
27                 returns `true` or `false` if two line segments collide.
28                 Each line segment of current car `cc` (borders) is
29                 checked to each line segment of parking slot `ps`
30                 (parking slot lines).
31                 */
32                 bool collide();
33                 /*! \brief Has current car `cc` left?
34
35                 Return `true` if the current car `cc` left the parking
36                 slot `ps`;
37                 */
38                 bool left();
39
40                 // find entry
41                 /*! \brief Find entry to the parking slot.
42                 */
43                 void fe();
44                 /*! \brief Find entry to slot by reverse approach.
45
46                 See `Vorobieva2015` for more information.
47                 */
48                 void fer();
49
50                 // getters, setters
51                 BicycleCar &cc() { return this->cc_; }
52                 BicycleCar &gc() { return this->gc_; }
53                 ParkingSlot &ps() { return this->ps_; }
54
55                 PSPlanner();
56 };
57
58 /*! \brief Return intersection of two line segments.
59
60 The output is tuple `std::tuple<bool, double, double>`, where the first
61 value is true when there is an intersection and false otherwise. The
62 second and third parameters in the return tuple are coordinates of the
63 intersection.
64
65 \see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
66
67 \param x1 First line segment first `x` coordinate.
68 \param y1 First line segment first `y` coordinate.
69 \param x2 First line segment second `x` coordinate.
70 \param y2 First line segment second `y` coordinate.
71 \param x3 Second line segment first `x` coordinate.
72 \param y3 Second line segment first `y` coordinate.
73 \param x4 Second line segment second `x` coordinate.
74 \param y4 Second line segment second `y` coordinate.
75 */
76 std::tuple<bool, double, double> intersect(
77         double x1, double y1,
78         double x2, double y2,
79         double x3, double y3,
80         double x4, double y4
81 );
82
83 #endif /* PSP_H */