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