]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/pslot.cc
Merge branch 'refactor'
[hubacji1/bcar.git] / src / pslot.cc
1 #include <cmath>
2 #include "pslot.hh"
3
4 void ParkingSlot::reverse_border()
5 {
6         this->border(
7                 this->x4(), this->y4(),
8                 this->x3(), this->y3(),
9                 this->x2(), this->y2(),
10                 this->x1(), this->y1()
11         );
12 }
13
14 // slot info
15 double ParkingSlot::heading() const
16 {
17         return atan2(this->y4() - this->y1(), this->x4() - this->x1());
18 }
19
20 bool ParkingSlot::parallel() const
21 {
22         double d1 = sqrt(
23                 pow(this->x2() - this->x1(), 2)
24                 + pow(this->y2() - this->y1(), 2)
25         );
26         double d2 = sqrt(
27                 pow(this->x3() - this->x2(), 2)
28                 + pow(this->y3() - this->y2(), 2)
29         );
30         if (d1 < d2)
31                 return true;
32         else
33                 return false;
34 }
35
36 bool ParkingSlot::right() const
37 {
38         if (sgn(
39                 (this->x2() - this->x1()) * (this->y4() - this->y1())
40                 - (this->y2() - this->y1()) * (this->x4() - this->x1())
41         ) < 0)
42                 return false;
43         else
44                 return true;
45 }
46
47 //getters, setters
48 void ParkingSlot::set_slot(
49         double x,
50         double y,
51         double h,
52         double w,
53         double l
54 )
55 {
56         double x1 = x + w/2 * cos(h - M_PI/2);
57         double y1 = y + w/2 * sin(h - M_PI/2);
58         double x2 = x + l * cos(h) + w/2 * cos(h - M_PI/2);
59         double y2 = y + l * sin(h) + w/2 * sin(h - M_PI/2);
60         double x3 = x + l * cos(h) + w/2 * cos(h + M_PI/2);
61         double y3 = y + l * sin(h) + w/2 * sin(h + M_PI/2);
62         double x4 = x + w/2 * cos(h + M_PI/2);
63         double y4 = y + w/2 * sin(h + M_PI/2);
64         this->border(x1, y1, x2, y2, x3, y3, x4, y4);
65 }
66
67 ParkingSlot::ParkingSlot()
68 {
69 }