]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/pslot.cc
Refactor pslot
[hubacji1/bcar.git] / src / pslot.cc
1 #include <cassert>
2 #include <cmath>
3 #include "pslot.hh"
4
5 namespace bcar {
6
7 ParkingSlot::ParkingSlot(Point p, double h, double W, double L) :
8                 border_({p,
9                         Point(p.x() + W * cos(h - M_PI / 2.0),
10                                 p.y() + W * sin(h - M_PI / 2.0)),
11                         Point(p.x() + W * cos(h - M_PI / 2.0) + L * cos(h),
12                                 p.y() + W * sin(h - M_PI / 2.0) + L * sin(h)),
13                         Point(p.x() + L * cos(h), p.y() + L * sin(h))}),
14                 entry_(p, border_[3]),
15                 rear_(p, border_[1]),
16                 curb_(border_[1], border_[2]),
17                 front_(border_[2], border_[3])
18 {
19 }
20
21 double
22 ParkingSlot::lfx() const
23 {
24         return this->border_[3].x();
25 }
26
27 double
28 ParkingSlot::lfy() const
29 {
30         return this->border_[3].y();
31 }
32
33 double
34 ParkingSlot::lrx() const
35 {
36         return this->border_[0].x();
37 }
38
39 double
40 ParkingSlot::lry() const
41 {
42         return this->border_[0].y();
43 }
44
45 double
46 ParkingSlot::rrx() const
47 {
48         return this->border_[1].x();
49 }
50
51 double
52 ParkingSlot::rry() const
53 {
54         return this->border_[1].y();
55 }
56
57 double
58 ParkingSlot::rfx() const
59 {
60         return this->border_[2].x();
61 }
62
63 double
64 ParkingSlot::rfy() const
65 {
66         return this->border_[2].y();
67 }
68
69 double
70 ParkingSlot::h() const
71 {
72         return atan2(this->lfy() - this->lry(), this->lfx() - this->lrx());
73 }
74
75 bool
76 ParkingSlot::parallel() const
77 {
78         return this->entry_.len() > this->rear_.len();
79 }
80
81 bool
82 ParkingSlot::right() const
83 {
84         return this->border_[1].on_right_side_of(this->entry_);
85 }
86
87 void
88 ParkingSlot::swap_side()
89 {
90         this->border_[1].rotate(this->border_[0], M_PI);
91         this->border_[2].rotate(this->border_[3], M_PI);
92 }
93
94 std::ostream&
95 operator<<(std::ostream& o, ParkingSlot const& s)
96 {
97         o << "[";
98         o << s.border_[0] << ",";
99         o << s.border_[1] << ",";
100         o << s.border_[2] << ",";
101         o << s.border_[3];
102         o << "]";
103         return o;
104 }
105
106 } // namespace bcar