]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - api/pslot.h
1f29f9ac726d52502e3083ef466b9c8ee7674ce6
[hubacji1/bcar.git] / api / pslot.h
1 #ifndef PSLOT_H
2 #define PSLOT_H
3
4 #include <ostream>
5
6 /*! \brief Parking slot basic class.
7
8 This class contains some geometrical computations of parking slot. Parking slot
9 consists of 4 cartesian coordinates `border` representing the border of the
10 parking slot.
11
12 \param border Array of 4 `x`, `y` values - the borderd of the parking slot.
13 */
14 class ParkingSlot {
15         private:
16                 double border_[4][2] = {
17                         {0, 0},
18                         {1, 0},
19                         {1, 2},
20                         {0, 2}
21                 };
22         public:
23                 /*! \brief Reverse order of border coordinates.
24                 */
25                 void reverse_border();
26
27                 // slot info
28                 /*! \brief Return orientation of the parking slot.
29
30                 The orientation of the parking slot is computed as the
31                 direction from the first to the last border coordinates.
32                 */
33                 double heading() const;
34                 /*! \brief Return `true` if slot is parallel.
35
36                 There are two slot types - parallel and perpendicular.
37                 */
38                 bool parallel() const;
39                 /*! \brief Return `true` if slot is on the right.
40
41                 The slot could be on right or the left side.
42                 */
43                 bool right() const;
44
45                 // getters, setters
46                 double x1() const { return this->border_[0][0]; }
47                 double y1() const { return this->border_[0][1]; }
48                 double x2() const { return this->border_[1][0]; }
49                 double y2() const { return this->border_[1][1]; }
50                 double x3() const { return this->border_[2][0]; }
51                 double y3() const { return this->border_[2][1]; }
52                 double x4() const { return this->border_[3][0]; }
53                 double y4() const { return this->border_[3][1]; }
54                 /*! \brief Set parking slot border.
55
56                 \param x1 First `x` coordinate.
57                 \param y1 First `y` coordinate.
58                 \param x2 Second `x` coordinate.
59                 \param y2 Second `y` coordinate.
60                 \param x3 Third `x` coordinate.
61                 \param y3 Third `y` coordinate.
62                 \param x4 The last (fourth) `x` coordinate.
63                 \param y4 The last (fourth) `y` coordinate.
64                 */
65                 void border(
66                         double x1, double y1,
67                         double x2, double y2,
68                         double x3, double y3,
69                         double x4, double y4
70                 ) {
71                         this->border_[0][0] = x1;
72                         this->border_[0][1] = y1;
73                         this->border_[1][0] = x2;
74                         this->border_[1][1] = y2;
75                         this->border_[2][0] = x3;
76                         this->border_[2][1] = y3;
77                         this->border_[3][0] = x4;
78                         this->border_[3][1] = y4;
79                 };
80                 /*! \brief Set parking slot.
81
82                 \param x Horizontal coordinate of entry side center.
83                 \param y Vertical coordinate of entry side center.
84                 \param h The heading towards slot.
85                 \param w The width of the slot.
86                 \param l The length of the slot.
87                 */
88                 void set_slot(
89                         double x,
90                         double y,
91                         double h,
92                         double w,
93                         double l
94                 );
95
96                 ParkingSlot();
97                 friend std::ostream &operator<<(
98                         std::ostream &out,
99                         const ParkingSlot &ps
100                 )
101                 {
102                         out << "[[" << ps.x1() << "," << ps.y1() << "]";
103                         out << ",[" << ps.x2() << "," << ps.y2() << "]";
104                         out << ",[" << ps.x3() << "," << ps.y3() << "]";
105                         out << ",[" << ps.x4() << "," << ps.y4() << "]";
106                         out << "]";
107                         return out;
108                 }
109 };
110
111 template <typename T> int sgn(T val) {
112         return (T(0) < val) - (val < T(0));
113 }
114
115 #endif /* PSLOT_H */