]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/pslot.cc
Add slot info methods implementation
[hubacji1/bcar.git] / src / pslot.cc
1 #include <cmath>
2 #include "pslot.h"
3
4 template <typename T> int sgn(T val) {
5         return (T(0) < val) - (val < T(0));
6 }
7
8 // slot info
9 double ParkingSlot::heading()
10 {
11         return atan2(this->y4() - this->y1(), this->x4() - this->x1());
12 }
13
14 bool ParkingSlot::parallel()
15 {
16         double d1 = sqrt(
17                 pow(this->x2() - this->x1(), 2)
18                 + pow(this->y2() - this->y1(), 2)
19         );
20         double d2 = sqrt(
21                 pow(this->x3() - this->x2(), 2)
22                 + pow(this->y3() - this->y2(), 2)
23         );
24         if (d1 < d2)
25                 return true;
26         else
27                 return false;
28 }
29
30 bool ParkingSlot::right()
31 {
32         if (sgn(
33                 (this->x2() - this->x1()) * (this->y4() - this->y1())
34                 - (this->y2() - this->y1()) * (this->x4() - this->x1())
35         ) < 0)
36                 return false;
37         else
38                 return true;
39 }
40
41 ParkingSlot::ParkingSlot()
42 {
43 }